mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
util: do not catch on circular @@toStringTag
errors
PR-URL: https://github.com/nodejs/node/pull/55544 Fixes: https://github.com/nodejs/node/issues/55539 Reviewed-By: James M Snell <jasnell@gmail.com> Co-Authored-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
98e5693cd4
commit
c185e11623
@ -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);
|
||||
}
|
||||
@ -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) {
|
||||
|
@ -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/);
|
||||
|
||||
class NotStringClass {
|
||||
get [Symbol.toStringTag]() {
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user