1'use strict'; 2 3// This verifies that adding an `uncaughtException` listener in an REPL instance 4// does not suppress errors in the whole application. Adding such listener 5// should throw. 6 7require('../common'); 8const ArrayStream = require('../common/arraystream'); 9const repl = require('repl'); 10const assert = require('assert'); 11 12let accum = ''; 13 14const output = new ArrayStream(); 15output.write = (data) => accum += data.replace('\r', ''); 16 17const r = repl.start({ 18 prompt: '', 19 input: new ArrayStream(), 20 output, 21 terminal: false, 22 useColors: false, 23 global: false 24}); 25 26r.write( 27 'process.nextTick(() => {\n' + 28 ' process.on("uncaughtException", () => console.log("Foo"));\n' + 29 ' throw new TypeError("foobar");\n' + 30 '});\n' 31); 32r.write( 33 'setTimeout(() => {\n' + 34 ' throw new RangeError("abc");\n' + 35 '}, 1);console.log()\n' 36); 37r.close(); 38 39setTimeout(() => { 40 const len = process.listenerCount('uncaughtException'); 41 process.removeAllListeners('uncaughtException'); 42 assert.strictEqual(len, 0); 43 assert(/ERR_INVALID_REPL_INPUT.*(?!Type)RangeError: abc/s.test(accum)); 44}, 2); 45