GeezerVison is showing github.com — util: do not catch on circular `@@toStringTag` errors · nodejs/node@4129bc7
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js +8-11Lines changed: 8 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1072,6 +1072,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray) { | 1072 | 1072 | ArrayPrototypePushApply(output, protoProps); | 1073 | 1073 | } | 1074 | 1074 | } catch (err) { | | 1075 | + if (!isStackOverflowError(err)) throw err; | 1075 | 1076 | const constructorName = StringPrototypeSlice(getCtxStyle(value, constructor, tag), 0, -1); | 1076 | 1077 | return handleMaxCallStackSize(ctx, err, constructorName, indentationLvl); | 1077 | 1078 | } | @@ -1557,17 +1558,13 @@ function groupArrayElements(ctx, output, value) { | 1557 | 1558 | } | 1558 | 1559 |
| 1559 | 1560 | 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 | + ); | 1571 | 1568 | } | 1572 | 1569 |
| 1573 | 1570 | function addNumericSeparator(integerString) { | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect.js +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1644,6 +1644,15 @@ util.inspect(process); | 1644 | 1644 |
| 1645 | 1645 | assert.throws(() => util.inspect(new ThrowingClass()), /toStringTag error/); | 1646 | 1646 |
| | 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 | + | 1647 | 1656 | class NotStringClass { | 1648 | 1657 | get [Symbol.toStringTag]() { | 1649 | 1658 | return null; | |
|