| Index: Source/bindings/v8/GarbageCollected.h
|
| diff --git a/Source/bindings/v8/SharedPersistent.h b/Source/bindings/v8/GarbageCollected.h
|
| similarity index 59%
|
| copy from Source/bindings/v8/SharedPersistent.h
|
| copy to Source/bindings/v8/GarbageCollected.h
|
| index 52cc1196f348e14168c6fbaf9332d475d76e5055..c21f421fac2b3ce52c0818d9b71de753bce0188d 100644
|
| --- a/Source/bindings/v8/SharedPersistent.h
|
| +++ b/Source/bindings/v8/GarbageCollected.h
|
| @@ -28,42 +28,51 @@
|
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| */
|
|
|
| -#ifndef SharedPersistent_h
|
| -#define SharedPersistent_h
|
| +#ifndef GarbageCollected_h
|
| +#define GarbageCollected_h
|
|
|
| #include "bindings/v8/ScopedPersistent.h"
|
| -#include <v8.h>
|
| -#include "wtf/PassRefPtr.h"
|
| -#include "wtf/RefCounted.h"
|
|
|
| namespace WebCore {
|
|
|
| - template <typename T>
|
| - class SharedPersistent : public RefCounted<SharedPersistent<T> > {
|
| - WTF_MAKE_NONCOPYABLE(SharedPersistent);
|
| - public:
|
| - static PassRefPtr<SharedPersistent<T> > create(v8::Handle<T> value)
|
| - {
|
| - return adoptRef(new SharedPersistent<T>(value));
|
| - }
|
| +template<typename T>
|
| +class GarbageCollected {
|
| + WTF_MAKE_NONCOPYABLE(GarbageCollected);
|
| +public:
|
| + static T* Cast(v8::Handle<v8::Value> value)
|
| + {
|
| + ASSERT(value->IsExternal());
|
| + T* result = static_cast<T*>(value.As<v8::External>()->Value());
|
| + RELEASE_ASSERT(result->m_handle == value);
|
| + return result;
|
| + }
|
|
|
| - v8::Local<T> newLocal(v8::Isolate* isolate) const
|
| - {
|
| - return m_value.newLocal(isolate);
|
| - }
|
| +protected:
|
| + GarbageCollected() : m_handle(v8::External::New(static_cast<T*>(this))) { }
|
|
|
| - bool isEmpty() { return m_value.isEmpty(); }
|
| + v8::Handle<v8::External> releaseToGarbageCollector()
|
| + {
|
| + ASSERT(!m_handle.isWeak()); // Call releaseToGarbageCollector exactly once.
|
| + v8::Handle<v8::External> result = m_handle.newLocal(v8::Isolate::GetCurrent());
|
| + m_handle.makeWeak(static_cast<T*>(this), weakCallback);
|
| + return result;
|
| + }
|
|
|
| - bool operator==(const SharedPersistent<T>& other)
|
| - {
|
| - return m_value == other.m_value;
|
| - }
|
| + ~GarbageCollected()
|
| + {
|
| + ASSERT(m_handle.isEmpty());
|
| + }
|
|
|
| - private:
|
| - explicit SharedPersistent(v8::Handle<T> value) : m_value(value) { }
|
| - ScopedPersistent<T> m_value;
|
| - };
|
| +private:
|
| + static void weakCallback(v8::Isolate* isolate, v8::Persistent<v8::External>* handle, T* self)
|
| + {
|
| + self->m_handle.clear();
|
| + delete self;
|
| + }
|
| +
|
| + ScopedPersistent<v8::External> m_handle;
|
| +};
|
|
|
| } // namespace WebCore
|
|
|
| -#endif // SharedPersistent_h
|
| +#endif // GarbageCollected_h
|
|
|