Skip to content

Commit 4d9d683

Browse files
codebyteretargos
authored andcommitted
test: force slow JSON.stringify path for overflow
PR-URL: #58181 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 11e4cd6 commit 4d9d683

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

test/fixtures/console/stack_overflow.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@ 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 ];
33-
}
34+
// eslint-disable-next-line no-sparse-arrays
35+
let array = [,];
36+
for (let i = 0; i < 10000; i++)
37+
array = [array];
3438

3539
JSON.stringify(array);
3640

0 commit comments

Comments
 (0)