Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ObjectWrap destructor from env exit under node_g #729

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ let testModules = [
'objectwrap_constructor_exception',
'objectwrap-removewrap',
'objectwrap_multiple_inheritance',
'objectwrap_worker_thread',
'objectreference',
'reference',
'version_management'
Expand Down Expand Up @@ -90,6 +91,10 @@ if (napiVersion < 6) {
testModules.splice(testModules.indexOf('typedarray-bigint'), 1);
}

if (majorNodeVersion < 12) {
testModules.splice(testModules.indexOf('objectwrap_worker_thread'), 1);
}

if (typeof global.gc === 'function') {
(async function() {
console.log(`Testing with N-API Version '${napiVersion}'.`);
Expand Down
10 changes: 10 additions & 0 deletions test/objectwrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ class Test : public Napi::ObjectWrap<Test> {
info.This().As<Napi::Object>().DefineProperty(
Napi::PropertyDescriptor::Accessor<OwnPropertyGetter>("ownPropertyT",
napi_enumerable, this));

bufref_ = Napi::Persistent(Napi::Buffer<uint8_t>::New(
Env(),
static_cast<uint8_t*>(malloc(1)),
1,
[](Napi::Env, uint8_t* bufaddr) {
free(bufaddr);
}));
}

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

static std::string s_staticMethodText;

Napi::Reference<Napi::Buffer<uint8_t>> bufref_;
};

std::string Test::s_staticMethodText;
Expand Down
14 changes: 14 additions & 0 deletions test/objectwrap_worker_thread.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';
const buildType = process.config.target_defaults.default_configuration;
const { Worker, isMainThread } = require('worker_threads');

if (isMainThread) {
new Worker(__filename);
} else {
const test = binding => {
new binding.objectwrap.Test();
};

test(require(`./build/${buildType}/binding.node`));
test(require(`./build/${buildType}/binding_noexcept.node`));
}