From 721208f29258d54f961b6417eddcd7e784fa5647 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Wed, 23 Oct 2024 17:23:41 +0800 Subject: [PATCH] test: avoid `apply()` calls with large amount of elements --- test/parallel/test-buffer-includes.js | 5 +---- test/parallel/test-buffer-indexof.js | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/test/parallel/test-buffer-includes.js b/test/parallel/test-buffer-includes.js index 57b3a33aaa487f..3d6138faca813f 100644 --- a/test/parallel/test-buffer-includes.js +++ b/test/parallel/test-buffer-includes.js @@ -213,10 +213,7 @@ assert(!asciiString.includes('\x2061')); assert(asciiString.includes('leb', 0)); // Search in string containing many non-ASCII chars. -const allCodePoints = []; -for (let i = 0; i < 65534; i++) allCodePoints[i] = i; -const allCharsString = String.fromCharCode.apply(String, allCodePoints) + - String.fromCharCode(65534, 65535); +const allCharsString = Array.from({ length: 65536 }, (_, i) => String.fromCharCode(i)).join(''); const allCharsBufferUtf8 = Buffer.from(allCharsString); const allCharsBufferUcs2 = Buffer.from(allCharsString, 'ucs2'); diff --git a/test/parallel/test-buffer-indexof.js b/test/parallel/test-buffer-indexof.js index 01cbd3dd5ab186..108b2f3071557e 100644 --- a/test/parallel/test-buffer-indexof.js +++ b/test/parallel/test-buffer-indexof.js @@ -285,10 +285,7 @@ assert.strictEqual(-1, asciiString.indexOf('\x2061')); assert.strictEqual(asciiString.indexOf('leb', 0), 3); // Search in string containing many non-ASCII chars. -const allCodePoints = []; -for (let i = 0; i < 65534; i++) allCodePoints[i] = i; -const allCharsString = String.fromCharCode.apply(String, allCodePoints) + - String.fromCharCode(65534, 65535); +const allCharsString = Array.from({ length: 65536 }, (_, i) => String.fromCharCode(i)).join(''); const allCharsBufferUtf8 = Buffer.from(allCharsString); const allCharsBufferUcs2 = Buffer.from(allCharsString, 'ucs2');