repl: do not insert duplicates into completions
authorMaciej Małecki <me@mmalecki.com>
Mon, 11 Nov 2013 23:03:29 +0000 (00:03 +0100)
committerNathan Rajlich <nathan@tootallnate.net>
Mon, 11 Nov 2013 23:45:09 +0000 (15:45 -0800)
Fix invalid `hasOwnProperty` function usage.

For example, before in the REPL:

```
> Ar<Tab>
Array

Array        ArrayBuffer
```

Now:

```
> Ar<Tab>
Array

ArrayBuffer
```

Fixes #6255.
Closes #6498.

lib/repl.js
test/simple/test-repl-tab-complete.js

index c726065..61855f9 100644 (file)
@@ -641,7 +641,7 @@ REPLServer.prototype.complete = function(line, callback) {
         group.sort();
         for (var j = 0; j < group.length; j++) {
           c = group[j];
-          if (!hasOwnProperty(c)) {
+          if (!hasOwnProperty(uniq, c)) {
             completions.push(c);
             uniq[c] = true;
           }
index 591cd32..6840638 100644 (file)
@@ -55,6 +55,9 @@ putIn.run([
 testMe.complete('inner.o', function(error, data) {
   assert.deepEqual(data, doesNotBreak);
 });
+testMe.complete('console.lo', function(error, data) {
+  assert.deepEqual(data, [['console.log'], 'console.lo']);
+});
 
 // Tab Complete will return globaly scoped variables
 putIn.run(['};']);