From 57c140d899063392cb0c0bb0e23fb46b0cbf9e2b Mon Sep 17 00:00:00 2001 From: netil Date: Fri, 27 Oct 2023 10:42:01 +0900 Subject: [PATCH] fix(module): Fix getFallback() uninitialized variable Fix the referencing error and the condition to prevent some potential issue. side-effect caused by https://github.com/naver/billboard.js/commit/201a8e3ce7c3fe65085f17e7a0ed726cbf7ec325 Ref #3489 --- src/module/browser.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/module/browser.ts b/src/module/browser.ts index 3a17a3ce6..ac1d7b7dd 100644 --- a/src/module/browser.ts +++ b/src/module/browser.ts @@ -33,14 +33,16 @@ function getGlobal() { * @private */ function getFallback(w) { - const hasRAF = typeof w?.requestAnimationFrame === "function"; - const hasRIC = typeof w?.requestIdleCallback === "function"; + const hasRAF = typeof w?.requestAnimationFrame === "function" && typeof w?.cancelAnimationFrame === "function"; + const hasRIC = typeof w?.requestIdleCallback === "function" && typeof w?.cancelIdleCallback === "function"; + const request = cb => setTimeout(cb, 1); + const cancel = id => clearTimeout(id); return [ - hasRAF ? w.requestAnimationFrame : (cb => setTimeout(cb, 1)), - hasRAF ? w.cancelAnimationFrame : (id => clearTimeout(id)), - hasRIC ? w.requestIdleCallback : requestAnimationFrame, - hasRIC ? w.cancelIdleCallback : cancelAnimationFrame + hasRAF ? w.requestAnimationFrame : request, + hasRAF ? w.cancelAnimationFrame : cancel, + hasRIC ? w.requestIdleCallback : request, + hasRIC ? w.cancelIdleCallback : cancel ]; }