From 58b29f1503a180fdfb8feb73a30d0c4448afad9a Mon Sep 17 00:00:00 2001 From: JiaLiPassion Date: Sun, 22 Dec 2019 13:15:08 +0900 Subject: [PATCH] fix: should also allow subclass Promise without Symbol.species (#34533) PR Close #34533 --- packages/zone.js/lib/common/promise.ts | 2 +- packages/zone.js/test/common/Promise.spec.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/zone.js/lib/common/promise.ts b/packages/zone.js/lib/common/promise.ts index 44fb652c58..2e12b15c53 100644 --- a/packages/zone.js/lib/common/promise.ts +++ b/packages/zone.js/lib/common/promise.ts @@ -384,7 +384,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr null): Promise { let C = (this.constructor as any)[Symbol.species]; if (!C || typeof C !== 'function') { - C = ZoneAwarePromise; + C = this.constructor || ZoneAwarePromise; } const chainPromise: Promise = new (C as typeof ZoneAwarePromise)(noop); const zone = Zone.current; diff --git a/packages/zone.js/test/common/Promise.spec.ts b/packages/zone.js/test/common/Promise.spec.ts index f5038b83f0..e277902da5 100644 --- a/packages/zone.js/test/common/Promise.spec.ts +++ b/packages/zone.js/test/common/Promise.spec.ts @@ -103,7 +103,14 @@ describe( }).toThrowError('Must be an instanceof Promise.'); }); - it('should allow subclassing with Promise.specices', () => { + it('should allow subclassing without Symbol.species', () => { + class MyPromise extends Promise { + constructor(fn: any) { super(fn); } + } + expect(new MyPromise(() => {}).then(() => null) instanceof MyPromise).toBe(true); + }); + + it('should allow subclassing with Symbol.species', () => { class MyPromise extends Promise { constructor(fn: any) { super(fn); } @@ -112,7 +119,7 @@ describe( expect(new MyPromise(() => {}).then(() => null) instanceof MyPromise).toBe(true); }); - it('Promise.specices should return ZoneAwarePromise', () => { + it('Symbol.species should return ZoneAwarePromise', () => { const empty = function() {}; const promise = Promise.resolve(1); const FakePromise = ((promise.constructor = {} as any) as any)[Symbol.species] = function(