Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4129bc7

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

File tree

Expand file treeCollapse file tree

2 files changed

+17
-11
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-11
lines changed
Open diff view settings
Collapse file

‎lib/internal/util/inspect.js‎

Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js
+8-11Lines 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)) throw err;
10751076
const constructorName = StringPrototypeSlice(getCtxStyle(value, constructor, tag), 0, -1);
10761077
return handleMaxCallStackSize(ctx, err, constructorName, indentationLvl);
10771078
}
@@ -1557,17 +1558,13 @@ function groupArrayElements(ctx, output, value) {
15571558
}
15581559

15591560
function handleMaxCallStackSize(ctx, err, constructorName, indentationLvl) {
1560-
if (isStackOverflowError(err)) {
1561-
ctx.seen.pop();
1562-
ctx.indentationLvl = indentationLvl;
1563-
return ctx.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+
return ctx.stylize(
1564+
`[${constructorName}: Inspection interrupted ` +
1565+
'prematurely. Maximum call stack size exceeded.]',
1566+
'special',
1567+
);
15711568
}
15721569

15731570
function addNumericSeparator(integerString) {
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect.js
+9Lines 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(new ThrowingClass()), /toStringTag error/);
16461646

1647+
const y = {
1648+
get [Symbol.toStringTag]() {
1649+
return JSON.stringify(this);
1650+
}
1651+
};
1652+
const x = { y };
1653+
y.x = x;
1654+
assert.throws(() => util.inspect(x), /TypeError: Converting circular structure to JSON/);
1655+
16471656
class NotStringClass {
16481657
get [Symbol.toStringTag]() {
16491658
return null;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.