diff --git a/lib/repl.js b/lib/repl.js index 96532910b4d7e4..763e283816bb64 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -641,7 +641,14 @@ REPLServer.prototype.complete = function(line, callback) { if (obj != null) { if (typeof obj === 'object' || typeof obj === 'function') { - memberGroups.push(Object.getOwnPropertyNames(obj)); + try { + memberGroups.push(Object.getOwnPropertyNames(obj)); + } catch (ex) { + // Probably a Proxy object without `getOwnPropertyNames` trap. + // We simply ignore it here, as we don't want to break the + // autocompletion. Fixes the bug + // https://github.com/nodejs/io.js/issues/2119 + } } // works for non-objects try { diff --git a/test/parallel/test-repl-tab-complete.js b/test/parallel/test-repl-tab-complete.js index a1b901f065eace..856fd9b041f973 100644 --- a/test/parallel/test-repl-tab-complete.js +++ b/test/parallel/test-repl-tab-complete.js @@ -1,4 +1,7 @@ 'use strict'; + +// Flags: --harmony-proxies + var common = require('../common'); var assert = require('assert'); var util = require('util'); @@ -232,3 +235,16 @@ putIn.run([ testMe.complete('cus', common.mustCall(function(error, data) { assert.deepEqual(data, [['custom'], 'cus']); })); + +// Make sure tab completion doesn't crash REPL with half-baked proxy objects. +// See: https://github.com/nodejs/io.js/issues/2119 +putIn.run(['.clear']); + +putIn.run([ + 'var proxy = Proxy.create({});' +]); + +testMe.complete('proxy.', common.mustCall(function(error, data) { + assert.strictEqual(error, null); + assert.deepEqual(data, [[], 'proxy.']); +}));