From 3ca25ae0bd7e4ac870c2caba9858b7c7eab763ae Mon Sep 17 00:00:00 2001 From: David Halls Date: Wed, 13 May 2020 23:03:15 +0100 Subject: [PATCH 1/2] Add test for ObjectWrap destructor (no HandleScope exception) --- test/index.js | 1 + test/objectwrap.cc | 10 ++++++++++ test/objectwrap_worker_thread.js | 14 ++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 test/objectwrap_worker_thread.js diff --git a/test/index.js b/test/index.js index 86939af84..b70c33b31 100644 --- a/test/index.js +++ b/test/index.js @@ -55,6 +55,7 @@ let testModules = [ 'objectwrap_constructor_exception', 'objectwrap-removewrap', 'objectwrap_multiple_inheritance', + 'objectwrap_worker_thread', 'objectreference', 'reference', 'version_management' diff --git a/test/objectwrap.cc b/test/objectwrap.cc index 92a29ce74..2ffc85a25 100644 --- a/test/objectwrap.cc +++ b/test/objectwrap.cc @@ -40,6 +40,14 @@ class Test : public Napi::ObjectWrap { info.This().As().DefineProperty( Napi::PropertyDescriptor::Accessor("ownPropertyT", napi_enumerable, this)); + + bufref_ = Napi::Persistent(Napi::Buffer::New( + Env(), + static_cast(malloc(1)), + 1, + [](Napi::Env, uint8_t* bufaddr) { + free(bufaddr); + })); } static Napi::Value OwnPropertyGetter(const Napi::CallbackInfo& info) { @@ -183,6 +191,8 @@ class Test : public Napi::ObjectWrap { Napi::FunctionReference finalizeCb_; static std::string s_staticMethodText; + + Napi::Reference> bufref_; }; std::string Test::s_staticMethodText; diff --git a/test/objectwrap_worker_thread.js b/test/objectwrap_worker_thread.js new file mode 100644 index 000000000..348309976 --- /dev/null +++ b/test/objectwrap_worker_thread.js @@ -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`)); +} From 51452e00b43cd51a40dd5eb726e8289e47f13ca5 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Mon, 24 Aug 2020 15:30:27 -0400 Subject: [PATCH 2/2] squash: exclude test for Node.js less than version 10 Signed-off-by: Michael Dawson --- test/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/index.js b/test/index.js index b70c33b31..33b128da0 100644 --- a/test/index.js +++ b/test/index.js @@ -91,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}'.`);