From f405daa92260b0bb9fc5cf8c5c2991679e00bdf2 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Wed, 25 Apr 2012 20:08:30 -0700 Subject: [PATCH] repl: make tab completion read up the prototype of "global" For example, there's a global "toString()" function, so the REPL's tab completion should pick that up. --- lib/repl.js | 4 ++++ test/simple/test-repl-tab-complete.js | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lib/repl.js b/lib/repl.js index 9cd88afb842..889a9f0d26a 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -535,6 +535,10 @@ REPLServer.prototype.complete = function(line, callback) { if (this.useGlobal || this.context.constructor && this.context.constructor.name === 'Context') { + var contextProto = this.context; + while (contextProto = Object.getPrototypeOf(contextProto)) { + completionGroups.push(Object.getOwnPropertyNames(contextProto)); + } completionGroups.push(Object.getOwnPropertyNames(this.context)); addStandardGlobals(); completionGroupsLoaded(); diff --git a/test/simple/test-repl-tab-complete.js b/test/simple/test-repl-tab-complete.js index b38eaa13b7c..4e9df6b6326 100644 --- a/test/simple/test-repl-tab-complete.js +++ b/test/simple/test-repl-tab-complete.js @@ -202,3 +202,9 @@ testMe.complete(' ', function(error, data) { assert.deepEqual(data, [[],undefined]); clearTimeout(spaceTimeout); }); + +// tab completion should pick up the global "toString" object, and +// any other properties up the "global" object's prototype chain +testMe.complete('toSt', function(error, data) { + assert.deepEqual(data, [['toString'], 'toSt']); +});