Skip to content

Commit

Permalink
Fix setTimeoutCustom in worker thread (#6923)
Browse files Browse the repository at this point in the history
In worker thread, window doesn't exist so !window will raise a
referenceError. Check "typeof window" to fix this.

BUG #6922

Co-authored-by: Matthew Soulanille <msoulanille@google.com>
  • Loading branch information
gyagp and mattsoulanille committed Oct 10, 2022
1 parent fd95c22 commit 522ff47
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tfjs-core/src/platforms/platform_browser.ts
Expand Up @@ -62,7 +62,8 @@ export class PlatformBrowser implements Platform {
// Interleaving window.postMessage and setTimeout will trick the browser and
// avoid the clamp.
setTimeoutCustom(functionRef: Function, delay: number): void {
if (!window || !env().getBool('USE_SETTIMEOUTCUSTOM')) {
if (typeof window === 'undefined' ||
!env().getBool('USE_SETTIMEOUTCUSTOM')) {
setTimeout(functionRef, delay);
return;
}
Expand Down

0 comments on commit 522ff47

Please sign in to comment.