Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl: don't crash if self is not in replMap #7718

Merged
merged 1 commit into from
Jul 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,12 +735,12 @@ function complete(line, callback) {
});
var flat = new ArrayStream(); // make a new "input" stream
var magic = new REPLServer('', flat); // make a nested REPL
replMap.set(magic, replMap.get(this));
magic.context = magic.createContext();
flat.run(tmp); // eval the flattened code
// all this is only profitable if the nested REPL
// does not have a bufferedCommand
if (!magic.bufferedCommand) {
replMap.set(magic, replMap.get(this));
return magic.complete(line, callback);
}
}
Expand Down
26 changes: 13 additions & 13 deletions test/parallel/test-repl-tab-complete-crash.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ const common = require('../common');
const assert = require('assert');
const repl = require('repl');

var referenceErrorCount = 0;

common.ArrayStream.prototype.write = function(msg) {
if (msg.startsWith('ReferenceError: ')) {
referenceErrorCount++;
}
};
common.ArrayStream.prototype.write = function(msg) {};

const putIn = new common.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.
// Tab-completion should be empty
putIn.run(['.clear']);
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() {
assert.strictEqual(referenceErrorCount, 1);
});
putIn.run(['.clear']);
putIn.run(['function () {']);
putIn.run(['undef;']);
testMe.complete('undef.', common.mustCall((err, completions) => {
assert.strictEqual(err, null);
assert.deepStrictEqual(completions, [[], 'undef.']);
}));