Skip to content

Commit 518cfdc

Browse files
davedoesdevmhdawson
authored andcommitted
test: test ObjectWrap destructor - no HandleScope
Add test for ObjectWrap destructor (no HandleScope exception) REFS: #722 PR-URL: #729 Reviewed-By: Michael Dawson <[email protected]>
1 parent c2cbbd9 commit 518cfdc

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

test/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ let testModules = [
5555
'objectwrap_constructor_exception',
5656
'objectwrap-removewrap',
5757
'objectwrap_multiple_inheritance',
58+
'objectwrap_worker_thread',
5859
'objectreference',
5960
'reference',
6061
'version_management'
@@ -90,6 +91,10 @@ if (napiVersion < 6) {
9091
testModules.splice(testModules.indexOf('typedarray-bigint'), 1);
9192
}
9293

94+
if (majorNodeVersion < 12) {
95+
testModules.splice(testModules.indexOf('objectwrap_worker_thread'), 1);
96+
}
97+
9398
if (typeof global.gc === 'function') {
9499
(async function() {
95100
console.log(`Testing with N-API Version '${napiVersion}'.`);

test/objectwrap.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ class Test : public Napi::ObjectWrap<Test> {
4040
info.This().As<Napi::Object>().DefineProperty(
4141
Napi::PropertyDescriptor::Accessor<OwnPropertyGetter>("ownPropertyT",
4242
napi_enumerable, this));
43+
44+
bufref_ = Napi::Persistent(Napi::Buffer<uint8_t>::New(
45+
Env(),
46+
static_cast<uint8_t*>(malloc(1)),
47+
1,
48+
[](Napi::Env, uint8_t* bufaddr) {
49+
free(bufaddr);
50+
}));
4351
}
4452

4553
static Napi::Value OwnPropertyGetter(const Napi::CallbackInfo& info) {
@@ -183,6 +191,8 @@ class Test : public Napi::ObjectWrap<Test> {
183191
Napi::FunctionReference finalizeCb_;
184192

185193
static std::string s_staticMethodText;
194+
195+
Napi::Reference<Napi::Buffer<uint8_t>> bufref_;
186196
};
187197

188198
std::string Test::s_staticMethodText;

test/objectwrap_worker_thread.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
const buildType = process.config.target_defaults.default_configuration;
3+
const { Worker, isMainThread } = require('worker_threads');
4+
5+
if (isMainThread) {
6+
new Worker(__filename);
7+
} else {
8+
const test = binding => {
9+
new binding.objectwrap.Test();
10+
};
11+
12+
test(require(`./build/${buildType}/binding.node`));
13+
test(require(`./build/${buildType}/binding_noexcept.node`));
14+
}

0 commit comments

Comments
 (0)