Skip to content

Commit

Permalink
The global scope in Workers is called self instead of window. How…
Browse files Browse the repository at this point in the history
…ever to be more generic we can use `globalThis` instead.

RELNOTES: Fix errors in errorhandler.js in Worker contexts

PiperOrigin-RevId: 504290713
Change-Id: I6f8f8db4c80a85814bd083693227334627e86f02
  • Loading branch information
Closure Team authored and Copybara-Service committed Jan 24, 2023
1 parent 41a3ba0 commit 53b06a2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions closure/goog/debug/errorhandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ goog.debug.ErrorHandler.prototype.protectWindowSetInterval = function() {
*/
goog.debug.ErrorHandler.prototype.catchUnhandledRejections = function(win) {
'use strict';
win = win || goog.global['window'];
win = win || goog.global['window'] || goog.global['globalThis'];
if ('onunhandledrejection' in win) {
win.onunhandledrejection = (event) => {
// event.reason contains the rejection reason. When an Error is
Expand All @@ -238,7 +238,7 @@ goog.debug.ErrorHandler.prototype.catchUnhandledRejections = function(win) {
goog.debug.ErrorHandler.prototype.protectWindowRequestAnimationFrame =
function() {
'use strict';
var win = goog.global['window'];
const win = goog.global['window'] || goog.global['globalThis'];
var fnNames = [
'requestAnimationFrame', 'mozRequestAnimationFrame', 'webkitAnimationFrame',
'msRequestAnimationFrame'
Expand All @@ -261,7 +261,7 @@ goog.debug.ErrorHandler.prototype.protectWindowRequestAnimationFrame =
goog.debug.ErrorHandler.prototype.protectWindowFunctionsHelper_ = function(
fnName) {
'use strict';
var win = goog.global['window'];
const win = goog.global['window'] || goog.global['globalThis'];
var originalFn = win[fnName];
if (!originalFn) throw new Error(fnName + ' not on global?');
var that = this;
Expand Down Expand Up @@ -328,7 +328,7 @@ goog.debug.ErrorHandler.prototype.setPrefixErrorMessages = function(
goog.debug.ErrorHandler.prototype.disposeInternal = function() {
'use strict';
// Try to unwrap window.setTimeout and window.setInterval.
var win = goog.global['window'];
const win = goog.global['window'] || goog.global['globalThis'];
win.setTimeout = this.unwrap(win.setTimeout);
win.setInterval = this.unwrap(win.setInterval);

Expand Down

0 comments on commit 53b06a2

Please sign in to comment.