Skip to content

Commit 4da7a85

Browse files
committed
repl: show proxies as Proxy objects
Fixes: nodejs#16483
1 parent 6971f02 commit 4da7a85

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

lib/repl.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ function hasOwnProperty(obj, prop) {
100100

101101
// Can overridden with custom print functions, such as `probe` or `eyes.js`.
102102
// This is the default "writer" value if none is passed in the REPL options.
103-
exports.writer = util.inspect;
103+
const writer = exports.writer = (obj) => util.inspect(obj, writer.options);
104+
writer.options =
105+
Object.assign(util.inspect.defaultOptions, { showProxy: true });
104106

105107
exports._builtinLibs = internalModule.builtinLibs;
106108

@@ -370,11 +372,10 @@ function REPLServer(prompt,
370372
}
371373
self.useColors = !!options.useColors;
372374

373-
if (self.useColors && self.writer === util.inspect) {
375+
if (self.useColors && self.writer === writer) {
374376
// Turn on ANSI coloring.
375-
self.writer = function(obj, showHidden, depth) {
376-
return util.inspect(obj, showHidden, depth, true);
377-
};
377+
self.writer = (obj) => util.inspect(obj, self.writer.options);
378+
self.writer.options = Object.assign(writer.options, { colors: true });
378379
}
379380

380381
function filterInternalStackFrames(error, structuredStack) {

test/parallel/test-repl.js

+12
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,18 @@ function error_test() {
412412
expect: `${prompt_multiline}${prompt_multiline}undefined\n${prompt_unix}`
413413
},
414414

415+
// https://github.com/nodejs/node/issues/16483
416+
{
417+
client: client_unix, send: 'new Proxy({x:42}, {get(){throw null}});',
418+
expect: `Proxy [ { x: 42 }, { get: [Function: get] } ]\n${prompt_unix}`
419+
},
420+
{
421+
client: client_unix,
422+
send: 'repl.writer.options.showProxy = false, new Proxy({x:42}, {});',
423+
expect: `{ x: 42 }\n${prompt_unix}`
424+
},
425+
426+
415427
// Newline within template string maintains whitespace.
416428
{ client: client_unix, send: '`foo \n`',
417429
expect: `${prompt_multiline}'foo \\n'\n${prompt_unix}` },

0 commit comments

Comments
 (0)