X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/14957cd040308e3eeec43d26bae5d76da13fcd85..40a37d088818fc2fbeba2ef850dbcaaf294befbf:/heap/Strong.h?ds=sidebyside diff --git a/heap/Strong.h b/heap/Strong.h index 9f2aa05..27ab5d3 100644 --- a/heap/Strong.h +++ b/heap/Strong.h @@ -26,19 +26,19 @@ #ifndef Strong_h #define Strong_h -#include "Assertions.h" +#include #include "Handle.h" -#include "HandleHeap.h" +#include "HandleSet.h" namespace JSC { -class JSGlobalData; -HandleSlot allocateGlobalHandle(JSGlobalData&); +class VM; // A strongly referenced handle that prevents the object it points to from being garbage collected. template class Strong : public Handle { using Handle::slot; using Handle::setSlot; + template friend class Strong; public: typedef typename Handle::ExternalType ExternalType; @@ -48,24 +48,16 @@ public: { } - Strong(JSGlobalData& globalData, ExternalType value = ExternalType()) - : Handle(allocateGlobalHandle(globalData)) - { - set(value); - } + Strong(VM&, ExternalType = ExternalType()); - Strong(JSGlobalData& globalData, Handle handle) - : Handle(allocateGlobalHandle(globalData)) - { - set(handle.get()); - } + Strong(VM&, Handle); Strong(const Strong& other) : Handle() { if (!other.slot()) return; - setSlot(HandleHeap::heapFor(other.slot())->allocate()); + setSlot(HandleSet::heapFor(other.slot())->allocate()); set(other.get()); } @@ -74,7 +66,7 @@ public: { if (!other.slot()) return; - setSlot(HandleHeap::heapFor(other.slot())->allocate()); + setSlot(HandleSet::heapFor(other.slot())->allocate()); set(other.get()); } @@ -90,17 +82,20 @@ public: clear(); } + bool operator!() const { return !slot() || !*slot(); } + + // This conversion operator allows implicit conversion to bool but not to other integer types. + typedef JSValue (HandleBase::*UnspecifiedBoolType); + operator UnspecifiedBoolType*() const { return !!*this ? reinterpret_cast(1) : 0; } + void swap(Strong& other) { Handle::swap(other); } - void set(JSGlobalData& globalData, ExternalType value) - { - if (!slot()) - setSlot(allocateGlobalHandle(globalData)); - set(value); - } + ExternalType get() const { return HandleTypes::getFromSlot(this->slot()); } + + void set(VM&, ExternalType); template Strong& operator=(const Strong& other) { @@ -109,7 +104,7 @@ public: return *this; } - set(*HandleHeap::heapFor(other.slot())->globalData(), other.get()); + set(*HandleSet::heapFor(other.slot())->vm(), other.get()); return *this; } @@ -120,7 +115,7 @@ public: return *this; } - set(*HandleHeap::heapFor(other.slot())->globalData(), other.get()); + set(*HandleSet::heapFor(other.slot())->vm(), other.get()); return *this; } @@ -128,7 +123,7 @@ public: { if (!slot()) return; - HandleHeap::heapFor(slot())->deallocate(slot()); + HandleSet::heapFor(slot())->deallocate(slot()); setSlot(0); } @@ -139,7 +134,7 @@ private: { ASSERT(slot()); JSValue value = HandleTypes::toJSValue(externalType); - HandleHeap::heapFor(slot())->writeBarrier(slot(), value); + HandleSet::heapFor(slot())->writeBarrier(slot(), value); *slot() = value; } }; @@ -153,11 +148,11 @@ template inline void swap(Strong& a, Strong& b) namespace WTF { -template struct VectorTraits > : SimpleClassVectorTraits { +template struct VectorTraits> : SimpleClassVectorTraits { static const bool canCompareWithMemcmp = false; }; -template struct HashTraits > : SimpleClassHashTraits > { }; +template struct HashTraits> : SimpleClassHashTraits> { }; }