test: avoid worker in shared value conveyor test

V8 no longer supports JSON.parse on worker isolates while the shared
string table is enabled. Since --harmony-struct enables that table and
Node workers parse process.config during bootstrap,
use direct MessageChannel instead of a worker.

Signed-Off-By: Michaël Zasso <targos@protonmail.com>
Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65161
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Richard Lau <richard.lau@ibm.com>
This commit is contained in:
Michaël Zasso authored and Antoine du Hamel committed 2026-10-04 22:38:33 +02:00
1 parent 6cf05e7ddc
commit 9b4d1576df
1 file changed
+12 -16
@@ -1,27 +1,23 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const { Worker, parentPort } = require('worker_threads');
const { MessageChannel } = require('worker_threads');
const { spawnSyncAndAssert } = require('../common/child_process');
if (process.env.TEST_CHILD_PROCESS === '1') {
// Do not use isMainThread so that this test itself can be run inside a Worker.
if (!process.env.HAS_STARTED_WORKER) {
process.env.HAS_STARTED_WORKER = 1;
const m = new globalThis.SharedArray(16);
// --harmony-struct implies --shared-string-table. V8 currently does not
// support JSON.parse in worker isolates with that flag, and Node workers
// parse process.config during bootstrap.
const m = new globalThis.SharedArray(16);
const { port1, port2 } = new MessageChannel();
const worker = new Worker(__filename);
worker.once('message', common.mustCall((message) => {
assert.strictEqual(message, m);
}));
port1.once('message', common.mustCall((message) => {
assert.strictEqual(message, m);
port1.close();
port2.close();
}));
worker.postMessage(m);
} else {
parentPort.once('message', common.mustCall((message) => {
// Simple echo.
parentPort.postMessage(message);
}));
}
port2.postMessage(m);
} else {
if (process.config.variables.v8_enable_pointer_compression === 1) {
common.skip('--harmony-struct cannot be used with pointer compression');