diff --git a/test/index.js b/test/index.js index 86939af84..33b128da0 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' @@ -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}'.`); 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`)); +}