Skip to content

Commit 1144617

Browse files
committed
fixup! util: add infinite recursion test case
1 parent 6ce0656 commit 1144617

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/parallel/test-util-inspect.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,6 +2745,43 @@ assert.strictEqual(
27452745
);
27462746
}
27472747

2748+
// Property getter throwing an error whose own getters throw that same error (infinite recursion).
2749+
{
2750+
const badError = new Error();
2751+
2752+
const throwingGetter = {
2753+
__proto__: null,
2754+
get() {
2755+
throw badError;
2756+
},
2757+
configurable: true,
2758+
enumerable: true,
2759+
};
2760+
2761+
Object.defineProperties(badError, {
2762+
name: throwingGetter,
2763+
message: throwingGetter,
2764+
stack: throwingGetter,
2765+
cause: throwingGetter,
2766+
});
2767+
2768+
const thrower = {
2769+
get foo() { throw badError; }
2770+
};
2771+
2772+
assert.strictEqual(
2773+
inspect(thrower, { getters: true, depth: Infinity }),
2774+
'{\n' +
2775+
' foo: [Getter: <Inspection threw (<ref *1> [object Error] {\n' +
2776+
' stack: [Getter/Setter: <Inspection threw ([Circular *1])>],\n' +
2777+
' name: [Getter: <Inspection threw ([Circular *1])>],\n' +
2778+
' message: [Getter: <Inspection threw ([Circular *1])>],\n' +
2779+
' cause: [Getter: <Inspection threw ([Circular *1])>]\n' +
2780+
' })>]\n' +
2781+
'}'
2782+
);
2783+
}
2784+
27482785
// Property getter throwing uncommon values.
27492786
{
27502787
assert.strictEqual(

0 commit comments

Comments
 (0)