Skip to content

Commit 285ef30

Browse files
daeyeonbengl
authored andcommitted
console: fix console.dir crash on a revoked proxy
Fixes: #43095 Signed-off-by: Daeyeon Jeong [email protected] PR-URL: #43100 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 2b8b224 commit 285ef30

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

‎lib/internal/util/inspect.js‎

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

Lines changed: 12 additions & 0 deletions
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+
constr=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‎

Lines changed: 21 additions & 0 deletions
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+
constr=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)