Skip to content

Commit ed7efbc

Browse files
committed
util: fix nested proxy inspection
Fixes: #61061
1 parent 14f02fc commit ed7efbc

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/internal/util/inspect.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ const {
173173
isModuleNamespaceObject,
174174
isNativeError,
175175
isPromise,
176+
isProxy,
176177
isSet,
177178
isSetIterator,
178179
isWeakMap,
@@ -1122,13 +1123,19 @@ function formatValue(ctx, value, recurseTimes, typedArray) {
11221123
// any proxy handlers.
11231124
const proxy = getProxyDetails(value, !!ctx.showProxy);
11241125
if (proxy !== undefined) {
1125-
if (proxy === null || proxy[0] === null) {
1126-
return ctx.stylize('<Revoked Proxy>', 'special');
1127-
}
11281126
if (ctx.showProxy) {
1127+
if (proxy[0] === null) {
1128+
return ctx.stylize('<Revoked Proxy>', 'special');
1129+
}
11291130
return formatProxy(ctx, proxy, recurseTimes);
11301131
}
1132+
if (proxy === null) {
1133+
return ctx.stylize('<Revoked Proxy>', 'special');
1134+
}
11311135
value = proxy;
1136+
if (isProxy(value)) {
1137+
return formatValue(ctx, value, recurseTimes);
1138+
}
11321139
}
11331140

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

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,12 @@ 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+
{
184+
// Nested proxies should not trigger any proxy handlers.
185+
const errorProxy = new Proxy({}, { get(...cause) { throw new EvalError('boom', { cause }); } });
186+
const nestedProxy = new Proxy(errorProxy, {});
187+
188+
util.inspect(nestedProxy, { showProxy: true });
189+
util.inspect(nestedProxy, { showProxy: false });
190+
}

0 commit comments

Comments
 (0)