Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: don't catch on circular toStringTag error #55544

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
ArrayPrototypePushApply(output, protoProps);
}
} catch (err) {
if (!isStackOverflowError(err)) throw err;
const constructorName = StringPrototypeSlice(getCtxStyle(value, constructor, tag), 0, -1);
return handleMaxCallStackSize(ctx, err, constructorName, indentationLvl);
}
Expand Down Expand Up @@ -1557,17 +1558,13 @@ function groupArrayElements(ctx, output, value) {
}

function handleMaxCallStackSize(ctx, err, constructorName, indentationLvl) {
if (isStackOverflowError(err)) {
ctx.seen.pop();
ctx.indentationLvl = indentationLvl;
return ctx.stylize(
`[${constructorName}: Inspection interrupted ` +
'prematurely. Maximum call stack size exceeded.]',
'special',
);
}
/* c8 ignore next */
assert.fail(err.stack);
ctx.seen.pop();
ctx.indentationLvl = indentationLvl;
return ctx.stylize(
`[${constructorName}: Inspection interrupted ` +
'prematurely. Maximum call stack size exceeded.]',
'special',
);
}

function addNumericSeparator(integerString) {
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,15 @@ util.inspect(process);

assert.throws(() => util.inspect(new ThrowingClass()), /toStringTag error/);

const y = {
get [Symbol.toStringTag]() {
return JSON.stringify(this);
}
};
const x = { y };
y.x = x;
assert.throws(() => util.inspect(x), /TypeError: Converting circular structure to JSON/);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like something that could break in a V8 update, not blocking but it'd be nice to find a way to test that without relying on the commit message


class NotStringClass {
get [Symbol.toStringTag]() {
return null;
Expand Down
Loading