Skip to content

Commit

Permalink
fix: use explicit context for setTimeout function (#699)
Browse files Browse the repository at this point in the history
In order to fix "Illegal invocation" errors that happen on some
platforms.
  • Loading branch information
zongzi531 authored Jan 10, 2023
1 parent 12b7d78 commit 047f420
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ export function pick(obj, ...attr) {
}

// Keep a reference to the real timeout functions so they can be used when overridden
const NATIVE_SET_TIMEOUT = setTimeout;
const NATIVE_CLEAR_TIMEOUT = clearTimeout;
const NATIVE_SET_TIMEOUT = globalThis.setTimeout;
const NATIVE_CLEAR_TIMEOUT = globalThis.clearTimeout;

export function installTimerFunctions(obj, opts) {
if (opts.useNativeTimers) {
obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globalThis);
obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globalThis);
} else {
obj.setTimeoutFn = setTimeout.bind(globalThis);
obj.clearTimeoutFn = clearTimeout.bind(globalThis);
obj.setTimeoutFn = globalThis.setTimeout.bind(globalThis);
obj.clearTimeoutFn = globalThis.clearTimeout.bind(globalThis);
}
}

Expand Down

0 comments on commit 047f420

Please sign in to comment.