11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciconst { parentPort, MessageChannel, Worker } = require('worker_threads'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ci// Do not use isMainThread so that this test itself can be run inside a Worker. 71cb0ef41Sopenharmony_ciif (!process.env.HAS_STARTED_WORKER) { 81cb0ef41Sopenharmony_ci process.env.HAS_STARTED_WORKER = 1; 91cb0ef41Sopenharmony_ci const w = new Worker(__filename); 101cb0ef41Sopenharmony_ci w.once('message', common.mustCall(() => { 111cb0ef41Sopenharmony_ci w.once('message', common.mustNotCall()); 121cb0ef41Sopenharmony_ci setTimeout(() => w.terminate(), 100); 131cb0ef41Sopenharmony_ci })); 141cb0ef41Sopenharmony_ci} else { 151cb0ef41Sopenharmony_ci const { port1 } = new MessageChannel(); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci parentPort.postMessage('ready'); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci // Make sure we don’t end up running JS after the infinite loop is broken. 201cb0ef41Sopenharmony_ci port1.postMessage({}, { 211cb0ef41Sopenharmony_ci // eslint-disable-next-line require-yield 221cb0ef41Sopenharmony_ci transfer: (function*() { while (true); })() 231cb0ef41Sopenharmony_ci }); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci parentPort.postMessage('UNREACHABLE'); 261cb0ef41Sopenharmony_ci process.kill(process.pid, 'SIGINT'); 271cb0ef41Sopenharmony_ci} 28