Skip to content

Commit

Permalink
repl: Tab complete when useGlobal is false
Browse files Browse the repository at this point in the history
  • Loading branch information
princejwesley committed Jun 21, 2016
1 parent 6be73fe commit 9c69364
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,15 @@ REPLServer.prototype.createContext = function() {
context = global;
} else {
context = vm.createContext();
for (var i in global) context[i] = global[i];
// #7353 - tab complete returns fewer results
context.global = global;
vm.runInContext(`
(function() {
for (let name of Object.getOwnPropertyNames(global)) {
this[name] = this[name];
}
})()
`, context);
context.console = new Console(this.outputStream);
context.global = context;
context.global.global = context;
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-repl-tab-complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,14 @@ putIn.run(['.clear']);
testMe.complete('var log = console.lo', common.mustCall((error, data) => {
assert.deepStrictEqual(data, [['console.log'], 'console.lo']);
}));

var testNonGlobal = repl.start({
input: putIn,
output: putIn,
useGlobal: false
});

testNonGlobal.complete('I', common.mustCall((error, data) => {
assert.deepStrictEqual(data, [['Infinity', '', 'Int16Array', 'Int32Array',
'Int8Array', 'Intl'], 'I']);
}));

0 comments on commit 9c69364

Please sign in to comment.