Fix hide scheduler timer binding

This commit is contained in:
Hao19911125
2026-04-02 21:41:14 +08:00
parent e77233f020
commit 6ad234cd06

View File

@@ -13,15 +13,22 @@ const hideState = {
}; };
function getTimerApi(runtime = {}) { function getTimerApi(runtime = {}) {
const rawSetTimeout =
typeof runtime.setTimeout === "function"
? runtime.setTimeout
: globalThis.setTimeout;
const rawClearTimeout =
typeof runtime.clearTimeout === "function"
? runtime.clearTimeout
: globalThis.clearTimeout;
return { return {
setTimeout: setTimeout(...args) {
typeof runtime.setTimeout === "function" return Reflect.apply(rawSetTimeout, globalThis, args);
? runtime.setTimeout.bind(runtime) },
: globalThis.setTimeout.bind(globalThis), clearTimeout(...args) {
clearTimeout: return Reflect.apply(rawClearTimeout, globalThis, args);
typeof runtime.clearTimeout === "function" },
? runtime.clearTimeout.bind(runtime)
: globalThis.clearTimeout.bind(globalThis),
}; };
} }