mirror of
https://github.com/nodejs/node.git
synced 2025-05-05 01:22:05 +00:00

Allow loading add-ons from multiple Node.js instances if they are declared context-aware; in particular, this applies to N-API addons. Also, plug a memory leak that occurred when registering N-API addons. Refs: https://github.com/nodejs/node/pull/23319 PR-URL: https://github.com/nodejs/node/pull/26175 Fixes: https://github.com/nodejs/node/issues/21481 Fixes: https://github.com/nodejs/node/issues/21783 Fixes: https://github.com/nodejs/node/issues/25662 Fixes: https://github.com/nodejs/node/issues/20239 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
23 lines
891 B
JavaScript
23 lines
891 B
JavaScript
'use strict';
|
|
const common = require('../../common');
|
|
const assert = require('assert');
|
|
const { Worker } = require('worker_threads');
|
|
|
|
const bindingPath = require.resolve(`./build/${common.buildType}/binding`);
|
|
const binding = require(bindingPath);
|
|
assert.strictEqual(binding.hello(), 'world');
|
|
console.log('binding.hello() =', binding.hello());
|
|
|
|
// Test multiple loading of the same module.
|
|
delete require.cache[bindingPath];
|
|
const rebinding = require(bindingPath);
|
|
assert.strictEqual(rebinding.hello(), 'world');
|
|
assert.notStrictEqual(binding.hello, rebinding.hello);
|
|
|
|
// Test that workers can load addons declared using NAPI_MODULE_INIT().
|
|
new Worker(`
|
|
const { parentPort } = require('worker_threads');
|
|
const msg = require(${JSON.stringify(bindingPath)}).hello();
|
|
parentPort.postMessage(msg)`, { eval: true })
|
|
.on('message', common.mustCall((msg) => assert.strictEqual(msg, 'world')));
|