(
onFulfilled?: ((value: R) => TResult1 | PromiseLike<TResult1>) | undefined | null,
onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null,
)
| 526 | } |
| 527 | |
| 528 | then<TResult1 = R, TResult2 = never>( |
| 529 | onFulfilled?: ((value: R) => TResult1 | PromiseLike<TResult1>) | undefined | null, |
| 530 | onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null, |
| 531 | ): Promise<TResult1 | TResult2> { |
| 532 | // We must read `Symbol.species` safely because `this` may be anything. For instance, `this` |
| 533 | // may be an object without a prototype (created through `Object.create(null)`); thus |
| 534 | // `this.constructor` will be undefined. One of the use cases is SystemJS creating |
| 535 | // prototype-less objects (modules) via `Object.create(null)`. The SystemJS creates an empty |
| 536 | // object and copies promise properties into that object (within the `getOrCreateLoad` |
| 537 | // function). The zone.js then checks if the resolved value has the `then` method and |
| 538 | // invokes it with the `value` context. Otherwise, this will throw an error: `TypeError: |
| 539 | // Cannot read properties of undefined (reading 'Symbol(Symbol.species)')`. |
| 540 | let C = (this.constructor as any)?.[Symbol.species]; |
| 541 | if (!C || typeof C !== 'function') { |
| 542 | C = this.constructor || ZoneAwarePromise; |
| 543 | } |
| 544 | const chainPromise: Promise<TResult1 | TResult2> = new (C as typeof ZoneAwarePromise)(noop); |
| 545 | const zone = Zone.current; |
| 546 | if ((this as any)[symbolState] == UNRESOLVED) { |
| 547 | (<any[]>(this as any)[symbolValue]).push(zone, chainPromise, onFulfilled, onRejected); |
| 548 | } else { |
| 549 | scheduleResolveOrReject(this, zone, chainPromise as any, onFulfilled, onRejected); |
| 550 | } |
| 551 | return chainPromise; |
| 552 | } |
| 553 | |
| 554 | catch<TResult = never>( |
| 555 | onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null, |
no test coverage detected