Skip to content

Commit

Permalink
fix(module): Fix getFallback() uninitialized variable
Browse files Browse the repository at this point in the history
Fix the referencing error and the condition to prevent
some potential issue.

side-effect caused by 201a8e3Fix #3489
  • Loading branch information
netil authored Oct 27, 2023
1 parent 5e80d9d commit 7a1d088
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/module/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
}

Expand Down

0 comments on commit 7a1d088

Please sign in to comment.