-
-
Notifications
You must be signed in to change notification settings - Fork 497
Expand file tree
/
Copy pathobjectwrap_removewrap.cc
More file actions
45 lines (36 loc) · 1021 Bytes
/
objectwrap_removewrap.cc
File metadata and controls
45 lines (36 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <assert.h>
#include <napi.h>
namespace {
static int dtor_called = 0;
class DtorCounter {
public:
~DtorCounter() {
assert(dtor_called == 0);
dtor_called++;
}
};
Napi::Value GetDtorCalled(const Napi::CallbackInfo& info) {
return Napi::Number::New(info.Env(), dtor_called);
}
class Test : public Napi::ObjectWrap<Test> {
public:
Test(const Napi::CallbackInfo& info) : Napi::ObjectWrap<Test>(info) {
#ifdef NAPI_CPP_EXCEPTIONS
throw Napi::Error::New(Env(), "Some error");
#else
Napi::Error::New(Env(), "Some error").ThrowAsJavaScriptException();
#endif
}
static void Initialize(Napi::Env env, Napi::Object exports) {
exports.Set("Test", DefineClass(env, "Test", {}));
exports.Set("getDtorCalled", Napi::Function::New(env, GetDtorCalled));
}
private:
DtorCounter dtor_counter_;
};
} // anonymous namespace
Napi::Object InitObjectWrapRemoveWrap(Napi::Env env) {
Napi::Object exports = Napi::Object::New(env);
Test::Initialize(env, exports);
return exports;
}