-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repl: display prompt once after error callback
Do not call `.displayPrompt()` twice after the `eval` callback resulted in an error. (This does not affect the default eval because it doesn’t use the callback if an error occurs.) PR-URL: #38314 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
- Loading branch information
Showing
2 changed files
with
28 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
test/parallel/test-repl-uncaught-exception-evalcallback.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const repl = require('repl'); | ||
const { PassThrough } = require('stream'); | ||
const input = new PassThrough(); | ||
const output = new PassThrough(); | ||
|
||
const r = repl.start({ | ||
input, output, | ||
eval: common.mustCall((code, context, filename, cb) => { | ||
r.setPrompt('prompt! '); | ||
cb(new Error('err')); | ||
}) | ||
}); | ||
|
||
input.end('foo\n'); | ||
|
||
// The output includes exactly one post-error prompt. | ||
const out = output.read().toString(); | ||
assert.match(out, /prompt!/); | ||
assert.doesNotMatch(out, /prompt![\S\s]*prompt!/); | ||
output.on('data', common.mustNotCall()); |