mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 07:27:22 +01:00
5030e81ce3
Adds `napi_set_instance_data()` and `napi_get_instance_data()`, which allow native addons to store their data on and retrieve their data from `napi_env`. `napi_set_instance_data()` accepts a finalizer which is called when the `node::Environment()` is destroyed. This entails rendering the `napi_env` local to each add-on. Fixes: https://github.com/nodejs/abi-stable-node/issues/378 PR-URL: https://github.com/nodejs/node/pull/28682 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
29 lines
674 B
JavaScript
29 lines
674 B
JavaScript
/* eslint-disable node-core/require-common-first, node-core/required-modules */
|
|
'use strict';
|
|
|
|
if (module.parent) {
|
|
const { spawnSync } = require('child_process');
|
|
|
|
function runModuleAs(filename, flags, spawnOptions, role) {
|
|
return spawnSync(process.execPath,
|
|
[...flags, __filename, role, filename], spawnOptions);
|
|
}
|
|
|
|
module.exports = runModuleAs;
|
|
return;
|
|
}
|
|
|
|
const { Worker, isMainThread, workerData } = require('worker_threads');
|
|
|
|
if (isMainThread) {
|
|
if (process.argv[2] === 'worker') {
|
|
new Worker(__filename, {
|
|
workerData: process.argv[3]
|
|
});
|
|
return;
|
|
}
|
|
require(process.argv[3]);
|
|
} else {
|
|
require(workerData);
|
|
}
|