From d735b2c6ef9dc710a2e8c58bf56dc6d28f5a4bd3 Mon Sep 17 00:00:00 2001 From: Sangmin Yoon Date: Wed, 27 May 2015 18:10:45 +0900 Subject: [PATCH] repl: fix tab completion for a non-global context Use vm.isContext() to properly identify contexts. PR-URL: https://github.com/joyent/node/pull/25382 PR-URL: https://github.com/nodejs/io.js/pull/2052 Reviewed-By: Colin Ihrig Reviewed-By: Ben Noordhuis --- lib/repl.js | 4 +--- test/parallel/test-repl-tab-complete.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) 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']); +});