@@ -85,17 +85,23 @@ var isPerformingWork = false;
85
85
var isHostCallbackScheduled = false ;
86
86
var isHostTimeoutScheduled = false ;
87
87
88
+ // Web Workers can't access window.
89
+ // Many browsers provide a globalThis property for this reason.
90
+ // For legacy reasons (mostly unit tests) this code prefers window if defined.
91
+ // eslint-disable-next-line no-undef
92
+ const globalObject = typeof window !== 'undefined' ? window : globalThis ;
93
+
88
94
// Capture local references to native APIs, in case a polyfill overrides them.
89
- const setTimeout = window . setTimeout ;
90
- const clearTimeout = window . clearTimeout ;
91
- const setImmediate = window . setImmediate ; // IE and Node.js + jsdom
95
+ const setTimeout = globalObject . setTimeout ;
96
+ const clearTimeout = globalObject . clearTimeout ;
97
+ const setImmediate = globalObject . setImmediate ; // IE and Node.js + jsdom
92
98
93
99
if ( typeof console !== 'undefined' ) {
94
100
// TODO: Scheduler no longer requires these methods to be polyfilled. But
95
101
// maybe we want to continue warning if they don't exist, to preserve the
96
102
// option to rely on it in the future?
97
- const requestAnimationFrame = window . requestAnimationFrame ;
98
- const cancelAnimationFrame = window . cancelAnimationFrame ;
103
+ const requestAnimationFrame = globalObject . requestAnimationFrame ;
104
+ const cancelAnimationFrame = globalObject . cancelAnimationFrame ;
99
105
100
106
if ( typeof requestAnimationFrame !== 'function' ) {
101
107
// Using console['error'] to evade Babel and ESLint
0 commit comments