Skip to content

Commit 8f6462f

Browse files
LiviaMedeirosmarco-ippolito
authored andcommitted
test: avoid apply() calls with large amount of elements
PR-URL: #55501 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent e9b0ff4 commit 8f6462f

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

test/parallel/test-buffer-includes.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,7 @@ assert(!asciiString.includes('\x2061'));
213213
assert(asciiString.includes('leb', 0));
214214

215215
// Search in string containing many non-ASCII chars.
216-
const allCodePoints = [];
217-
for (let i = 0; i < 65534; i++) allCodePoints[i] = i;
218-
const allCharsString = String.fromCharCode.apply(String, allCodePoints) +
219-
String.fromCharCode(65534, 65535);
216+
const allCharsString = Array.from({ length: 65536 }, (_, i) => String.fromCharCode(i)).join('');
220217
const allCharsBufferUtf8 = Buffer.from(allCharsString);
221218
const allCharsBufferUcs2 = Buffer.from(allCharsString, 'ucs2');
222219

test/parallel/test-buffer-indexof.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,7 @@ assert.strictEqual(-1, asciiString.indexOf('\x2061'));
285285
assert.strictEqual(asciiString.indexOf('leb', 0), 3);
286286

287287
// Search in string containing many non-ASCII chars.
288-
const allCodePoints = [];
289-
for (let i = 0; i < 65534; i++) allCodePoints[i] = i;
290-
const allCharsString = String.fromCharCode.apply(String, allCodePoints) +
291-
String.fromCharCode(65534, 65535);
288+
const allCharsString = Array.from({ length: 65536 }, (_, i) => String.fromCharCode(i)).join('');
292289
const allCharsBufferUtf8 = Buffer.from(allCharsString);
293290
const allCharsBufferUcs2 = Buffer.from(allCharsString, 'ucs2');
294291

0 commit comments

Comments
 (0)