1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const { Worker } = require('worker_threads'); 5 6// Test that 'exit' is emitted if 'beforeExit' throws, both inside the Worker. 7 8const workerData = new Uint8Array(new SharedArrayBuffer(2)); 9const w = new Worker(` 10 const { workerData } = require('worker_threads'); 11 process.on('exit', () => { 12 workerData[0] = 100; 13 }); 14 process.on('beforeExit', () => { 15 workerData[1] = 200; 16 throw new Error('banana'); 17 }); 18`, { eval: true, workerData }); 19 20w.on('error', common.mustCall((err) => { 21 assert.strictEqual(err.message, 'banana'); 22})); 23 24w.on('exit', common.mustCall((code) => { 25 assert.strictEqual(code, 1); 26 assert.strictEqual(workerData[0], 100); 27 assert.strictEqual(workerData[1], 200); 28})); 29