Skip to content

Commit

Permalink
fix(zone.js): use globalThis instead of global and window (#52367)
Browse files Browse the repository at this point in the history
`globalThis` global property contains the global `this` value, which is usually akin to the global object. This is needed for better compatibility with CloudFlare workers were global nor window are defined as globals.

PR Close #52367
  • Loading branch information
alan-agius4 authored and dylhunn committed Oct 25, 2023
1 parent 7b3d269 commit def719e
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/zone.js/lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ declare const WorkerGlobalScope: any;
export const zoneSymbol = Zone.__symbol__;
const isWindowExists = typeof window !== 'undefined';
const internalWindow: any = isWindowExists ? window : undefined;
const _global: any = isWindowExists && internalWindow || typeof self === 'object' && self || global;
const _global: any = isWindowExists && internalWindow || globalThis;

const REMOVE_ATTRIBUTE = 'removeAttribute';

Expand Down
2 changes: 1 addition & 1 deletion packages/zone.js/lib/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1445,4 +1445,4 @@ const Zone: ZoneType = (function(global: any) {

performanceMeasure('Zone', 'Zone');
return global['Zone'] = Zone;
})(typeof window !== 'undefined' && window || typeof self !== 'undefined' && self || global);
})(globalThis);
2 changes: 1 addition & 1 deletion packages/zone.js/test/test-env-setup-mocha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,4 @@ declare const global: any;
}
};
};
})(typeof window !== 'undefined' && window || typeof self !== 'undefined' && self || global);
})(globalThis);
2 changes: 1 addition & 1 deletion packages/zone.js/test/test_fake_polyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ global[zoneSymbolPrefix + 'FakeAsyncTestMacroTask'] = [{source: 'TestClass.myTim
global[zoneSymbolPrefix + 'UNPATCHED_EVENTS'] = ['scroll', 'wheel'];
// touchstart and scroll will be passive by default.
global[zoneSymbolPrefix + 'PASSIVE_EVENTS'] = ['touchstart', 'scroll'];
})(typeof window === 'object' && window || typeof self === 'object' && self || global);
})(globalThis);
2 changes: 1 addition & 1 deletion packages/zone.js/test/wtf_mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ beforeEach(function() {

(<any>global).wtfMock = wtfMock;
(<any>global).wtf = wtfMock;
})(typeof window === 'object' && window || typeof self === 'object' && self || global);
})(globalThis);

declare const wtfMock: any;
1 change: 0 additions & 1 deletion packages/zone.js/test/zone_worker_entry_point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ System.config({defaultJSExtensions: true});
System.import('../lib/browser/api-util').then(() => {
System.import('../lib/browser/browser-legacy').then(() => {
System.import('../lib/browser/browser').then(() => {
const _global = typeof window !== 'undefined' ? window : self;
Zone.current.fork({name: 'webworker'}).run(() => {
const websocket = new WebSocket('ws://localhost:8001');
websocket.addEventListener('open', () => {
Expand Down

0 comments on commit def719e

Please sign in to comment.