From 5e27e595fb22143757956a9fa5ee915d5691b2fd Mon Sep 17 00:00:00 2001 From: Livia Medeiros Date: Sun, 27 Oct 2024 05:27:20 +0900 Subject: [PATCH] test: avoid `apply()` calls with large amount of elements PR-URL: https://github.com/nodejs/node/pull/55501 Reviewed-By: Luigi Pinca Reviewed-By: Antoine du Hamel Reviewed-By: Chemi Atlow --- 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');