-
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.
lib: avoid REPL exit on completion error
If a tab completion is attempted on an undefined reference inside of a function, the REPL was exiting without reporting an error or anything else. This change results in the REPL reporting the ReferenceError and continuing. Fixes: #3346 PR-URL: #3358 Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
2 changed files
with
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const util = require('util'); | ||
const repl = require('repl'); | ||
|
||
var referenceErrorCount = 0; | ||
|
||
// A stream to push an array into a REPL | ||
function ArrayStream() { | ||
this.run = function(data) { | ||
const self = this; | ||
data.forEach(function(line) { | ||
self.emit('data', line + '\n'); | ||
}); | ||
}; | ||
} | ||
util.inherits(ArrayStream, require('stream').Stream); | ||
ArrayStream.prototype.readable = true; | ||
ArrayStream.prototype.writable = true; | ||
ArrayStream.prototype.resume = function() {}; | ||
ArrayStream.prototype.write = function(msg) { | ||
if (msg.startsWith('ReferenceError: ')) { | ||
referenceErrorCount++; | ||
} | ||
}; | ||
|
||
const putIn = new ArrayStream(); | ||
const testMe = repl.start('', putIn); | ||
|
||
// https://github.com/nodejs/node/issues/3346 | ||
// Tab-completion for an undefined variable inside a function should report a | ||
// ReferenceError. | ||
putIn.run(['.clear']); | ||
putIn.run(['function () {']); | ||
testMe.complete('arguments.'); | ||
|
||
process.on('exit', function() { | ||
assert.strictEqual(referenceErrorCount, 1); | ||
}); |