fix(zone.js): remove unused Promise overwritten setter logic (#36851)

In the early Zone.js versions (< 0.10.3), `ZoneAwarePromise` did not support `Symbol.species`,
so when user used a 3rd party `Promise` such as `es6-promise`, and try to load the promise library after import of `zone.js`, the loading promise library will overwrite the patched `Promise` from `zone.js` and will break `Promise` semantics with respect to `zone.js`.

Starting with `zone.js` 0.10.3, `Symbol.species` is supported therefore this will not longer be an issue. (https://github.com//pull/34533)

Before 0.10.3, the logic in zone.js tried to handle the case in the wrong way. It did so by overriding the descriptor of `global.Promise`, to allow the 3rd party libraries to override native `Promise` instead of `ZoneAwarePromise`. This is not the correct solution, and since the `Promise.species` is now supported, the 3rd party solution of overriding `global.Promise` is no longer needed.

PR removes the wrong work around logic. (This will improve the bundle size.)

PR Close #36851
This commit is contained in:
JiaLiPassion
2020-04-29 17:08:28 +09:00
committed by Misko Hevery
parent 9b8eb42354
commit c909e731d7
5 changed files with 8 additions and 58 deletions

View File

@ -334,7 +334,7 @@ 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) {}
@ -342,15 +342,12 @@ describe('Zone', function() {
}
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();
});