Skip to content

Commit

Permalink
test: test ObjectWrap destructor - no HandleScope
Browse files Browse the repository at this point in the history
Add test for ObjectWrap destructor (no HandleScope exception)

REFS: #722
PR-URL: #729
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
davedoesdev authored and mhdawson committed Aug 24, 2020
1 parent c2cbbd9 commit 518cfdc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
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`));
}

0 comments on commit 518cfdc

Please sign in to comment.