forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(zone.js): Promise.resolve(subPromise) should return subPromise
In the original `Promise` impelmentation, zone.js follow the spec from https://promisesaplus.com/#point-51. ``` const p1 = Promise.resolve(1); const p2 = Promise.resolve(p1); p1 === p2; // false ``` in this case, `p2` should be the same status with `p1` but they are still different instances. And for some edge case. ``` class MyPromise extends Promise { constructor(sub) { super((res) => res(null)); this.sub = sub; } then(onFufilled, onRejected) { this.sub.then(onFufilled, onRejected); } } const p1 = new Promise(setTimeout(res), 100); const myP = new MyPromise(p1); const r = await myP; r === 1; // false ``` So in the above code, `myP` is not the same instance with `p1`, and since `myP` is resolved in constructor, so `await myP` will just pass without waiting for `p1`. And in the current `tc39` spec here https://tc39.es/ecma262/multipage/control-abstraction-objects.html#sec-promise-resolve `Promise.resolve(subP)` should return `subP`. ``` const p1 = Promise.resolve(1); const p2 = Promise.resolve(p1); p1 === p2; // true ``` So the above `MyPromise` can wait for the `p1` correctly.
- Loading branch information
1 parent
5f73608
commit a2a89a5
Showing
7 changed files
with
69 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.