Skip to content

Commit afa44fb

Browse files
avivkellercjihrig
authored andcommitted
util: do not catch on circular @@toStringTag errors
PR-URL: #55544Fixes: #55539 Reviewed-By: James M Snell <[email protected]> Co-Authored-By: Colin Ihrig <[email protected]>
1 parent ffb0d3c commit afa44fb

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

‎lib/internal/util/inspect.js‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray){
10621062
ArrayPrototypePushApply(output,protoProps);
10631063
}
10641064
}catch(err){
1065+
if(!isStackOverflowError(err))throwerr;
10651066
constconstructorName=StringPrototypeSlice(getCtxStyle(value,constructor,tag),0,-1);
10661067
returnhandleMaxCallStackSize(ctx,err,constructorName,indentationLvl);
10671068
}
@@ -1547,17 +1548,13 @@ function groupArrayElements(ctx, output, value){
15471548
}
15481549

15491550
functionhandleMaxCallStackSize(ctx,err,constructorName,indentationLvl){
1550-
if(isStackOverflowError(err)){
1551-
ctx.seen.pop();
1552-
ctx.indentationLvl=indentationLvl;
1553-
returnctx.stylize(
1554-
`[${constructorName}: Inspection interrupted `+
1555-
'prematurely. Maximum call stack size exceeded.]',
1556-
'special',
1557-
);
1558-
}
1559-
/* c8 ignore next */
1560-
assert.fail(err.stack);
1551+
ctx.seen.pop();
1552+
ctx.indentationLvl=indentationLvl;
1553+
returnctx.stylize(
1554+
`[${constructorName}: Inspection interrupted `+
1555+
'prematurely. Maximum call stack size exceeded.]',
1556+
'special',
1557+
);
15611558
}
15621559

15631560
functionaddNumericSeparator(integerString){

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,15 @@ util.inspect(process);
16441644

16451645
assert.throws(()=>util.inspect(newThrowingClass()),/toStringTagerror/);
16461646

1647+
consty={
1648+
get[Symbol.toStringTag](){
1649+
returnJSON.stringify(this);
1650+
}
1651+
};
1652+
constx={ y };
1653+
y.x=x;
1654+
assert.throws(()=>util.inspect(x),/TypeError:ConvertingcircularstructuretoJSON/);
1655+
16471656
classNotStringClass{
16481657
get[Symbol.toStringTag](){
16491658
returnnull;

0 commit comments

Comments
(0)