diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2010-01-27 18:23:35 -0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-01-27 18:33:15 -0800 |
commit | b06dda1f5e6d89fc8412a7b14bb23a6582a40850 (patch) | |
tree | f8918009c093ae37b8624c4409db2a03d17aedaf /src/node_object_wrap.h | |
parent | 5a702240813b172d096961edb4c461973b09998b (diff) | |
download | node-new-b06dda1f5e6d89fc8412a7b14bb23a6582a40850.tar.gz |
ObjectWrap fixed - buffers working!
Hot bug fix from net2 branch.
Diffstat (limited to 'src/node_object_wrap.h')
-rw-r--r-- | src/node_object_wrap.h | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/src/node_object_wrap.h b/src/node_object_wrap.h index 6656664bdf..7e26f25b0d 100644 --- a/src/node_object_wrap.h +++ b/src/node_object_wrap.h @@ -13,15 +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(); } - protected: template <class T> static inline T* Unwrap (v8::Handle<v8::Object> handle) { @@ -31,6 +28,9 @@ class ObjectWrap { handle->GetInternalField(0))->Value()); } + v8::Persistent<v8::Object> handle_; // ro + + protected: inline void Wrap (v8::Handle<v8::Object> handle) { assert(handle_.IsEmpty()); @@ -51,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 @@ -66,13 +66,11 @@ 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(); } } - v8::Persistent<v8::Object> handle_; // ro int refs_; // ro private: @@ -80,11 +78,8 @@ class ObjectWrap { { ObjectWrap *obj = static_cast<ObjectWrap*>(data); assert(value == obj->handle_); - if (obj->refs_ == 0) { - delete obj; - } else { - obj->MakeWeak(); - } + assert(!obj->refs_); + if (value.IsNearDeath()) delete obj; } }; |