Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions goldens/size-tracking/integration-payloads.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"master": {
"uncompressed": {
"runtime-es2015": 1485,
"main-es2015": 141394,
"polyfills-es2015": 36963
"main-es2015": 141151,
"polyfills-es2015": 36571
}
}
},
Expand All @@ -22,7 +22,7 @@
"uncompressed": {
"runtime-es2015": 1485,
"main-es2015": 147314,
"polyfills-es2015": 36963
"polyfills-es2015": 36571
}
}
},
Expand Down
38 changes: 0 additions & 38 deletions packages/zone.js/lib/common/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,44 +459,6 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
ZoneAwarePromise['all'] = ZoneAwarePromise.all;

const NativePromise = global[symbolPromise] = global['Promise'];
const ZONE_AWARE_PROMISE = Zone.__symbol__('ZoneAwarePromise');

let desc = ObjectGetOwnPropertyDescriptor(global, 'Promise');
if (!desc || desc.configurable) {
desc && delete desc.writable;
desc && delete desc.value;
if (!desc) {
desc = {configurable: true, enumerable: true};
}
desc.get = function() {
// if we already set ZoneAwarePromise, use patched one
// otherwise return native one.
return global[ZONE_AWARE_PROMISE] ? global[ZONE_AWARE_PROMISE] : global[symbolPromise];
};
desc.set = function(NewNativePromise) {
if (NewNativePromise === ZoneAwarePromise) {
// if the NewNativePromise is ZoneAwarePromise
// save to global
global[ZONE_AWARE_PROMISE] = NewNativePromise;
} else {
// if the NewNativePromise is not ZoneAwarePromise
// for example: after load zone.js, some library just
// set es6-promise to global, if we set it to global
// directly, assertZonePatched will fail and angular
// will not loaded, so we just set the NewNativePromise
// to global[symbolPromise], so the result is just like
// we load ES6 Promise before zone.js
global[symbolPromise] = NewNativePromise;
if (!NewNativePromise.prototype[symbolThen]) {
patchThen(NewNativePromise);
}
api.setNativePromise(NewNativePromise);
}
};

ObjectDefineProperty(global, 'Promise', desc);
}

global['Promise'] = ZoneAwarePromise;

const symbolThenPatched = __symbol__('thenPatched');
Expand Down
2 changes: 1 addition & 1 deletion packages/zone.js/lib/extra/bluebird.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ Zone.__load_patch('bluebird', (global: any, Zone: ZoneType, api: _ZonePrivate) =
});

// override global promise
global[api.symbol('ZoneAwarePromise')] = Bluebird;
global.Promise = Bluebird;
};
});
9 changes: 0 additions & 9 deletions packages/zone.js/lib/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ interface _ZonePrivate {
patchEventTarget: (global: any, apis: any[], options?: any) => boolean[];
patchOnProperties: (obj: any, properties: string[]|null, prototype?: any) => void;
patchThen: (ctro: Function) => void;
setNativePromise: (nativePromise: any) => void;
patchMethod:
(target: any, name: string,
patchFn: (delegate: Function, delegateName: string, name: string) =>
Expand Down Expand Up @@ -1419,14 +1418,6 @@ const Zone: ZoneType = (function(global: any) {
bindArguments: () => [],
patchThen: () => noop,
patchMacroTask: () => noop,
setNativePromise: (NativePromise: any) => {
// sometimes NativePromise.resolve static function
// is not ready yet, (such as core-js/es6.promise)
// so we need to check here.
if (NativePromise && typeof NativePromise.resolve === 'function') {
nativeMicroTaskQueuePromise = NativePromise.resolve(0);
}
},
patchEventPrototype: () => noop,
isIEOrEdge: () => false,
getGlobalObjects: () => undefined,
Expand Down
11 changes: 4 additions & 7 deletions packages/zone.js/test/common/zone.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,23 +334,20 @@ describe('Zone', function() {
Zone.assertZonePatched();
});

it('should keep ZoneAwarePromise has been patched', () => {
xit('should throw error if ZoneAwarePromise has been overwritten', () => {
class WrongPromise {
static resolve(value: any) {}

then() {}
}

const ZoneAwarePromise = global.Promise;
const NativePromise = (global as any)[zoneSymbol('Promise')];
global.Promise = WrongPromise;
try {
expect(ZoneAwarePromise).toBeTruthy();
Zone.assertZonePatched();
expect(global.Promise).toBe(ZoneAwarePromise);
global.Promise = WrongPromise;
expect(Zone.assertZonePatched()).toThrow();
} finally {
// restore it.
global.Promise = NativePromise;
global.Promise = ZoneAwarePromise;
}
Zone.assertZonePatched();
});
Expand Down