From b93b09a877cf01a0cd2dc5350bbcc7150c2f94dd Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 27 Jan 2010 18:23:35 -0800 Subject: [PATCH] ObjectWrap fixed - buffers working! --- src/node_object_wrap.h | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/node_object_wrap.h b/src/node_object_wrap.h index 1d3fafa48b..7e26f25b0d 100644 --- a/src/node_object_wrap.h +++ b/src/node_object_wrap.h @@ -13,16 +13,12 @@ class ObjectWrap { } virtual ~ObjectWrap ( ) { - if (!handle_.IsEmpty()) { - assert(handle_.IsNearDeath()); - handle_->SetInternalField(0, v8::Undefined()); - handle_.Dispose(); - handle_.Clear(); - } + assert(handle_.IsNearDeath()); + handle_->SetInternalField(0, v8::Undefined()); + handle_.Dispose(); + handle_.Clear(); } - v8::Persistent handle_; // ro - template static inline T* Unwrap (v8::Handle handle) { @@ -32,6 +28,8 @@ class ObjectWrap { handle->GetInternalField(0))->Value()); } + v8::Persistent handle_; // ro + protected: inline void Wrap (v8::Handle handle) { @@ -53,8 +51,8 @@ class ObjectWrap { */ virtual void Ref() { assert(!handle_.IsEmpty()); - assert(handle_.IsWeak()); refs_++; + handle_.ClearWeak(); } /* Unref() marks an object as detached from the event loop. This is its @@ -68,10 +66,9 @@ class ObjectWrap { */ virtual void Unref() { assert(!handle_.IsEmpty()); - assert(handle_.IsWeak()); + assert(!handle_.IsWeak()); assert(refs_ > 0); - refs_--; - if (refs_ == 0 && handle_.IsNearDeath()) delete this; + if (--refs_ == 0) { MakeWeak(); } } int refs_; // ro @@ -81,11 +78,8 @@ class ObjectWrap { { ObjectWrap *obj = static_cast(data); assert(value == obj->handle_); - if (obj->refs_ == 0) { - delete obj; - } else { - obj->MakeWeak(); - } + assert(!obj->refs_); + if (value.IsNearDeath()) delete obj; } };