From 8c2c02d28a9db48baa7af579f44ef56821d5a2bd Mon Sep 17 00:00:00 2001 From: Chemi Atlow Date: Thu, 15 Jun 2023 15:55:12 +0300 Subject: [PATCH] lib: create weakRef only if any signals provided PR-URL: https://github.com/nodejs/node/pull/48448 Fixes: https://github.com/nodejs/node/issues/48419 Reviewed-By: Antoine du Hamel Reviewed-By: Nitzan Uziely Reviewed-By: Moshe Atlow Reviewed-By: Luigi Pinca --- lib/internal/abort_controller.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/internal/abort_controller.js b/lib/internal/abort_controller.js index 779d2a7c39144a..e31738b98288ca 100644 --- a/lib/internal/abort_controller.js +++ b/lib/internal/abort_controller.js @@ -197,6 +197,9 @@ class AbortSignal extends EventTarget { static any(signals) { validateAbortSignalArray(signals, 'signals'); const resultSignal = createAbortSignal({ composite: true }); + if (!signals.length) { + return resultSignal; + } const resultSignalWeakRef = new WeakRef(resultSignal); resultSignal[kSourceSignals] = new SafeSet(); for (let i = 0; i < signals.length; i++) {