1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
|
/*
* Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef JSCellInlines_h
#define JSCellInlines_h
#include "CallFrame.h"
#include "DeferGC.h"
#include "Handle.h"
#include "JSCell.h"
#include "JSDestructibleObject.h"
#include "JSObject.h"
#include "JSString.h"
#include "MarkedBlock.h"
#include "Structure.h"
#include <wtf/CompilationThread.h>
namespace JSC {
inline JSCell::JSCell(CreatingEarlyCellTag)
: m_gcData(NotMarked)
{
ASSERT(!isCompilationThread());
}
inline JSCell::JSCell(VM&, Structure* structure)
: m_structureID(structure->id())
, m_indexingType(structure->indexingType())
, m_type(structure->typeInfo().type())
, m_flags(structure->typeInfo().inlineTypeFlags())
, m_gcData(NotMarked)
{
ASSERT(!isCompilationThread());
}
inline void JSCell::finishCreation(VM& vm)
{
#if ENABLE(GC_VALIDATION)
ASSERT(vm.isInitializingObject());
vm.setInitializingObjectClass(0);
#else
UNUSED_PARAM(vm);
#endif
ASSERT(m_structureID);
}
inline void JSCell::finishCreation(VM& vm, Structure* structure, CreatingEarlyCellTag)
{
#if ENABLE(GC_VALIDATION)
ASSERT(vm.isInitializingObject());
vm.setInitializingObjectClass(0);
if (structure) {
#endif
m_structureID = structure->id();
m_indexingType = structure->indexingType();
m_type = structure->typeInfo().type();
m_flags = structure->typeInfo().inlineTypeFlags();
#if ENABLE(GC_VALIDATION)
}
#else
UNUSED_PARAM(vm);
#endif
// Very first set of allocations won't have a real structure.
ASSERT(m_structureID || !vm.structureStructure);
}
inline JSType JSCell::type() const
{
return m_type;
}
inline IndexingType JSCell::indexingType() const
{
return m_indexingType;
}
inline Structure* JSCell::structure() const
{
return Heap::heap(this)->structureIDTable().get(m_structureID);
}
inline Structure* JSCell::structure(VM& vm) const
{
return vm.heap.structureIDTable().get(m_structureID);
}
inline void JSCell::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
Structure* structure = cell->structure(visitor.vm());
visitor.appendUnbarrieredPointer(&structure);
}
inline VM* JSCell::vm() const
{
return MarkedBlock::blockFor(this)->vm();
}
inline VM& ExecState::vm() const
{
ASSERT(callee()->vm());
return *callee()->vm();
}
template<typename T>
void* allocateCell(Heap& heap, size_t size)
{
ASSERT(!DisallowGC::isGCDisallowedOnCurrentThread());
ASSERT(size >= sizeof(T));
JSCell* result = 0;
if (T::needsDestruction && T::hasImmortalStructure)
result = static_cast<JSCell*>(heap.allocateWithImmortalStructureDestructor(size));
else if (T::needsDestruction)
result = static_cast<JSCell*>(heap.allocateWithNormalDestructor(size));
else
result = static_cast<JSCell*>(heap.allocateWithoutDestructor(size));
#if ENABLE(GC_VALIDATION)
ASSERT(!heap.vm()->isInitializingObject());
heap.vm()->setInitializingObjectClass(T::info());
#endif
result->clearStructure();
return result;
}
template<typename T>
void* allocateCell(Heap& heap)
{
return allocateCell<T>(heap, sizeof(T));
}
inline bool isZapped(const JSCell* cell)
{
return cell->isZapped();
}
inline bool JSCell::isObject() const
{
return TypeInfo::isObject(m_type);
}
inline bool JSCell::isString() const
{
return m_type == StringType;
}
inline bool JSCell::isGetterSetter() const
{
return m_type == GetterSetterType;
}
inline bool JSCell::isCustomGetterSetter() const
{
return m_type == CustomGetterSetterType;
}
inline bool JSCell::isProxy() const
{
return m_type == ImpureProxyType || m_type == PureForwardingProxyType;
}
inline bool JSCell::isAPIValueWrapper() const
{
return m_type == APIValueWrapperType;
}
inline void JSCell::setStructure(VM& vm, Structure* structure)
{
ASSERT(structure->classInfo() == this->structure()->classInfo());
ASSERT(!this->structure()
|| this->structure()->transitionWatchpointSetHasBeenInvalidated()
|| Heap::heap(this)->structureIDTable().get(structure->id()) == structure);
vm.heap.writeBarrier(this, structure);
m_structureID = structure->id();
m_flags = structure->typeInfo().inlineTypeFlags();
m_type = structure->typeInfo().type();
m_indexingType = structure->indexingType();
}
inline const MethodTable* JSCell::methodTable() const
{
VM& vm = *Heap::heap(this)->vm();
Structure* structure = this->structure(vm);
if (Structure* rootStructure = structure->structure(vm))
RELEASE_ASSERT(rootStructure == rootStructure->structure(vm));
return &structure->classInfo()->methodTable;
}
inline const MethodTable* JSCell::methodTable(VM& vm) const
{
Structure* structure = this->structure(vm);
if (Structure* rootStructure = structure->structure(vm))
RELEASE_ASSERT(rootStructure == rootStructure->structure(vm));
return &structure->classInfo()->methodTable;
}
inline bool JSCell::inherits(const ClassInfo* info) const
{
return classInfo()->isSubClassOf(info);
}
ALWAYS_INLINE JSValue JSCell::fastGetOwnProperty(VM& vm, Structure& structure, PropertyName name)
{
ASSERT(canUseFastGetOwnProperty(structure));
PropertyOffset offset = structure.get(vm, name);
if (offset != invalidOffset)
return asObject(this)->locationForOffset(offset)->get();
return JSValue();
}
inline bool JSCell::canUseFastGetOwnProperty(const Structure& structure)
{
return !structure.hasGetterSetterProperties()
&& !structure.hasCustomGetterSetterProperties()
&& !structure.typeInfo().overridesGetOwnPropertySlot();
}
inline const ClassInfo* JSCell::classInfo() const
{
MarkedBlock* block = MarkedBlock::blockFor(this);
if (block->destructorType() == MarkedBlock::Normal)
return static_cast<const JSDestructibleObject*>(this)->classInfo();
return structure(*block->vm())->classInfo();
}
inline bool JSCell::toBoolean(ExecState* exec) const
{
if (isString())
return static_cast<const JSString*>(this)->toBoolean();
return !structure()->masqueradesAsUndefined(exec->lexicalGlobalObject());
}
inline TriState JSCell::pureToBoolean() const
{
if (isString())
return static_cast<const JSString*>(this)->toBoolean() ? TrueTriState : FalseTriState;
return MixedTriState;
}
} // namespace JSC
#endif // JSCellInlines_h
|