diff --git a/lib/repl.js b/lib/repl.js index 420fde45eb6a6b..4e2356135708ea 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -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)); diff --git a/test/parallel/test-repl-tab-complete.js b/test/parallel/test-repl-tab-complete.js index 659c8046a98173..6fe62f39fc91b6 100644 --- a/test/parallel/test-repl-tab-complete.js +++ b/test/parallel/test-repl-tab-complete.js @@ -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']); +});