Skip to content

Commit 047f420

Browse files
authored
fix: use explicit context for setTimeout function (#699)
In order to fix "Illegal invocation" errors that happen on some platforms.
1 parent 12b7d78 commit 047f420

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/util.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ export function pick(obj, ...attr) {
1010
}
1111

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

1616
export function installTimerFunctions(obj, opts) {
1717
if (opts.useNativeTimers) {
1818
obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globalThis);
1919
obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globalThis);
2020
} else {
21-
obj.setTimeoutFn = setTimeout.bind(globalThis);
22-
obj.clearTimeoutFn = clearTimeout.bind(globalThis);
21+
obj.setTimeoutFn = globalThis.setTimeout.bind(globalThis);
22+
obj.clearTimeoutFn = globalThis.clearTimeout.bind(globalThis);
2323
}
2424
}
2525

0 commit comments

Comments
 (0)