mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
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: https://github.com/nodejs/node/pull/38314 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
1 parent
c9ce98c377
commit
a4eb5571eb
2 files changed
+28
-2
No files matched your search
+5
-2
@@ -861,8 +861,11 @@ function REPLServer(prompt,
|
||||
self.output.write(self.writer(ret) + '\n');
|
||||
}
|
||||
|
||||
// Display prompt again
|
||||
self.displayPrompt();
|
||||
// Display prompt again (unless we already did by emitting the 'error'
|
||||
// event on the domain instance).
|
||||
if (!e) {
|
||||
self.displayPrompt();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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());
|
||||
Reference in new issue
Block a user