1// When MessagePort.onmessage is set to a value that is not a function, the 2// setter should call .unref() and .stop(), clearing a previous onmessage 3// listener from holding the event loop open. This test confirms that 4// functionality. 5 6'use strict'; 7const common = require('../common'); 8const { Worker, parentPort } = require('worker_threads'); 9 10// Do not use isMainThread so that this test itself can be run inside a Worker. 11if (!process.env.HAS_STARTED_WORKER) { 12 process.env.HAS_STARTED_WORKER = 1; 13 const w = new Worker(__filename); 14 w.postMessage(2); 15} else { 16 // .onmessage uses a setter. Set .onmessage to a function that ultimately 17 // should not be called. This will call .ref() and .start() which will keep 18 // the event loop open (and prevent this from exiting) if the subsequent 19 // assignment of a value to .onmessage doesn't call .unref() and .stop(). 20 parentPort.onmessage = common.mustNotCall(); 21 // Setting `onmessage` to a value that is not a function should clear the 22 // previous value and also should allow the event loop to exit. (In other 23 // words, this test should exit rather than run indefinitely.) 24 parentPort.onmessage = 'fhqwhgads'; 25} 26