Browse Source

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>
v4.0.0-rc
Sangmin Yoon 10 years ago
committed by cjihrig
parent
commit
d735b2c6ef
  1. 4
      lib/repl.js
  2. 10
      test/parallel/test-repl-tab-complete.js

4
lib/repl.js

@ -611,9 +611,7 @@ REPLServer.prototype.complete = function(line, callback) {
if (!expr) { if (!expr) {
// If context is instance of vm.ScriptContext // If context is instance of vm.ScriptContext
// Get global vars synchronously // Get global vars synchronously
if (this.useGlobal || if (this.useGlobal || vm.isContext(this.context)) {
this.context.constructor &&
this.context.constructor.name === 'Context') {
var contextProto = this.context; var contextProto = this.context;
while (contextProto = Object.getPrototypeOf(contextProto)) { while (contextProto = Object.getPrototypeOf(contextProto)) {
completionGroups.push(Object.getOwnPropertyNames(contextProto)); completionGroups.push(Object.getOwnPropertyNames(contextProto));

10
test/parallel/test-repl-tab-complete.js

@ -206,3 +206,13 @@ testMe.complete('require(\'n', function(error, data) {
assert.strictEqual(error, null); assert.strictEqual(error, null);
assert.deepEqual(data, [['net'], 'n']); 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']);
});

Loading…
Cancel
Save