1'use strict'; 2const common = require('../common'); 3 4// https://github.com/nodejs/node/issues/45421 5// 6// Check that node will NOT call v8::Isolate::SetIdle() when exiting 7// due to an unhandled exception, otherwise the assertion(enabled in 8// debug build only) in the SetIdle(), which checks that the vm state 9// is either EXTERNAL or IDLE will fail. 10// 11// The root cause of this issue is that before PerIsolateMessageListener() 12// is invoked by v8, v8 preserves the JS vm state, although it should 13// switch to EXTERNEL. https://bugs.chromium.org/p/v8/issues/detail?id=13464 14// 15// Therefore, this commit can be considered as an workaround of the v8 bug, 16// but we also find it not useful to call SetIdle() when terminating. 17 18if (process.argv[2] === 'child') { 19 const { Worker } = require('worker_threads'); 20 new Worker('', { eval: true }); 21 throw new Error('xxx'); 22} else { 23 const assert = require('assert'); 24 const { spawnSync } = require('child_process'); 25 const result = spawnSync(process.execPath, [__filename, 'child']); 26 27 const stderr = result.stderr.toString().trim(); 28 // Expect error message to be preserved 29 assert.match(stderr, /xxx/); 30 // Expect no crash 31 assert(!common.nodeProcessAborted(result.status, result.signal), stderr); 32} 33