Skip to content

Commit 4129bc7

Browse files
avivkellercjihrig
authored andcommitted
util: do not catch on circular @@toStringTag errors
PR-URL: #55544Fixes: #55539 Reviewed-By: James M Snell <jasnell@gmail.com> Co-Authored-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 20cb52d commit 4129bc7

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

‎lib/internal/util/inspect.js‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
10721072
ArrayPrototypePushApply(output,protoProps);
10731073
}
10741074
}catch(err){
1075+
if(!isStackOverflowError(err))throwerr;
10751076
constconstructorName=StringPrototypeSlice(getCtxStyle(value,constructor,tag),0,-1);
10761077
returnhandleMaxCallStackSize(ctx,err,constructorName,indentationLvl);
10771078
}
@@ -1557,17 +1558,13 @@ function groupArrayElements(ctx, output, value) {
15571558
}
15581559

15591560
functionhandleMaxCallStackSize(ctx,err,constructorName,indentationLvl){
1560-
if(isStackOverflowError(err)){
1561-
ctx.seen.pop();
1562-
ctx.indentationLvl=indentationLvl;
1563-
returnctx.stylize(
1564-
`[${constructorName}: Inspection interrupted `+
1565-
'prematurely. Maximum call stack size exceeded.]',
1566-
'special',
1567-
);
1568-
}
1569-
/* c8 ignore next */
1570-
assert.fail(err.stack);
1561+
ctx.seen.pop();
1562+
ctx.indentationLvl=indentationLvl;
1563+
returnctx.stylize(
1564+
`[${constructorName}: Inspection interrupted `+
1565+
'prematurely. Maximum call stack size exceeded.]',
1566+
'special',
1567+
);
15711568
}
15721569

15731570
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)