1'use strict'; 2const common = require('../common'); 3 4const { parentPort, MessageChannel, Worker } = require('worker_threads'); 5 6// Do not use isMainThread so that this test itself can be run inside a Worker. 7if (!process.env.HAS_STARTED_WORKER) { 8 process.env.HAS_STARTED_WORKER = 1; 9 const w = new Worker(__filename); 10 w.once('message', common.mustCall(() => { 11 w.once('message', common.mustNotCall()); 12 setTimeout(() => w.terminate(), 100); 13 })); 14} else { 15 const { port1 } = new MessageChannel(); 16 17 parentPort.postMessage('ready'); 18 19 // Make sure we don’t end up running JS after the infinite loop is broken. 20 port1.postMessage({}, { 21 // eslint-disable-next-line require-yield 22 transfer: (function*() { while (true); })() 23 }); 24 25 parentPort.postMessage('UNREACHABLE'); 26 process.kill(process.pid, 'SIGINT'); 27} 28