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: https://github.com/nodejs/node/issues/3346 PR-URL: https://github.com/nodejs/node/pull/3358 Reviewed-By: James M Snell <jasnell@gmail.com>
41 lines
1 KiB
JavaScript
41 lines
1 KiB
JavaScript
'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);
|
|
});
|