Skip to content

Commit 858d4dd

Browse files
committed
test: force slow JSON.stringify path for overflow
1 parent c46b2b9 commit 858d4dd

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

test/fixtures/console/stack_overflow.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ Error.stackTraceLimit = 0;
2626

2727
console.error('before');
2828

29+
// Invalidate elements protector to force slow-path.
30+
// The fast-path of JSON.stringify is iterative and won't throw.
31+
Array.prototype[2] = 'foo';
32+
2933
// Trigger stack overflow by stringifying a deeply nested array.
30-
let array = [];
31-
for (let i = 0; i < 100000; i++) {
32-
array = [ array ];
34+
const depth = 10000;
35+
// eslint-disable-next-line no-sparse-arrays
36+
let array = [,];
37+
for (let i = 0; i < depth; i++) {
38+
array = [array];
3339
}
3440

3541
JSON.stringify(array);

0 commit comments

Comments
 (0)