repl: prevent undefined ref in completion
Fixes: https://github.com/nodejs/node/issues/7716 PR-URL: https://github.com/nodejs/node/pull/7718 Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
d525e6c92a
commit
392c70a827
@ -735,12 +735,12 @@ function complete(line, callback) {
|
|||||||
});
|
});
|
||||||
var flat = new ArrayStream(); // make a new "input" stream
|
var flat = new ArrayStream(); // make a new "input" stream
|
||||||
var magic = new REPLServer('', flat); // make a nested REPL
|
var magic = new REPLServer('', flat); // make a nested REPL
|
||||||
|
replMap.set(magic, replMap.get(this));
|
||||||
magic.context = magic.createContext();
|
magic.context = magic.createContext();
|
||||||
flat.run(tmp); // eval the flattened code
|
flat.run(tmp); // eval the flattened code
|
||||||
// all this is only profitable if the nested REPL
|
// all this is only profitable if the nested REPL
|
||||||
// does not have a bufferedCommand
|
// does not have a bufferedCommand
|
||||||
if (!magic.bufferedCommand) {
|
if (!magic.bufferedCommand) {
|
||||||
replMap.set(magic, replMap.get(this));
|
|
||||||
return magic.complete(line, callback);
|
return magic.complete(line, callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,24 +4,24 @@ const common = require('../common');
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const repl = require('repl');
|
const repl = require('repl');
|
||||||
|
|
||||||
var referenceErrorCount = 0;
|
common.ArrayStream.prototype.write = function(msg) {};
|
||||||
|
|
||||||
common.ArrayStream.prototype.write = function(msg) {
|
|
||||||
if (msg.startsWith('ReferenceError: ')) {
|
|
||||||
referenceErrorCount++;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const putIn = new common.ArrayStream();
|
const putIn = new common.ArrayStream();
|
||||||
const testMe = repl.start('', putIn);
|
const testMe = repl.start('', putIn);
|
||||||
|
|
||||||
// https://github.com/nodejs/node/issues/3346
|
// https://github.com/nodejs/node/issues/3346
|
||||||
// Tab-completion for an undefined variable inside a function should report a
|
// Tab-completion should be empty
|
||||||
// ReferenceError.
|
|
||||||
putIn.run(['.clear']);
|
putIn.run(['.clear']);
|
||||||
putIn.run(['function () {']);
|
putIn.run(['function () {']);
|
||||||
testMe.complete('arguments.');
|
testMe.complete('arguments.', common.mustCall((err, completions) => {
|
||||||
|
assert.strictEqual(err, null);
|
||||||
|
assert.deepStrictEqual(completions, [[], 'arguments.']);
|
||||||
|
}));
|
||||||
|
|
||||||
process.on('exit', function() {
|
putIn.run(['.clear']);
|
||||||
assert.strictEqual(referenceErrorCount, 1);
|
putIn.run(['function () {']);
|
||||||
});
|
putIn.run(['undef;']);
|
||||||
|
testMe.complete('undef.', common.mustCall((err, completions) => {
|
||||||
|
assert.strictEqual(err, null);
|
||||||
|
assert.deepStrictEqual(completions, [[], 'undef.']);
|
||||||
|
}));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user