diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-05-17 16:25:36 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-05-08 08:15:15 +0200 |
commit | 422e8f762873aef4a37185f3237c0d666c929d8e (patch) | |
tree | e56695393ab0bfe6445a76541502354506916f29 /test/parallel/test-repl-uncaught-exception-standalone.js | |
parent | 9a174db3d869c8d5cde9e09db92d88d0d97e9513 (diff) | |
download | android-node-v8-422e8f762873aef4a37185f3237c0d666c929d8e.tar.gz android-node-v8-422e8f762873aef4a37185f3237c0d666c929d8e.tar.bz2 android-node-v8-422e8f762873aef4a37185f3237c0d666c929d8e.zip |
repl: handle uncaughtException properly
When running the REPL as standalone program it's now possible to use
`process.on('uncaughtException', listener)`. It is going to use those
listeners from now on and the regular error output is suppressed.
It also fixes the issue that REPL instances started inside of an
application would silence all application errors. It is now prohibited
to add the exception listener in such REPL instances. Trying to add
such listeners throws an `ERR_INVALID_REPL_INPUT` error.
Fixes: https://github.com/nodejs/node/issues/19998
PR-URL: https://github.com/nodejs/node/pull/27151
Fixes: https://github.com/nodejs/node/issues/19998
Reviewed-By: Lance Ball <lball@redhat.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test/parallel/test-repl-uncaught-exception-standalone.js')
-rw-r--r-- | test/parallel/test-repl-uncaught-exception-standalone.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/parallel/test-repl-uncaught-exception-standalone.js b/test/parallel/test-repl-uncaught-exception-standalone.js new file mode 100644 index 0000000000..ae7b214fef --- /dev/null +++ b/test/parallel/test-repl-uncaught-exception-standalone.js @@ -0,0 +1,38 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const cp = require('child_process'); +const child = cp.spawn(process.execPath, ['-i']); +let output = ''; + +child.stdout.setEncoding('utf8'); +child.stdout.on('data', (data) => { + output += data; +}); + +child.on('exit', common.mustCall(() => { + const results = output.split('\n'); + results.shift(); + assert.deepStrictEqual( + results, + [ + 'Type ".help" for more information.', + // x\n + '> Thrown:', + 'ReferenceError: x is not defined', + // Added `uncaughtException` listener. + '> short', + 'undefined', + // x\n + '> Foobar', + '> ' + ] + ); +})); + +child.stdin.write('x\n'); +child.stdin.write( + 'process.on("uncaughtException", () => console.log("Foobar"));' + + 'console.log("short")\n'); +child.stdin.write('x\n'); +child.stdin.end(); |