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

Check whether calling into JS is allowed before doing so. PR-URL: https://github.com/nodejs/node/pull/26127 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
24 lines
772 B
JavaScript
24 lines
772 B
JavaScript
'use strict';
|
|
const common = require('../../common');
|
|
const assert = require('assert');
|
|
const { Worker, isMainThread, workerData } = require('worker_threads');
|
|
|
|
if (isMainThread) {
|
|
const counter = new Int32Array(new SharedArrayBuffer(4));
|
|
const worker = new Worker(__filename, { workerData: { counter } });
|
|
worker.on('exit', common.mustCall(() => {
|
|
assert.strictEqual(counter[0], 1);
|
|
}));
|
|
worker.on('error', common.mustNotCall());
|
|
} else {
|
|
const { Test } = require(`./build/${common.buildType}/test_worker_terminate`);
|
|
|
|
const { counter } = workerData;
|
|
// Test() tries to call a function twice and asserts that the second call does
|
|
// not work because of a pending exception.
|
|
Test(() => {
|
|
Atomics.add(counter, 0, 1);
|
|
process.exit();
|
|
});
|
|
}
|