Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

repl: fix tab completion for a non-global context #25382

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 1 addition & 3 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,7 @@ REPLServer.prototype.complete = function(line, callback) {
if (!expr) {
// If context is instance of vm.ScriptContext
// Get global vars synchronously
if (this.useGlobal ||
this.context.constructor &&
this.context.constructor.name === 'Context') {
if (this.useGlobal || vm.isContext(this.context)) {
var contextProto = this.context;
while (contextProto = Object.getPrototypeOf(contextProto)) {
completionGroups.push(Object.getOwnPropertyNames(contextProto));
Expand Down
10 changes: 10 additions & 0 deletions test/simple/test-repl-tab-complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,13 @@ testMe.complete(' ', function(error, data) {
testMe.complete('toSt', function(error, data) {
assert.deepEqual(data, [['toString'], 'toSt']);
});

putIn.run(['.clear']);

// make sure tab completion works on context properties
putIn.run([
'var custom = "test";'
]);
testMe.complete('cus', function(error, data) {
assert.deepEqual(data, [['custom'], 'cus']);
});