Skip to content

test: force slow JSON.stringify path for overflow #58181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions test/fixtures/console/stack_overflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading