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 <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
Sangmin Yoon 2015-05-27 18:10:45 +09:00 committed by cjihrig
parent c370bd3aea
commit d735b2c6ef
2 changed files with 11 additions and 3 deletions

View File

@ -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));

View File

@ -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']);
});