|
2 | 2 | const common = require('../common'); |
3 | 3 | const assert = require('assert'); |
4 | 4 | const { spawnSync } = require('child_process'); |
5 | | -const { Worker, parentPort } = require('worker_threads'); |
| 5 | +const { MessageChannel } = require('worker_threads'); |
6 | 6 |
|
7 | 7 | if (process.env.TEST_CHILD_PROCESS === '1') { |
8 | | - // Do not use isMainThread so that this test itself can be run inside a Worker. |
9 | | - if (!process.env.HAS_STARTED_WORKER) { |
10 | | - process.env.HAS_STARTED_WORKER = 1; |
11 | | - const m = new globalThis.SharedArray(16); |
| 8 | + // --harmony-struct implies --shared-string-table. V8 currently does not |
| 9 | + // support JSON.parse in worker isolates with that flag, and Node workers |
| 10 | + // parse process.config during bootstrap. |
| 11 | + const m = new globalThis.SharedArray(16); |
| 12 | + const { port1, port2 } = new MessageChannel(); |
12 | 13 |
|
13 | | - const worker = new Worker(__filename); |
14 | | - worker.once('message', common.mustCall((message) => { |
15 | | - assert.strictEqual(message, m); |
16 | | - })); |
| 14 | + port1.once('message', common.mustCall((message) => { |
| 15 | + assert.strictEqual(message, m); |
| 16 | + port1.close(); |
| 17 | + port2.close(); |
| 18 | + })); |
17 | 19 |
|
18 | | - worker.postMessage(m); |
19 | | - } else { |
20 | | - parentPort.once('message', common.mustCall((message) => { |
21 | | - // Simple echo. |
22 | | - parentPort.postMessage(message); |
23 | | - })); |
24 | | - } |
| 20 | + port2.postMessage(m); |
25 | 21 | } else { |
26 | 22 | if (process.config.variables.v8_enable_pointer_compression === 1) { |
27 | 23 | common.skip('--harmony-struct cannot be used with pointer compression'); |
|
0 commit comments