mirror of https://github.com/lukechilds/node.git
Browse Source
Allow REPL consumers to callback with a `Recoverable` error instance and trigger multi-line REPL prompts. Fixes: https://github.com/nodejs/node/issues/2939 PR-URL: https://github.com/nodejs/node/pull/3488 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>v6.x
committed by
Evan Lucas
3 changed files with 65 additions and 5 deletions
@ -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); |
||||
|
}); |
Loading…
Reference in new issue