From 29cf3c024dd8220a429ca0e9383ce523193a114b Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Fri, 30 May 2025 08:22:52 +0200 Subject: [PATCH] test: force slow JSON.stringify path for overflow PR-URL: https://github.com/nodejs/node/pull/58181 Reviewed-By: Yagiz Nizipli Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell --- test/fixtures/console/stack_overflow.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/fixtures/console/stack_overflow.js b/test/fixtures/console/stack_overflow.js index 565692b6d6..14bceef878 100644 --- a/test/fixtures/console/stack_overflow.js +++ b/test/fixtures/console/stack_overflow.js @@ -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);