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 2025-05-30 08:22:52 +02:00 committed by GitHub
parent a8e9f634d3
commit 29cf3c024d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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);