1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const { Worker } = require('worker_threads'); 5 6// Check that `process.exit()` can be called inside a Worker from an uncaught 7// exception handler. 8 9// Do not use isMainThread so that this test itself can be run inside a Worker. 10if (!process.env.HAS_STARTED_WORKER) { 11 process.env.HAS_STARTED_WORKER = 1; 12 const w = new Worker(__filename); 13 w.on('exit', common.mustCall((code) => { 14 assert.strictEqual(code, 42); 15 })); 16 return; 17} 18 19process.on('uncaughtException', () => { 20 process.exit(42); 21}); 22 23throw new Error(); 24