Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,13 @@ function formatValue(ctx, value, recurseTimes, typedArray) {
return ctx.stylize(`[Circular *${index}]`, 'special');
}

return formatRaw(ctx, value, recurseTimes, typedArray);
const formatted = formatRaw(ctx, value, recurseTimes, typedArray);

if (proxy !== undefined) {
return `${ctx.stylize('Proxy(', 'special')}${formatted}${ctx.stylize(')', 'special')}`;
}

return formatted;
}

function formatRaw(ctx, value, recurseTimes, typedArray) {
Expand Down
21 changes: 15 additions & 6 deletions test/parallel/test-util-inspect-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const proxy3 = new Proxy(proxy2, proxy1);
const proxy4 = new Proxy(proxy1, proxy2);
const proxy5 = new Proxy(proxy3, proxy4);
const proxy6 = new Proxy(proxy5, proxy5);
const expected0 = '{}';
const expected0 = 'Proxy({})';
const expected1 = 'Proxy [ {}, {} ]';
const expected2 = 'Proxy [ Proxy [ {}, {} ], {} ]';
const expected3 = 'Proxy [ Proxy [ Proxy [ {}, {} ], {} ], Proxy [ {}, {} ] ]';
Expand Down Expand Up @@ -154,7 +154,7 @@ assert.strictEqual(util.inspect(proxy6), expected0);
const proxy7 = new Proxy([], []);
const expected7 = 'Proxy [ [], [] ]';
assert.strictEqual(util.inspect(proxy7, opts), expected7);
assert.strictEqual(util.inspect(proxy7), '[]');
assert.strictEqual(util.inspect(proxy7), 'Proxy([])');

// Now we're just getting silly, right?
const proxy8 = new Proxy(Date, []);
Expand All @@ -163,8 +163,8 @@ const expected8 = 'Proxy [ [Function: Date], [] ]';
const expected9 = 'Proxy [ [Function: Date], [Function: String] ]';
assert.strictEqual(util.inspect(proxy8, opts), expected8);
assert.strictEqual(util.inspect(proxy9, opts), expected9);
assert.strictEqual(util.inspect(proxy8), '[Function: Date]');
assert.strictEqual(util.inspect(proxy9), '[Function: Date]');
assert.strictEqual(util.inspect(proxy8), 'Proxy([Function: Date])');
assert.strictEqual(util.inspect(proxy9), 'Proxy([Function: Date])');

const proxy10 = new Proxy(() => {}, {});
const proxy11 = new Proxy(() => {}, {
Expand All @@ -175,7 +175,16 @@ const proxy11 = new Proxy(() => {}, {
return proxy11;
}
});
const expected10 = '[Function (anonymous)]';
const expected11 = '[Function (anonymous)]';
const expected10 = 'Proxy([Function (anonymous)])';
const expected11 = 'Proxy([Function (anonymous)])';
assert.strictEqual(util.inspect(proxy10), expected10);
assert.strictEqual(util.inspect(proxy11), expected11);

const proxy12 = new Proxy([1, 2, 3], proxy5);
assert.strictEqual(
util.inspect(proxy12, { colors: true, breakLength: 1 }),
'\x1B[36mProxy(\x1B[39m' +
'[\n \x1B[33m1\x1B[39m,\n \x1B[33m2\x1B[39m,\n \x1B[33m3\x1B[39m\n]\x1B[36m' +
')\x1B[39m'
);
assert.strictEqual(util.format('%s', proxy12), 'Proxy([ 1, 2, 3 ])');
Loading