test: force slow JSON.stringify path for overflow

PR-URL: https://github.com/nodejs/node/pull/58181
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Shelley Vohr authored and Michaël Zasso committed 2025-05-31 15:02:42 +02:00
1 parent 11e4cd698b
commit 4d9d6830e0
1 file changed
+8 -4
+8 -4
View File
@@ -26,11 +26,15 @@ Error.stackTraceLimit = 0;
console.error('before');
// Invalidate elements protector to force slow-path.
// The fast-path of JSON.stringify is iterative and won't throw.
Array.prototype[2] = 'foo';
// Trigger stack overflow by stringifying a deeply nested array.
let array = [];
for (let i = 0; i < 100000; i++) {
array = [ array ];
}
// eslint-disable-next-line no-sparse-arrays
let array = [,];
for (let i = 0; i < 10000; i++)
array = [array];
JSON.stringify(array);