diff --git a/src/runtime/node/timers/index.ts b/src/runtime/node/timers/index.ts index 31cc2fce..10480d21 100644 --- a/src/runtime/node/timers/index.ts +++ b/src/runtime/node/timers/index.ts @@ -12,18 +12,18 @@ import { setIntervalFallback } from "./internal/set-interval"; export * as promises from "./promises"; export const clearImmediate: typeof timers.clearImmediate = - globalThis.clearImmediate || clearImmediateFallback; + globalThis.clearImmediate?.bind(globalThis) || clearImmediateFallback; export const clearInterval: typeof timers.clearInterval = - globalThis.clearInterval || noop; + globalThis.clearInterval?.bind(globalThis) || noop; export const clearTimeout: typeof timers.clearTimeout = - globalThis.clearTimeout || noop; + globalThis.clearTimeout?.bind(globalThis) || noop; export const setImmediate: typeof timers.setImmediate = - globalThis.setImmediate || setImmediateFallback; + globalThis.setImmediate?.bind(globalThis) || setImmediateFallback; export const setTimeout: typeof timers.setTimeout = - globalThis.setTimeout || setTimeoutFallback; + globalThis.setTimeout?.bind(globalThis) || setTimeoutFallback; export const setInterval: typeof timers.setInterval = - globalThis.setInterval || setIntervalFallback; + globalThis.setInterval?.bind(globalThis) || setIntervalFallback; export const active = notImplemented("timers.active"); export const _unrefActive = notImplemented("timers._unrefActive"); diff --git a/test/workerd/tests.mjs b/test/workerd/tests.mjs index e24b26e8..76e3749b 100644 --- a/test/workerd/tests.mjs +++ b/test/workerd/tests.mjs @@ -157,6 +157,18 @@ export const workerd_dns = { }, }; +// --- node:timers + +export const workerd_timers = { + async test() { + const timers = await import("unenv/runtime/node/timers"); + + timers.clearTimeout(timers.setTimeout(() => null, 1000)); + timers.clearInterval(timers.setInterval(() => null, 1000)); + timers.clearImmediate(timers.setImmediate(() => null)); + }, +}; + // --- unenv:fetch // https://github.com/unjs/unenv/issues/364