From b6f1e8234ca2048c329100e0c72db440cc563b4f Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 5 May 2025 14:54:01 +0200 Subject: [PATCH] test: force slow JSON.stringify path for overflow --- 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 565692b6d6e4ba..14bceef878b5cf 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);