Skip to content

Commit 35e258c

Browse files
committed
util: keep proxies opaque in util.inspect when showProxy is false
1 parent 6c306b6 commit 35e258c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/internal/util/inspect.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,10 +1125,14 @@ function formatValue(ctx, value, recurseTimes, typedArray) {
11251125
if (proxy === null || proxy[0] === null) {
11261126
return ctx.stylize('<Revoked Proxy>', 'special');
11271127
}
1128+
11281129
if (ctx.showProxy) {
11291130
return formatProxy(ctx, proxy, recurseTimes);
11301131
}
1131-
value = proxy;
1132+
1133+
// Treat proxies as opaque when showProxy is false,
1134+
// but preserve the original target for inspection.
1135+
value = proxy[0];
11321136
}
11331137

11341138
// Provide a hook for user-specified inspect functions.

test/parallel/test-util-inspect-proxy.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,22 @@ const expected10 = '[Function (anonymous)]';
179179
const expected11 = '[Function (anonymous)]';
180180
assert.strictEqual(util.inspect(proxy10), expected10);
181181
assert.strictEqual(util.inspect(proxy11), expected11);
182+
183+
// Regression test for https://github.com/nodejs/node/issues/61061
184+
{
185+
const throwingProxy = new Proxy({}, {
186+
get() {
187+
throw new EvalError('boom');
188+
}
189+
});
190+
191+
const nestedThrowingProxy = new Proxy(throwingProxy, {});
192+
193+
// showProxy: false must NOT trigger proxy traps
194+
// Directly inspect proxies; it should not throw
195+
const result1 = util.inspect(throwingProxy, { showProxy: false });
196+
assert.strictEqual(result1, '{}');
197+
198+
const result2 = util.inspect(nestedThrowingProxy, { showProxy: false });
199+
assert.strictEqual(result2, '{}');
200+
}

0 commit comments

Comments
 (0)