Skip to content

Commit

Permalink
fix: proper detection of global in WebWorker
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Sep 11, 2016
1 parent 2b15b01 commit 0a7a155
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {patchMethod, patchPrototype, patchClass, zoneSymbol} from "../common/uti
const set = 'set';
const clear = 'clear';
const blockingMethods = ['alert', 'prompt', 'confirm'];
const _global = typeof window == 'undefined' ? global : window;
const _global = typeof window === 'object' && window || typeof self === 'object' && self || global;

patchTimer(_global, set, clear, 'Timeout');
patchTimer(_global, set, clear, 'Interval');
Expand Down
2 changes: 1 addition & 1 deletion lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Hack since TypeScript isn't compiling this for a worker.
declare const WorkerGlobalScope;
export const zoneSymbol: (name: string) => string = Zone['__symbol__'];
const _global = typeof window == 'undefined' ? global : window;
const _global = typeof window === 'object' && window || typeof self === 'object' && self || global;

export function bindArguments(args: any[], source: string): any[] {
for (let i = args.length - 1; i >= 0; i--) {
Expand Down
2 changes: 1 addition & 1 deletion lib/node/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {patchTimer} from '../common/timers';

const set = 'set';
const clear = 'clear';
const _global = typeof window === 'undefined' ? global : window;
const _global = typeof window === 'object' && window || typeof self === 'object' && self || global;

// Timers
const timers = require('timers');
Expand Down
2 changes: 1 addition & 1 deletion lib/zone-spec/fake-async-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,4 @@
// Export the class so that new instances can be created with proper
// constructor params.
Zone['FakeAsyncTestZoneSpec'] = FakeAsyncTestZoneSpec;
})(typeof window !== 'undefined' ? window : global);
})(typeof window === 'object' && window || typeof self === 'object' && self || global);
2 changes: 1 addition & 1 deletion lib/zone-spec/wtf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@
}

Zone['wtfZoneSpec'] = !wtfEnabled ? null : new WtfZoneSpec();
})(typeof window == 'undefined' ? global : window);
})(typeof window === 'object' && window || typeof self === 'object' && self || global);
2 changes: 1 addition & 1 deletion lib/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1157,4 +1157,4 @@ const Zone: ZoneType = (function(global: any) {
// This is not part of public API, but it is usefull for tests, so we expose it.
Promise[Zone.__symbol__('uncaughtPromiseErrors')] = _uncaughtPromiseErrors;
return global.Zone = Zone;
})(typeof window === 'undefined' ? global : window);
})(typeof window === 'object' && window || typeof self === 'object' && self || global);
2 changes: 0 additions & 2 deletions test/zone_worker_entry_point.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Setup tests for Zone without microtask support
(self as any).global = self;

System.config({
defaultJSExtensions: true
});
Expand Down

0 comments on commit 0a7a155

Please sign in to comment.