node/test/addons/dlopen-ping-pong/test-worker.js
Anna Henningsen 8ebd339031
worker: improve integration with native addons
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>
2019-02-22 21:42:09 +01:00

21 lines
670 B
JavaScript

'use strict';
const common = require('../../common');
if (common.isWindows)
common.skip('dlopen global symbol loading is not supported on this os.');
const assert = require('assert');
const { Worker } = require('worker_threads');
// Check that modules that are not declared as context-aware cannot be re-loaded
// from workers.
const bindingPath = require.resolve(`./build/${common.buildType}/binding`);
require(bindingPath);
new Worker(`require(${JSON.stringify(bindingPath)})`, { eval: true })
.on('error', common.mustCall((err) => {
assert.strictEqual(err.constructor, Error);
assert.strictEqual(err.message, 'Module did not self-register.');
}));