summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Rajlich <nathan@tootallnate.net>2012-02-16 16:33:40 -0800
committerBen Noordhuis <info@bnoordhuis.nl>2012-02-17 15:51:33 +0100
commita118f2172880d338101f80647437b8832ac1f768 (patch)
tree7cb12ff4f8d8714db9de3f9650d5d144110e1c4f
parent30e462e91937ced3847af3fe9c393ebd32294b68 (diff)
downloadnode-a118f2172880d338101f80647437b8832ac1f768.tar.gz
repl: make tab completion work on non-objects
-rw-r--r--lib/repl.js7
-rw-r--r--test/simple/test-repl-tab-complete.js9
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/repl.js b/lib/repl.js
index 08697ab72..20fa7aefc 100644
--- a/lib/repl.js
+++ b/lib/repl.js
@@ -523,8 +523,13 @@ REPLServer.prototype.complete = function(line, callback) {
}
// works for non-objects
try {
- var p = Object.getPrototypeOf(obj);
var sentinel = 5;
+ var p;
+ if (typeof obj == 'object') {
+ p = Object.getPrototypeOf(obj);
+ } else {
+ p = obj.constructor ? obj.constructor.prototype : null;
+ }
while (p !== null) {
memberGroups.push(Object.getOwnPropertyNames(p));
p = Object.getPrototypeOf(p);
diff --git a/test/simple/test-repl-tab-complete.js b/test/simple/test-repl-tab-complete.js
index ba511046b..0bc43ab19 100644
--- a/test/simple/test-repl-tab-complete.js
+++ b/test/simple/test-repl-tab-complete.js
@@ -180,3 +180,12 @@ testMe.complete('inner.o', function(error, data) {
assert.deepEqual(data, doesNotBreak);
});
+putIn.run(['.clear']);
+
+// make sure tab completion works on non-Objects
+putIn.run([
+ 'var str = "test";'
+]);
+testMe.complete('str.len', function(error, data) {
+ assert.deepEqual(data, [ [ 'str.length' ], 'str.len' ]);
+});