-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforce a clean stack for
onFulfilled
and onRejected
.
- Loading branch information
Showing
2 changed files
with
3 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,7 @@ promise.then(onFulfilled, onRejected) | |
1. it must be called after `promise` is rejected, with `promise`'s reason as its first argument. | ||
1. it must not be called before `promise` is rejected. | ||
1. it must not be called more than once. | ||
1. `then` must return before `onFulfilled` or `onRejected` is called [[4.1](#notes)]. | ||
1. `onFulfilled` or `onRejected` must not be called until the execution context stack contains only platform code. [[4.1](#notes)]. | ||
1. `onFulfilled` and `onRejected` must be called as functions (i.e. with no `this` value). [[4.2](#notes)] | ||
1. `then` may be called multiple times on the same promise. | ||
1. If/when `promise` is fulfilled, all respective `onFulfilled` callbacks must execute in the order of their originating calls to `then`. | ||
|
@@ -102,7 +102,7 @@ If a promise is resolved with a thenable that participates in a circular thenabl | |
|
||
## Notes | ||
|
||
1. In practical terms, an implementation must use a mechanism such as `setTimeout`, `setImmediate`, or `process.nextTick` to ensure that `onFulfilled` and `onRejected` are not invoked in the same turn of the event loop as the call to `then` to which they are passed. | ||
1. Here "platform code" means engine, environment, and promise implementation code. In practice, this requirement ensures that `onFulfilled` and `onRejected` execute asynchronously, after the event loop turn in which `then` is called, and with a fresh stack. This can be implemented with either a "macro-turn" mechanism such as `setTimeout` or `setImmediate`, or with a "micro-turn" mechanism such as `Object.observe` or `process.nextTick`. Since the promise implementation is considered platform code, it may itself contain a task-scheduling queue or "trampoline" in which the handlers are called. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
domenic
Author
Member
|
||
|
||
1. That is, in strict mode `this` will be `undefined` inside of them; in sloppy mode, it will be the global object. | ||
|
||
|
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
Does it make sense to provide a definition of "platform code" in the definitions section? On one hand, I can see it, since we are defining it. On the other, however, it isn't a term that is central to the foundation of promises (although it is necessary for our particular specification). It's also quite a long paragraph, and would look weird if we moved the whole thing up--would probably have to split it up, providing a short definition up top, and retain the rest of the note at the bottom. Hrm, thoughts?