From dd8bb3de4f353a81954234999f1fea748aee2ea9 Mon Sep 17 00:00:00 2001 From: Ben Murdoch Date: Wed, 11 Aug 2010 14:44:44 +0100 Subject: Merge WebKit at r65072 : Initial merge by git. Change-Id: Ibcf418498376b2660aacb7f8d46ea7085ef91585 --- JavaScriptCore/runtime/WeakGCPtr.h | 46 +++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'JavaScriptCore/runtime/WeakGCPtr.h') diff --git a/JavaScriptCore/runtime/WeakGCPtr.h b/JavaScriptCore/runtime/WeakGCPtr.h index 9dce858..ac77cf3 100644 --- a/JavaScriptCore/runtime/WeakGCPtr.h +++ b/JavaScriptCore/runtime/WeakGCPtr.h @@ -27,6 +27,7 @@ #define WeakGCPtr_h #include "Collector.h" +#include "GCHandle.h" #include namespace JSC { @@ -34,23 +35,34 @@ namespace JSC { // A smart pointer whose get() function returns 0 for cells awaiting destruction. template class WeakGCPtr : Noncopyable { public: - WeakGCPtr() : m_ptr(0) { } + WeakGCPtr() + : m_ptr(0) + { + } + WeakGCPtr(T* ptr) { assign(ptr); } + ~WeakGCPtr() + { + if (m_ptr) + m_ptr->pool()->free(m_ptr); + } + T* get() const { - if (!m_ptr || !Heap::isCellMarked(m_ptr)) - return 0; - return m_ptr; + if (m_ptr && m_ptr->isValidPtr()) + return static_cast(m_ptr->get()); + return 0; } - bool clear(JSCell* ptr) + bool clear(JSCell* p) { - if (ptr == m_ptr) { - m_ptr = 0; - return true; - } - return false; + if (!m_ptr || m_ptr->get() != p) + return false; + + m_ptr->pool()->free(m_ptr); + m_ptr = 0; + return true; } T& operator*() const { return *get(); } @@ -62,7 +74,7 @@ public: #if COMPILER(WINSCW) operator bool() const { return m_ptr; } #else - typedef T* WeakGCPtr::*UnspecifiedBoolType; + typedef WeakGCHandle* WeakGCPtr::*UnspecifiedBoolType; operator UnspecifiedBoolType() const { return get() ? &WeakGCPtr::m_ptr : 0; } #endif @@ -73,14 +85,16 @@ public: #endif private: - void assign(T* ptr) + void assign(JSCell* ptr) { ASSERT(ptr); - Heap::markCell(ptr); - m_ptr = ptr; + if (m_ptr) + m_ptr->set(ptr); + else + m_ptr = Heap::heap(ptr)->addWeakGCHandle(ptr); } - T* m_ptr; + WeakGCHandle* m_ptr; }; template inline WeakGCPtr& WeakGCPtr::operator=(T* optr) @@ -129,7 +143,7 @@ template inline WeakGCPtr const_pointer_cast(const W return WeakGCPtr(const_cast(p.get())); } -template inline T* getPtr(const WeakGCPtr& p) +template inline T* get(const WeakGCPtr& p) { return p.get(); } -- cgit v1.1