1/*
2 * Copyright (C) 2015 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "ObjectPropertyCondition.h"
28
29#include "JSCInlines.h"
30#include "TrackedReferences.h"
31
32namespace JSC {
33
34void ObjectPropertyCondition::dumpInContext(PrintStream& out, DumpContext* context) const
35{
36 if (!*this) {
37 out.print("<invalid>");
38 return;
39 }
40
41 out.print("<", inContext(JSValue(m_object), context), ": ", inContext(m_condition, context), ">");
42}
43
44void ObjectPropertyCondition::dump(PrintStream& out) const
45{
46 dumpInContext(out, nullptr);
47}
48
49bool ObjectPropertyCondition::structureEnsuresValidityAssumingImpurePropertyWatchpoint() const
50{
51 if (!*this)
52 return false;
53
54 return m_condition.isStillValidAssumingImpurePropertyWatchpoint(m_object->structure(), nullptr);
55}
56
57bool ObjectPropertyCondition::validityRequiresImpurePropertyWatchpoint(Structure* structure) const
58{
59 return m_condition.validityRequiresImpurePropertyWatchpoint(structure);
60}
61
62bool ObjectPropertyCondition::validityRequiresImpurePropertyWatchpoint() const
63{
64 if (!*this)
65 return false;
66
67 return validityRequiresImpurePropertyWatchpoint(m_object->structure());
68}
69
70bool ObjectPropertyCondition::isStillValidAssumingImpurePropertyWatchpoint(Structure* structure) const
71{
72 return m_condition.isStillValidAssumingImpurePropertyWatchpoint(structure, m_object);
73}
74
75bool ObjectPropertyCondition::isStillValidAssumingImpurePropertyWatchpoint() const
76{
77 if (!*this)
78 return false;
79
80 return isStillValidAssumingImpurePropertyWatchpoint(m_object->structure());
81}
82
83
84bool ObjectPropertyCondition::isStillValid(Structure* structure) const
85{
86 return m_condition.isStillValid(structure, m_object);
87}
88
89bool ObjectPropertyCondition::isStillValid() const
90{
91 if (!*this)
92 return false;
93
94 return isStillValid(m_object->structure());
95}
96
97bool ObjectPropertyCondition::structureEnsuresValidity(Structure* structure) const
98{
99 return m_condition.isStillValid(structure);
100}
101
102bool ObjectPropertyCondition::structureEnsuresValidity() const
103{
104 if (!*this)
105 return false;
106
107 return structureEnsuresValidity(m_object->structure());
108}
109
110bool ObjectPropertyCondition::isWatchableAssumingImpurePropertyWatchpoint(
111 Structure* structure, PropertyCondition::WatchabilityEffort effort) const
112{
113 return m_condition.isWatchableAssumingImpurePropertyWatchpoint(structure, m_object, effort);
114}
115
116bool ObjectPropertyCondition::isWatchableAssumingImpurePropertyWatchpoint(
117 PropertyCondition::WatchabilityEffort effort) const
118{
119 if (!*this)
120 return false;
121
122 return isWatchableAssumingImpurePropertyWatchpoint(m_object->structure(), effort);
123}
124
125bool ObjectPropertyCondition::isWatchable(
126 Structure* structure, PropertyCondition::WatchabilityEffort effort) const
127{
128 return m_condition.isWatchable(structure, m_object, effort);
129}
130
131bool ObjectPropertyCondition::isWatchable(PropertyCondition::WatchabilityEffort effort) const
132{
133 if (!*this)
134 return false;
135
136 return isWatchable(m_object->structure(), effort);
137}
138
139bool ObjectPropertyCondition::isStillLive(VM& vm) const
140{
141 if (!*this)
142 return false;
143
144 bool isStillLive = true;
145 forEachDependentCell([&](JSCell* cell) {
146 isStillLive &= vm.heap.isMarked(cell);
147 });
148 return isStillLive;
149}
150
151void ObjectPropertyCondition::validateReferences(const TrackedReferences& tracked) const
152{
153 if (!*this)
154 return;
155
156 tracked.check(m_object);
157 m_condition.validateReferences(tracked);
158}
159
160ObjectPropertyCondition ObjectPropertyCondition::attemptToMakeEquivalenceWithoutBarrier(VM& vm) const
161{
162 PropertyCondition result = condition().attemptToMakeEquivalenceWithoutBarrier(vm, object());
163 if (!result)
164 return ObjectPropertyCondition();
165 return ObjectPropertyCondition(object(), result);
166}
167
168} // namespace JSC
169
170