1'use strict'; 2require('../common'); 3const tmpdir = require('../common/tmpdir'); 4const assert = require('assert'); 5const path = require('path'); 6const child_process = require('child_process'); 7 8tmpdir.refresh(); 9 10// Tests that exceptions from the PromiseRejectCallback are printed to stderr 11// when they occur as a best-effort way of handling them, and that calling 12// `console.log()` works after that. Earlier, the latter did not work because 13// of the exception left lying around by the PromiseRejectCallback when its JS 14// part exceeded the call stack limit, and when the inspector/built-in coverage 15// was enabled, it resulted in a hard crash. 16 17for (const NODE_V8_COVERAGE of ['', tmpdir.path]) { 18 // NODE_V8_COVERAGE does not work without the inspector. 19 // Refs: https://github.com/nodejs/node/issues/29542 20 if (!process.features.inspector && NODE_V8_COVERAGE !== '') continue; 21 22 const { status, signal, stdout, stderr } = 23 child_process.spawnSync(process.execPath, 24 [path.join(__dirname, 'test-ttywrap-stack.js')], 25 { env: { ...process.env, NODE_V8_COVERAGE } }); 26 27 assert(stdout.toString('utf8') 28 .startsWith('RangeError: Maximum call stack size exceeded'), 29 `stdout: <${stdout}>`); 30 assert(stderr.toString('utf8') 31 .startsWith('Exception in PromiseRejectCallback'), 32 `stderr: <${stderr}>`); 33 assert.strictEqual(status, 0); 34 assert.strictEqual(signal, null); 35} 36