Skip to content

Commit 58b29f1

Browse files
JiaLiPassionmhevery
authored andcommitted
fix: should also allow subclass Promise without Symbol.species (#34533)
PR Close #34533
1 parent 60018d2 commit 58b29f1

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

packages/zone.js/lib/common/promise.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
384384
null): Promise<TResult1|TResult2> {
385385
let C = (this.constructor as any)[Symbol.species];
386386
if (!C || typeof C !== 'function') {
387-
C = ZoneAwarePromise;
387+
C = this.constructor || ZoneAwarePromise;
388388
}
389389
const chainPromise: Promise<TResult1|TResult2> = new (C as typeof ZoneAwarePromise)(noop);
390390
const zone = Zone.current;

packages/zone.js/test/common/Promise.spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,14 @@ describe(
103103
}).toThrowError('Must be an instanceof Promise.');
104104
});
105105

106-
it('should allow subclassing with Promise.specices', () => {
106+
it('should allow subclassing without Symbol.species', () => {
107+
class MyPromise extends Promise<any> {
108+
constructor(fn: any) { super(fn); }
109+
}
110+
expect(new MyPromise(() => {}).then(() => null) instanceof MyPromise).toBe(true);
111+
});
112+
113+
it('should allow subclassing with Symbol.species', () => {
107114
class MyPromise extends Promise<any> {
108115
constructor(fn: any) { super(fn); }
109116

@@ -112,7 +119,7 @@ describe(
112119
expect(new MyPromise(() => {}).then(() => null) instanceof MyPromise).toBe(true);
113120
});
114121

115-
it('Promise.specices should return ZoneAwarePromise', () => {
122+
it('Symbol.species should return ZoneAwarePromise', () => {
116123
const empty = function() {};
117124
const promise = Promise.resolve(1);
118125
const FakePromise = ((promise.constructor = {} as any) as any)[Symbol.species] = function(

0 commit comments

Comments
 (0)