Skip to content

Commit e1884d5

Browse files
committed
repl: Tab complete when useGlobal is false
Fixes nodejs#7353
1 parent 6be73fe commit e1884d5

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/repl.js

+16
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,22 @@ REPLServer.prototype.createContext = function() {
586586
} else {
587587
context = vm.createContext();
588588
for (var i in global) context[i] = global[i];
589+
590+
// #7353 - tab complete returns fewer results
591+
vm.runInContext(`
592+
(function() {
593+
for (const name of Object.getOwnPropertyNames(global)) {
594+
this[name] = this[name];
595+
}
596+
})()
597+
`, context);
598+
599+
for (const name of Object.keys(context)) {
600+
Object.defineProperty(context, name, {
601+
enumerable: global.propertyIsEnumerable(name)
602+
});
603+
}
604+
589605
context.console = new Console(this.outputStream);
590606
context.global = context;
591607
context.global.global = context;

test/parallel/test-repl-tab-complete.js

+11
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,14 @@ putIn.run(['.clear']);
260260
testMe.complete('var log = console.lo', common.mustCall((error, data) => {
261261
assert.deepStrictEqual(data, [['console.log'], 'console.lo']);
262262
}));
263+
264+
var testNonGlobal = repl.start({
265+
input: putIn,
266+
output: putIn,
267+
useGlobal: false
268+
});
269+
270+
testNonGlobal.complete('I', common.mustCall((error, data) => {
271+
assert.deepStrictEqual(data, [['Infinity', '', 'Int16Array', 'Int32Array',
272+
'Int8Array', 'Intl'], 'I']);
273+
}));

0 commit comments

Comments
 (0)