Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
ObjectWrap fixed - buffers working!
Browse files Browse the repository at this point in the history
Hot bug fix from net2 branch.
  • Loading branch information
ry committed Jan 28, 2010
1 parent 5a70224 commit b06dda1
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/node_object_wrap.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@ class ObjectWrap {
} }


virtual ~ObjectWrap ( ) { virtual ~ObjectWrap ( ) {
if (!handle_.IsEmpty()) { assert(handle_.IsNearDeath());
assert(handle_.IsNearDeath()); handle_->SetInternalField(0, v8::Undefined());
handle_->SetInternalField(0, v8::Undefined()); handle_.Dispose();
handle_.Dispose(); handle_.Clear();
handle_.Clear();
}
} }


protected:
template <class T> template <class T>
static inline T* Unwrap (v8::Handle<v8::Object> handle) static inline T* Unwrap (v8::Handle<v8::Object> handle)
{ {
Expand All @@ -31,6 +28,9 @@ class ObjectWrap {
handle->GetInternalField(0))->Value()); handle->GetInternalField(0))->Value());
} }


v8::Persistent<v8::Object> handle_; // ro

protected:
inline void Wrap (v8::Handle<v8::Object> handle) inline void Wrap (v8::Handle<v8::Object> handle)
{ {
assert(handle_.IsEmpty()); assert(handle_.IsEmpty());
Expand All @@ -51,8 +51,8 @@ class ObjectWrap {
*/ */
virtual void Ref() { virtual void Ref() {
assert(!handle_.IsEmpty()); assert(!handle_.IsEmpty());
assert(handle_.IsWeak());
refs_++; refs_++;
handle_.ClearWeak();
} }


/* Unref() marks an object as detached from the event loop. This is its /* Unref() marks an object as detached from the event loop. This is its
Expand All @@ -66,25 +66,20 @@ class ObjectWrap {
*/ */
virtual void Unref() { virtual void Unref() {
assert(!handle_.IsEmpty()); assert(!handle_.IsEmpty());
assert(handle_.IsWeak()); assert(!handle_.IsWeak());
assert(refs_ > 0); assert(refs_ > 0);
refs_--; if (--refs_ == 0) { MakeWeak(); }
if (refs_ == 0 && handle_.IsNearDeath()) delete this;
} }


v8::Persistent<v8::Object> handle_; // ro
int refs_; // ro int refs_; // ro


private: private:
static void WeakCallback (v8::Persistent<v8::Value> value, void *data) static void WeakCallback (v8::Persistent<v8::Value> value, void *data)
{ {
ObjectWrap *obj = static_cast<ObjectWrap*>(data); ObjectWrap *obj = static_cast<ObjectWrap*>(data);
assert(value == obj->handle_); assert(value == obj->handle_);
if (obj->refs_ == 0) { assert(!obj->refs_);
delete obj; if (value.IsNearDeath()) delete obj;
} else {
obj->MakeWeak();
}
} }
}; };


Expand Down

0 comments on commit b06dda1

Please sign in to comment.