-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow REPL consumers to callback with a `Recoverable` error instance and trigger multi-line REPL prompts. Fixes: #2939 PR-URL: #3488 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
- Loading branch information
1 parent
25f8d04
commit 9552e3b
Showing
3 changed files
with
65 additions
and
5 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
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
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,40 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const repl = require('repl'); | ||
|
||
let evalCount = 0; | ||
let recovered = false; | ||
let rendered = false; | ||
|
||
function customEval(code, context, file, cb) { | ||
evalCount++; | ||
|
||
return cb(evalCount === 1 ? new repl.Recoverable() : null, true); | ||
} | ||
|
||
const putIn = new common.ArrayStream(); | ||
|
||
putIn.write = function(msg) { | ||
if (msg === '... ') { | ||
recovered = true; | ||
} | ||
|
||
if (msg === 'true\n') { | ||
rendered = true; | ||
} | ||
}; | ||
|
||
repl.start('', putIn, customEval); | ||
|
||
// https://github.com/nodejs/node/issues/2939 | ||
// Expose recoverable errors to the consumer. | ||
putIn.emit('data', '1\n'); | ||
putIn.emit('data', '2\n'); | ||
|
||
process.on('exit', function() { | ||
assert(recovered, 'REPL never recovered'); | ||
assert(rendered, 'REPL never rendered the result'); | ||
assert.strictEqual(evalCount, 2); | ||
}); |