diff --git a/src/module/isolate.cc b/src/module/isolate.cc index e206e428..548dcbcc 100644 --- a/src/module/isolate.cc +++ b/src/module/isolate.cc @@ -131,4 +131,6 @@ void init(Local target) { } // namespace ivm -NODE_MODULE_CONTEXT_AWARE(isolated_vm, ivm::init) // NOLINT +NODE_MODULE_INIT(/* exports, module, context */) { + ivm::init(exports); +} diff --git a/tests/worker-reload.js b/tests/worker-reload.js new file mode 100644 index 00000000..674f8cbe --- /dev/null +++ b/tests/worker-reload.js @@ -0,0 +1,18 @@ +const { Worker } = require('worker_threads'); + +if (process.platform === 'win32') { + // unloading the module segfaults on Windows, skip for now + console.log('pass'); + process.exit(); +} + +(async function () { + for (let i = 0; i < 2; i++) { + const worker = new Worker("require('isolated-vm')", { eval: true }); + await new Promise((resolve, reject) => { + worker.on('exit', code => code ? reject(new Error(`Worker exited with code: ${code}`)) : resolve()); + worker.on('error', error => reject(error)); + }); + } + console.log('pass') +})().catch(console.error);