mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
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:
parent
a8e9f634d3
commit
29cf3c024d
1 changed files with 8 additions and 4 deletions
12
test/fixtures/console/stack_overflow.js
vendored
12
test/fixtures/console/stack_overflow.js
vendored
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue