11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst { Worker, parentPort } = 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 const expectation = [ 4, undefined, null ]; 111cb0ef41Sopenharmony_ci const actual = []; 121cb0ef41Sopenharmony_ci w.on('message', common.mustCall((message) => { 131cb0ef41Sopenharmony_ci actual.push(message); 141cb0ef41Sopenharmony_ci if (actual.length === expectation.length) { 151cb0ef41Sopenharmony_ci assert.deepStrictEqual(expectation, actual); 161cb0ef41Sopenharmony_ci w.terminate(); 171cb0ef41Sopenharmony_ci } 181cb0ef41Sopenharmony_ci }, expectation.length)); 191cb0ef41Sopenharmony_ci w.postMessage(2); 201cb0ef41Sopenharmony_ci} else { 211cb0ef41Sopenharmony_ci parentPort.onmessage = common.mustCall((message) => { 221cb0ef41Sopenharmony_ci parentPort.postMessage(message.data * 2); 231cb0ef41Sopenharmony_ci parentPort.postMessage(undefined); 241cb0ef41Sopenharmony_ci parentPort.postMessage(null); 251cb0ef41Sopenharmony_ci }); 261cb0ef41Sopenharmony_ci} 27