Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl: Prevent REPL crash when tab-completed with Proxy objects #2120

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-repl-tab-complete.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
'use strict';

// Flags: --harmony-proxies

var common = require('../common');
var assert = require('assert');
var util = require('util');
Expand Down Expand Up @@ -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.']);
}));