]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (C) 2012 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 | #ifndef JSCellInlines_h | |
27 | #define JSCellInlines_h | |
28 | ||
29 | #include "CallFrame.h" | |
30 | #include "Handle.h" | |
31 | #include "JSCell.h" | |
32 | #include "JSObject.h" | |
33 | #include "JSString.h" | |
34 | #include "Structure.h" | |
35 | ||
36 | namespace JSC { | |
37 | ||
38 | inline JSCell::JSCell(CreatingEarlyCellTag) | |
39 | { | |
40 | } | |
41 | ||
42 | inline JSCell::JSCell(VM& vm, Structure* structure) | |
43 | : m_structure(vm, this, structure) | |
44 | { | |
45 | } | |
46 | ||
47 | inline void JSCell::finishCreation(VM& vm) | |
48 | { | |
49 | #if ENABLE(GC_VALIDATION) | |
50 | ASSERT(vm.isInitializingObject()); | |
51 | vm.setInitializingObjectClass(0); | |
52 | #else | |
53 | UNUSED_PARAM(vm); | |
54 | #endif | |
55 | ASSERT(m_structure); | |
56 | } | |
57 | ||
58 | inline void JSCell::finishCreation(VM& vm, Structure* structure, CreatingEarlyCellTag) | |
59 | { | |
60 | #if ENABLE(GC_VALIDATION) | |
61 | ASSERT(vm.isInitializingObject()); | |
62 | vm.setInitializingObjectClass(0); | |
63 | if (structure) | |
64 | #endif | |
65 | m_structure.setEarlyValue(vm, this, structure); | |
66 | // Very first set of allocations won't have a real structure. | |
67 | ASSERT(m_structure || !vm.structureStructure); | |
68 | } | |
69 | ||
70 | inline Structure* JSCell::structure() const | |
71 | { | |
72 | return m_structure.get(); | |
73 | } | |
74 | ||
75 | inline void JSCell::visitChildren(JSCell* cell, SlotVisitor& visitor) | |
76 | { | |
77 | MARK_LOG_PARENT(visitor, cell); | |
78 | ||
79 | visitor.append(&cell->m_structure); | |
80 | } | |
81 | ||
82 | template<typename T> | |
83 | void* allocateCell(Heap& heap, size_t size) | |
84 | { | |
85 | ASSERT(size >= sizeof(T)); | |
86 | #if ENABLE(GC_VALIDATION) | |
87 | ASSERT(!heap.vm()->isInitializingObject()); | |
88 | heap.vm()->setInitializingObjectClass(&T::s_info); | |
89 | #endif | |
90 | JSCell* result = 0; | |
91 | if (T::needsDestruction && T::hasImmortalStructure) | |
92 | result = static_cast<JSCell*>(heap.allocateWithImmortalStructureDestructor(size)); | |
93 | else if (T::needsDestruction) | |
94 | result = static_cast<JSCell*>(heap.allocateWithNormalDestructor(size)); | |
95 | else | |
96 | result = static_cast<JSCell*>(heap.allocateWithoutDestructor(size)); | |
97 | result->clearStructure(); | |
98 | return result; | |
99 | } | |
100 | ||
101 | template<typename T> | |
102 | void* allocateCell(Heap& heap) | |
103 | { | |
104 | return allocateCell<T>(heap, sizeof(T)); | |
105 | } | |
106 | ||
107 | inline bool isZapped(const JSCell* cell) | |
108 | { | |
109 | return cell->isZapped(); | |
110 | } | |
111 | ||
112 | inline bool JSCell::isObject() const | |
113 | { | |
114 | return m_structure->isObject(); | |
115 | } | |
116 | ||
117 | inline bool JSCell::isString() const | |
118 | { | |
119 | return m_structure->typeInfo().type() == StringType; | |
120 | } | |
121 | ||
122 | inline bool JSCell::isGetterSetter() const | |
123 | { | |
124 | return m_structure->typeInfo().type() == GetterSetterType; | |
125 | } | |
126 | ||
127 | inline bool JSCell::isProxy() const | |
128 | { | |
129 | return structure()->typeInfo().type() == ProxyType; | |
130 | } | |
131 | ||
132 | inline bool JSCell::isAPIValueWrapper() const | |
133 | { | |
134 | return m_structure->typeInfo().type() == APIValueWrapperType; | |
135 | } | |
136 | ||
137 | inline void JSCell::setStructure(VM& vm, Structure* structure) | |
138 | { | |
139 | ASSERT(structure->typeInfo().overridesVisitChildren() == this->structure()->typeInfo().overridesVisitChildren()); | |
140 | ASSERT(structure->classInfo() == m_structure->classInfo()); | |
141 | ASSERT(!m_structure | |
142 | || m_structure->transitionWatchpointSetHasBeenInvalidated() | |
143 | || m_structure.get() == structure); | |
144 | m_structure.set(vm, this, structure); | |
145 | } | |
146 | ||
147 | inline const MethodTable* JSCell::methodTableForDestruction() const | |
148 | { | |
149 | return &classInfo()->methodTable; | |
150 | } | |
151 | ||
152 | inline const MethodTable* JSCell::methodTable() const | |
153 | { | |
154 | if (Structure* rootStructure = m_structure->structure()) | |
155 | RELEASE_ASSERT(rootStructure == rootStructure->structure()); | |
156 | ||
157 | return &classInfo()->methodTable; | |
158 | } | |
159 | ||
160 | inline bool JSCell::inherits(const ClassInfo* info) const | |
161 | { | |
162 | return classInfo()->isSubClassOf(info); | |
163 | } | |
164 | ||
165 | ALWAYS_INLINE bool JSCell::fastGetOwnPropertySlot(ExecState* exec, PropertyName propertyName, PropertySlot& slot) | |
166 | { | |
167 | if (!structure()->typeInfo().overridesGetOwnPropertySlot()) | |
168 | return asObject(this)->inlineGetOwnPropertySlot(exec, propertyName, slot); | |
169 | return methodTable()->getOwnPropertySlot(this, exec, propertyName, slot); | |
170 | } | |
171 | ||
172 | // Fast call to get a property where we may not yet have converted the string to an | |
173 | // identifier. The first time we perform a property access with a given string, try | |
174 | // performing the property map lookup without forming an identifier. We detect this | |
175 | // case by checking whether the hash has yet been set for this string. | |
176 | ALWAYS_INLINE JSValue JSCell::fastGetOwnProperty(ExecState* exec, const String& name) | |
177 | { | |
178 | if (!structure()->typeInfo().overridesGetOwnPropertySlot() && !structure()->hasGetterSetterProperties()) { | |
179 | PropertyOffset offset = name.impl()->hasHash() | |
180 | ? structure()->get(exec->vm(), Identifier(exec, name)) | |
181 | : structure()->get(exec->vm(), name); | |
182 | if (offset != invalidOffset) | |
183 | return asObject(this)->locationForOffset(offset)->get(); | |
184 | } | |
185 | return JSValue(); | |
186 | } | |
187 | ||
188 | inline bool JSCell::toBoolean(ExecState* exec) const | |
189 | { | |
190 | if (isString()) | |
191 | return static_cast<const JSString*>(this)->toBoolean(); | |
192 | return !structure()->masqueradesAsUndefined(exec->lexicalGlobalObject()); | |
193 | } | |
194 | ||
195 | inline TriState JSCell::pureToBoolean() const | |
196 | { | |
197 | if (isString()) | |
198 | return static_cast<const JSString*>(this)->toBoolean() ? TrueTriState : FalseTriState; | |
199 | return MixedTriState; | |
200 | } | |
201 | ||
202 | } // namespace JSC | |
203 | ||
204 | #endif // JSCellInlines_h |