diff options
Diffstat (limited to 'Source/JavaScriptCore/runtime/JSCell.h')
-rw-r--r-- | Source/JavaScriptCore/runtime/JSCell.h | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/Source/JavaScriptCore/runtime/JSCell.h b/Source/JavaScriptCore/runtime/JSCell.h index 74833d12f..78d2d0801 100644 --- a/Source/JavaScriptCore/runtime/JSCell.h +++ b/Source/JavaScriptCore/runtime/JSCell.h @@ -36,9 +36,10 @@ namespace JSC { class JSGlobalObject; - class Structure; + class LLIntOffsetsExtractor; class PropertyDescriptor; class PropertyNameArray; + class Structure; enum EnumerationMode { ExcludeDontEnumProperties, @@ -61,6 +62,7 @@ namespace JSC { class JSCell { friend class JSValue; friend class MarkedBlock; + template<typename T> friend void* allocateCell(Heap&); public: enum CreatingEarlyCellTag { CreatingEarlyCell }; @@ -162,6 +164,8 @@ namespace JSC { static bool getOwnPropertyDescriptor(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&); private: + friend class LLIntOffsetsExtractor; + const ClassInfo* m_classInfo; WriteBarrier<Structure> m_structure; }; @@ -307,14 +311,34 @@ namespace JSC { return isCell() ? asCell()->toObject(exec, globalObject) : toObjectSlowCase(exec, globalObject); } - template <typename T> void* allocateCell(Heap& heap) +#if COMPILER(CLANG) + template<class T> + struct NeedsDestructor { + static const bool value = !__has_trivial_destructor(T); + }; +#else + // Write manual specializations for this struct template if you care about non-clang compilers. + template<class T> + struct NeedsDestructor { + static const bool value = true; + }; +#endif + + template<typename T> + void* allocateCell(Heap& heap) { #if ENABLE(GC_VALIDATION) ASSERT(sizeof(T) == T::s_info.cellSize); ASSERT(!heap.globalData()->isInitializingObject()); heap.globalData()->setInitializingObject(true); #endif - JSCell* result = static_cast<JSCell*>(heap.allocate(sizeof(T))); + JSCell* result = 0; + if (NeedsDestructor<T>::value) + result = static_cast<JSCell*>(heap.allocateWithDestructor(sizeof(T))); + else { + ASSERT(T::s_info.methodTable.destroy == JSCell::destroy); + result = static_cast<JSCell*>(heap.allocateWithoutDestructor(sizeof(T))); + } result->clearStructure(); return result; } |