Skip to content

Commit

Permalink
repl: fix tab completion for a non-global context
Browse files Browse the repository at this point in the history
Use vm.isContext() to properly identify contexts.

PR-URL: nodejs/node-v0.x-archive#25382
PR-URL: #2052
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
sixmen authored and cjihrig committed Jun 25, 2015
1 parent c370bd3 commit d735b2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,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/parallel/test-repl-tab-complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,13 @@ testMe.complete('require(\'n', function(error, data) {
assert.strictEqual(error, null);
assert.deepEqual(data, [['net'], 'n']);
});

// Make sure tab completion works on context properties
putIn.run(['.clear']);

putIn.run([
'var custom = "test";'
]);
testMe.complete('cus', function(error, data) {
assert.deepEqual(data, [['custom'], 'cus']);
});

0 comments on commit d735b2c

Please sign in to comment.