Skip to content

Commit

Permalink
remove wrapper_ from napi_wrap examples
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Schulhof <[email protected]>
Fixes: nodejs#140
  • Loading branch information
Gabriel Schulhof committed Aug 5, 2020
1 parent adb6ab3 commit 16112d3
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 21 deletions.
8 changes: 2 additions & 6 deletions 6_object_wrap/napi/myobject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
#include <assert.h>

MyObject::MyObject(double value)
: value_(value), env_(nullptr), wrapper_(nullptr) {}

MyObject::~MyObject() {
napi_delete_reference(env_, wrapper_);
}
: value_(value), env_(nullptr) {}

void MyObject::Destructor(napi_env env,
void* nativeObject,
Expand Down Expand Up @@ -105,7 +101,7 @@ napi_value MyObject::New(napi_env env, napi_callback_info info) {
reinterpret_cast<void*>(obj),
MyObject::Destructor,
nullptr, // finalize_hint
&obj->wrapper_);
nullptr);
assert(status == napi_ok);

return jsthis;
Expand Down
1 change: 0 additions & 1 deletion 6_object_wrap/napi/myobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class MyObject {

double value_;
napi_env env_;
napi_ref wrapper_;
};

#endif // TEST_ADDONS_NAPI_6_OBJECT_WRAP_MYOBJECT_H_
8 changes: 2 additions & 6 deletions 7_factory_wrap/napi/myobject.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#include "myobject.h"
#include <assert.h>

MyObject::MyObject() : env_(nullptr), wrapper_(nullptr) {}

MyObject::~MyObject() {
napi_delete_reference(env_, wrapper_);
}
MyObject::MyObject() : env_(nullptr) {}

void MyObject::Destructor(napi_env env,
void* nativeObject,
Expand Down Expand Up @@ -81,7 +77,7 @@ napi_value MyObject::New(napi_env env, napi_callback_info info) {
reinterpret_cast<void*>(obj),
MyObject::Destructor,
nullptr, /* finalize_hint */
&obj->wrapper_);
nullptr);
assert(status == napi_ok);

return jsthis;
Expand Down
1 change: 0 additions & 1 deletion 7_factory_wrap/napi/myobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class MyObject {
static napi_value PlusOne(napi_env env, napi_callback_info info);
double counter_;
napi_env env_;
napi_ref wrapper_;
};

#endif // TEST_ADDONS_NAPI_7_FACTORY_WRAP_MYOBJECT_H_
8 changes: 2 additions & 6 deletions 8_passing_wrapped/napi/myobject.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#include "myobject.h"
#include <assert.h>

MyObject::MyObject() : env_(nullptr), wrapper_(nullptr) {}

MyObject::~MyObject() {
napi_delete_reference(env_, wrapper_);
}
MyObject::MyObject() : env_(nullptr) {}

void MyObject::Destructor(napi_env env,
void* nativeObject,
Expand Down Expand Up @@ -75,7 +71,7 @@ napi_value MyObject::New(napi_env env, napi_callback_info info) {
reinterpret_cast<void*>(obj),
MyObject::Destructor,
nullptr, // finalize_hint
&obj->wrapper_);
nullptr);
assert(status == napi_ok);

return jsthis;
Expand Down
1 change: 0 additions & 1 deletion 8_passing_wrapped/napi/myobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class MyObject {
static napi_value New(napi_env env, napi_callback_info info);
double val_;
napi_env env_;
napi_ref wrapper_;
};

#endif // TEST_ADDONS_NAPI_8_PASSING_WRAPPED_MYOBJECT_H_

0 comments on commit 16112d3

Please sign in to comment.