Skip to content

Commit def719e

Browse files
alan-agius4dylhunn
authored andcommitted
fix(zone.js): use globalThis instead of global and window (angular#52367)
`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 angular#52367
1 parent 7b3d269 commit def719e

File tree

6 files changed

+5
-6
lines changed

6 files changed

+5
-6
lines changed

packages/zone.js/lib/common/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ declare const WorkerGlobalScope: any;
5555
export const zoneSymbol = Zone.__symbol__;
5656
const isWindowExists = typeof window !== 'undefined';
5757
const internalWindow: any = isWindowExists ? window : undefined;
58-
const _global: any = isWindowExists && internalWindow || typeof self === 'object' && self || global;
58+
const _global: any = isWindowExists && internalWindow || globalThis;
5959

6060
const REMOVE_ATTRIBUTE = 'removeAttribute';
6161

packages/zone.js/lib/zone.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,4 +1445,4 @@ const Zone: ZoneType = (function(global: any) {
14451445

14461446
performanceMeasure('Zone', 'Zone');
14471447
return global['Zone'] = Zone;
1448-
})(typeof window !== 'undefined' && window || typeof self !== 'undefined' && self || global);
1448+
})(globalThis);

packages/zone.js/test/test-env-setup-mocha.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,4 @@ declare const global: any;
183183
}
184184
};
185185
};
186-
})(typeof window !== 'undefined' && window || typeof self !== 'undefined' && self || global);
186+
})(globalThis);

packages/zone.js/test/test_fake_polyfill.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,4 @@ global[zoneSymbolPrefix + 'FakeAsyncTestMacroTask'] = [{source: 'TestClass.myTim
8686
global[zoneSymbolPrefix + 'UNPATCHED_EVENTS'] = ['scroll', 'wheel'];
8787
// touchstart and scroll will be passive by default.
8888
global[zoneSymbolPrefix + 'PASSIVE_EVENTS'] = ['touchstart', 'scroll'];
89-
})(typeof window === 'object' && window || typeof self === 'object' && self || global);
89+
})(globalThis);

packages/zone.js/test/wtf_mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,6 @@ beforeEach(function() {
9090

9191
(<any>global).wtfMock = wtfMock;
9292
(<any>global).wtf = wtfMock;
93-
})(typeof window === 'object' && window || typeof self === 'object' && self || global);
93+
})(globalThis);
9494

9595
declare const wtfMock: any;

packages/zone.js/test/zone_worker_entry_point.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ System.config({defaultJSExtensions: true});
1111
System.import('../lib/browser/api-util').then(() => {
1212
System.import('../lib/browser/browser-legacy').then(() => {
1313
System.import('../lib/browser/browser').then(() => {
14-
const _global = typeof window !== 'undefined' ? window : self;
1514
Zone.current.fork({name: 'webworker'}).run(() => {
1615
const websocket = new WebSocket('ws://localhost:8001');
1716
websocket.addEventListener('open', () => {

0 commit comments

Comments
 (0)