Skip to content

Commit 4b98946

Browse files
authored
Updates isWorker() check to test if importScripts and WorkerGlobalScope are defined (#1706)
1 parent b5c8cf6 commit 4b98946

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

packages/auth/src/utils.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,12 +636,13 @@ fireauth.util.isOpenerAnIframe = function(opt_win) {
636636

637637

638638
/**
639-
* @param {?Object=} opt_global The optional global scope.
639+
* @param {?Object=} global The optional global scope.
640640
* @return {boolean} Whether current environment is a worker.
641641
*/
642-
fireauth.util.isWorker = function(opt_global) {
643-
var scope = opt_global || goog.global;
644-
return typeof scope['window'] !== 'object' &&
642+
fireauth.util.isWorker = function(global) {
643+
var scope = global || goog.global;
644+
// WorkerGlobalScope only defined in worker environment.
645+
return typeof scope['WorkerGlobalScope'] !== 'undefined' &&
645646
typeof scope['importScripts'] === 'function';
646647
};
647648

packages/auth/test/utils_test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ function testGetEnvironment_worker() {
557557
function testIsWorker() {
558558
assertFalse(fireauth.util.isWorker({'window': {}}));
559559
assertTrue(fireauth.util.isWorker({
560+
'WorkerGlobalScope': function() {},
560561
'importScripts': function() {}
561562
}));
562563
}

0 commit comments

Comments
 (0)