Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 0a7a155

Browse files
committed
fix: proper detection of global in WebWorker
1 parent 2b15b01 commit 0a7a155

File tree

7 files changed

+6
-8
lines changed

7 files changed

+6
-8
lines changed

Diff for: lib/browser/browser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {patchMethod, patchPrototype, patchClass, zoneSymbol} from "../common/uti
99
const set = 'set';
1010
const clear = 'clear';
1111
const blockingMethods = ['alert', 'prompt', 'confirm'];
12-
const _global = typeof window == 'undefined' ? global : window;
12+
const _global = typeof window === 'object' && window || typeof self === 'object' && self || global;
1313

1414
patchTimer(_global, set, clear, 'Timeout');
1515
patchTimer(_global, set, clear, 'Interval');

Diff for: lib/common/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// Hack since TypeScript isn't compiling this for a worker.
88
declare const WorkerGlobalScope;
99
export const zoneSymbol: (name: string) => string = Zone['__symbol__'];
10-
const _global = typeof window == 'undefined' ? global : window;
10+
const _global = typeof window === 'object' && window || typeof self === 'object' && self || global;
1111

1212
export function bindArguments(args: any[], source: string): any[] {
1313
for (let i = args.length - 1; i >= 0; i--) {

Diff for: lib/node/node.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {patchTimer} from '../common/timers';
33

44
const set = 'set';
55
const clear = 'clear';
6-
const _global = typeof window === 'undefined' ? global : window;
6+
const _global = typeof window === 'object' && window || typeof self === 'object' && self || global;
77

88
// Timers
99
const timers = require('timers');

Diff for: lib/zone-spec/fake-async-test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,4 @@
258258
// Export the class so that new instances can be created with proper
259259
// constructor params.
260260
Zone['FakeAsyncTestZoneSpec'] = FakeAsyncTestZoneSpec;
261-
})(typeof window !== 'undefined' ? window : global);
261+
})(typeof window === 'object' && window || typeof self === 'object' && self || global);

Diff for: lib/zone-spec/wtf.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,4 @@
137137
}
138138

139139
Zone['wtfZoneSpec'] = !wtfEnabled ? null : new WtfZoneSpec();
140-
})(typeof window == 'undefined' ? global : window);
140+
})(typeof window === 'object' && window || typeof self === 'object' && self || global);

Diff for: lib/zone.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1157,4 +1157,4 @@ const Zone: ZoneType = (function(global: any) {
11571157
// This is not part of public API, but it is usefull for tests, so we expose it.
11581158
Promise[Zone.__symbol__('uncaughtPromiseErrors')] = _uncaughtPromiseErrors;
11591159
return global.Zone = Zone;
1160-
})(typeof window === 'undefined' ? global : window);
1160+
})(typeof window === 'object' && window || typeof self === 'object' && self || global);

Diff for: test/zone_worker_entry_point.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// Setup tests for Zone without microtask support
2-
(self as any).global = self;
3-
42
System.config({
53
defaultJSExtensions: true
64
});

0 commit comments

Comments
 (0)