From 3d478728f2ea01813436d21c261268e97acd0624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Tue, 10 Sep 2024 14:48:04 +0200 Subject: [PATCH] timers: avoid generating holey internal arrays PR-URL: https://github.com/nodejs/node/pull/54771 Reviewed-By: James M Snell Reviewed-By: Antoine du Hamel --- lib/timers.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/timers.js b/lib/timers.js index ee7ed0d4dcbaba..9de6b8887dd943 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -22,6 +22,7 @@ 'use strict'; const { + ArrayPrototypePush, MathTrunc, ObjectDefineProperties, ObjectDefineProperty, @@ -154,7 +155,7 @@ function setTimeout(callback, after, arg1, arg2, arg3) { args = [arg1, arg2, arg3]; for (i = 5; i < arguments.length; i++) { // Extend array dynamically, makes .apply run much faster in v6.0.0 - args[i - 2] = arguments[i]; + ArrayPrototypePush(args, arguments[i]); } break; } @@ -224,7 +225,7 @@ function setInterval(callback, repeat, arg1, arg2, arg3) { args = [arg1, arg2, arg3]; for (i = 5; i < arguments.length; i++) { // Extend array dynamically, makes .apply run much faster in v6.0.0 - args[i - 2] = arguments[i]; + ArrayPrototypePush(args, arguments[i]); } break; } @@ -296,7 +297,7 @@ function setImmediate(callback, arg1, arg2, arg3) { args = [arg1, arg2, arg3]; for (i = 4; i < arguments.length; i++) { // Extend array dynamically, makes .apply run much faster in v6.0.0 - args[i - 1] = arguments[i]; + ArrayPrototypePush(args, arguments[i]); } break; }