]>
git.saurik.com Git - apple/javascriptcore.git/blob - runtime/JSCellInlines.h
2 * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef JSCellInlines_h
27 #define JSCellInlines_h
29 #include "CallFrame.h"
33 #include "JSDestructibleObject.h"
36 #include "MarkedBlock.h"
37 #include "Structure.h"
39 #include <wtf/CompilationThread.h>
43 inline JSCell::JSCell(CreatingEarlyCellTag
)
46 ASSERT(!isCompilationThread());
49 inline JSCell::JSCell(VM
&, Structure
* structure
)
50 : m_structureID(structure
->id())
51 , m_indexingType(structure
->indexingType())
52 , m_type(structure
->typeInfo().type())
53 , m_flags(structure
->typeInfo().inlineTypeFlags())
56 ASSERT(!isCompilationThread());
59 inline void JSCell::finishCreation(VM
& vm
)
61 #if ENABLE(GC_VALIDATION)
62 ASSERT(vm
.isInitializingObject());
63 vm
.setInitializingObjectClass(0);
67 ASSERT(m_structureID
);
70 inline void JSCell::finishCreation(VM
& vm
, Structure
* structure
, CreatingEarlyCellTag
)
72 #if ENABLE(GC_VALIDATION)
73 ASSERT(vm
.isInitializingObject());
74 vm
.setInitializingObjectClass(0);
77 m_structureID
= structure
->id();
78 m_indexingType
= structure
->indexingType();
79 m_type
= structure
->typeInfo().type();
80 m_flags
= structure
->typeInfo().inlineTypeFlags();
81 #if ENABLE(GC_VALIDATION)
86 // Very first set of allocations won't have a real structure.
87 ASSERT(m_structureID
|| !vm
.structureStructure
);
90 inline JSType
JSCell::type() const
95 inline IndexingType
JSCell::indexingType() const
97 return m_indexingType
;
100 inline Structure
* JSCell::structure() const
102 return Heap::heap(this)->structureIDTable().get(m_structureID
);
105 inline Structure
* JSCell::structure(VM
& vm
) const
107 return vm
.heap
.structureIDTable().get(m_structureID
);
110 inline void JSCell::visitChildren(JSCell
* cell
, SlotVisitor
& visitor
)
112 Structure
* structure
= cell
->structure(visitor
.vm());
113 visitor
.appendUnbarrieredPointer(&structure
);
116 inline VM
* JSCell::vm() const
118 return MarkedBlock::blockFor(this)->vm();
121 inline VM
& ExecState::vm() const
124 ASSERT(callee()->vm());
125 return *calleeAsValue().asCell()->vm();
129 void* allocateCell(Heap
& heap
, size_t size
)
131 ASSERT(!DisallowGC::isGCDisallowedOnCurrentThread());
132 ASSERT(size
>= sizeof(T
));
133 JSCell
* result
= static_cast<JSCell
*>(heap
.allocateObjectOfType
<T
>(size
));
134 #if ENABLE(GC_VALIDATION)
135 ASSERT(!heap
.vm()->isInitializingObject());
136 heap
.vm()->setInitializingObjectClass(T::info());
138 result
->clearStructure();
143 void* allocateCell(Heap
& heap
)
145 return allocateCell
<T
>(heap
, sizeof(T
));
148 inline bool isZapped(const JSCell
* cell
)
150 return cell
->isZapped();
153 inline bool JSCell::isObject() const
155 return TypeInfo::isObject(m_type
);
158 inline bool JSCell::isString() const
160 return m_type
== StringType
;
163 inline bool JSCell::isSymbol() const
165 return m_type
== SymbolType
;
168 inline bool JSCell::isGetterSetter() const
170 return m_type
== GetterSetterType
;
173 inline bool JSCell::isCustomGetterSetter() const
175 return m_type
== CustomGetterSetterType
;
178 inline bool JSCell::isProxy() const
180 return m_type
== ImpureProxyType
|| m_type
== PureForwardingProxyType
;
183 inline bool JSCell::isAPIValueWrapper() const
185 return m_type
== APIValueWrapperType
;
188 inline void JSCell::setStructure(VM
& vm
, Structure
* structure
)
190 ASSERT(structure
->classInfo() == this->structure()->classInfo());
191 ASSERT(!this->structure()
192 || this->structure()->transitionWatchpointSetHasBeenInvalidated()
193 || Heap::heap(this)->structureIDTable().get(structure
->id()) == structure
);
194 vm
.heap
.writeBarrier(this, structure
);
195 m_structureID
= structure
->id();
196 m_flags
= structure
->typeInfo().inlineTypeFlags();
197 m_type
= structure
->typeInfo().type();
198 m_indexingType
= structure
->indexingType();
201 inline const MethodTable
* JSCell::methodTable() const
203 VM
& vm
= *Heap::heap(this)->vm();
204 Structure
* structure
= this->structure(vm
);
205 if (Structure
* rootStructure
= structure
->structure(vm
))
206 RELEASE_ASSERT(rootStructure
== rootStructure
->structure(vm
));
208 return &structure
->classInfo()->methodTable
;
211 inline const MethodTable
* JSCell::methodTable(VM
& vm
) const
213 Structure
* structure
= this->structure(vm
);
214 if (Structure
* rootStructure
= structure
->structure(vm
))
215 RELEASE_ASSERT(rootStructure
== rootStructure
->structure(vm
));
217 return &structure
->classInfo()->methodTable
;
220 inline bool JSCell::inherits(const ClassInfo
* info
) const
222 return classInfo()->isSubClassOf(info
);
225 ALWAYS_INLINE JSValue
JSCell::fastGetOwnProperty(VM
& vm
, Structure
& structure
, PropertyName name
)
227 ASSERT(canUseFastGetOwnProperty(structure
));
228 PropertyOffset offset
= structure
.get(vm
, name
);
229 if (offset
!= invalidOffset
)
230 return asObject(this)->locationForOffset(offset
)->get();
234 inline bool JSCell::canUseFastGetOwnProperty(const Structure
& structure
)
236 return !structure
.hasGetterSetterProperties()
237 && !structure
.hasCustomGetterSetterProperties()
238 && !structure
.typeInfo().overridesGetOwnPropertySlot();
241 inline const ClassInfo
* JSCell::classInfo() const
243 MarkedBlock
* block
= MarkedBlock::blockFor(this);
244 if (block
->needsDestruction() && !(inlineTypeFlags() & StructureIsImmortal
))
245 return static_cast<const JSDestructibleObject
*>(this)->classInfo();
246 return structure(*block
->vm())->classInfo();
249 inline bool JSCell::toBoolean(ExecState
* exec
) const
252 return static_cast<const JSString
*>(this)->toBoolean();
253 return !structure()->masqueradesAsUndefined(exec
->lexicalGlobalObject());
256 inline TriState
JSCell::pureToBoolean() const
259 return static_cast<const JSString
*>(this)->toBoolean() ? TrueTriState
: FalseTriState
;
262 return MixedTriState
;
267 #endif // JSCellInlines_h