Skip to content
This repository
Browse code

ObjectWrap fixed - buffers working!

Hot bug fix from net2 branch.
  • Loading branch information...
commit b06dda1f5e6d89fc8412a7b14bb23a6582a40850 1 parent 5a70224
ry ry authored

Showing 1 changed file with 12 additions and 17 deletions. Show diff stats Hide diff stats

  1. +12 17 src/node_object_wrap.h
29 src/node_object_wrap.h
@@ -13,15 +13,12 @@ class ObjectWrap {
13 13 }
14 14
15 15 virtual ~ObjectWrap ( ) {
16   - if (!handle_.IsEmpty()) {
17   - assert(handle_.IsNearDeath());
18   - handle_->SetInternalField(0, v8::Undefined());
19   - handle_.Dispose();
20   - handle_.Clear();
21   - }
  16 + assert(handle_.IsNearDeath());
  17 + handle_->SetInternalField(0, v8::Undefined());
  18 + handle_.Dispose();
  19 + handle_.Clear();
22 20 }
23 21
24   - protected:
25 22 template <class T>
26 23 static inline T* Unwrap (v8::Handle<v8::Object> handle)
27 24 {
@@ -31,6 +28,9 @@ class ObjectWrap {
31 28 handle->GetInternalField(0))->Value());
32 29 }
33 30
  31 + v8::Persistent<v8::Object> handle_; // ro
  32 +
  33 + protected:
34 34 inline void Wrap (v8::Handle<v8::Object> handle)
35 35 {
36 36 assert(handle_.IsEmpty());
@@ -51,8 +51,8 @@ class ObjectWrap {
51 51 */
52 52 virtual void Ref() {
53 53 assert(!handle_.IsEmpty());
54   - assert(handle_.IsWeak());
55 54 refs_++;
  55 + handle_.ClearWeak();
56 56 }
57 57
58 58 /* Unref() marks an object as detached from the event loop. This is its
@@ -66,13 +66,11 @@ class ObjectWrap {
66 66 */
67 67 virtual void Unref() {
68 68 assert(!handle_.IsEmpty());
69   - assert(handle_.IsWeak());
  69 + assert(!handle_.IsWeak());
70 70 assert(refs_ > 0);
71   - refs_--;
72   - if (refs_ == 0 && handle_.IsNearDeath()) delete this;
  71 + if (--refs_ == 0) { MakeWeak(); }
73 72 }
74 73
75   - v8::Persistent<v8::Object> handle_; // ro
76 74 int refs_; // ro
77 75
78 76 private:
@@ -80,11 +78,8 @@ class ObjectWrap {
80 78 {
81 79 ObjectWrap *obj = static_cast<ObjectWrap*>(data);
82 80 assert(value == obj->handle_);
83   - if (obj->refs_ == 0) {
84   - delete obj;
85   - } else {
86   - obj->MakeWeak();
87   - }
  81 + assert(!obj->refs_);
  82 + if (value.IsNearDeath()) delete obj;
88 83 }
89 84 };
90 85

0 comments on commit b06dda1

Please sign in to comment.
Something went wrong with that request. Please try again.