Skip to content

Commit c4ff510

Browse files
daeyeonjuanarbol
authored andcommitted
console: fix console.dir crash on a revoked proxy
Fixes: #43095 Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com PR-URL: #43100 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 63045bf commit c4ff510

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

lib/internal/util/inspect.js

+6
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,9 @@ function formatValue(ctx, value, recurseTimes, typedArray) {
759759
// any proxy handlers.
760760
const proxy = getProxyDetails(value, !!ctx.showProxy);
761761
if (proxy !== undefined) {
762+
if (proxy === null || proxy[0] === null) {
763+
return ctx.stylize('<Revoked Proxy>', 'special');
764+
}
762765
if (ctx.showProxy) {
763766
return formatProxy(ctx, proxy, recurseTimes);
764767
}
@@ -1967,6 +1970,9 @@ function hasBuiltInToString(value) {
19671970
const getFullProxy = false;
19681971
const proxyTarget = getProxyDetails(value, getFullProxy);
19691972
if (proxyTarget !== undefined) {
1973+
if (proxyTarget === null) {
1974+
return true;
1975+
}
19701976
value = proxyTarget;
19711977
}
19721978

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
require('../common');
4+
const { inspect } = require('node:util');
5+
6+
const r = Proxy.revocable({}, {});
7+
r.revoke();
8+
9+
console.dir(r);
10+
console.dir(r.proxy);
11+
console.log(r.proxy);
12+
console.log(inspect(r.proxy, { showProxy: true }));

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

+21
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,27 @@ assert.strictEqual(handler, details[1]);
5757
details = processUtil.getProxyDetails(proxyObj, false);
5858
assert.strictEqual(target, details);
5959

60+
details = processUtil.getProxyDetails({}, true);
61+
assert.strictEqual(details, undefined);
62+
63+
const r = Proxy.revocable({}, {});
64+
r.revoke();
65+
66+
details = processUtil.getProxyDetails(r.proxy, true);
67+
assert.strictEqual(details[0], null);
68+
assert.strictEqual(details[1], null);
69+
70+
details = processUtil.getProxyDetails(r.proxy, false);
71+
assert.strictEqual(details, null);
72+
73+
assert.strictEqual(util.inspect(r.proxy), '<Revoked Proxy>');
74+
assert.strictEqual(
75+
util.inspect(r, { showProxy: true }),
76+
'{ proxy: <Revoked Proxy>, revoke: [Function (anonymous)] }',
77+
);
78+
79+
assert.strictEqual(util.format('%s', r.proxy), '<Revoked Proxy>');
80+
6081
assert.strictEqual(
6182
util.inspect(proxyObj, opts),
6283
'Proxy [\n' +

0 commit comments

Comments
 (0)