diff --git a/README.md b/README.md index 8033399..86005e9 100644 --- a/README.md +++ b/README.md @@ -59,10 +59,11 @@ promise.then(onFulfilled, onRejected) 1. it must not be called more than once. 1. it must not be called if `onFulfilled` has been called. 1. `then` must return before `onFulfilled` or `onRejected` is called [[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`. 1. If/when `promise` is rejected, all respective `onRejected` callbacks must execute in the order of their originating calls to `then`. -1. `then` must return a promise [[4.2](#notes)]. +1. `then` must return a promise [[4.3](#notes)]. ``` promise2 = promise1.then(onFulfilled, onRejected); @@ -70,7 +71,7 @@ promise.then(onFulfilled, onRejected) 1. If either `onFulfilled` or `onRejected` returns a value that is not a promise, `promise2` must be fulfilled with that value. 1. If either `onFulfilled` or `onRejected` throws an exception, `promise2` must be rejected with the thrown exception as the reason. - 1. If either `onFulfilled` or `onRejected` returns a promise (call it `returnedPromise`), `promise2` must assume the state of `returnedPromise` [[4.3](#notes)]: + 1. If either `onFulfilled` or `onRejected` returns a promise (call it `returnedPromise`), `promise2` must assume the state of `returnedPromise` [[4.4](#notes)]: 1. If `returnedPromise` is pending, `promise2` must remain pending until `returnedPromise` is fulfilled or rejected. 1. If/when `returnedPromise` is fulfilled, `promise2` must be fulfilled with the same value. 1. If/when `returnedPromise` is rejected, `promise2` must be rejected with the same reason. @@ -81,6 +82,8 @@ promise.then(onFulfilled, onRejected) 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. That is, in strict mode `this` will be undefined inside of them; in sloppy mode, it will be the global object. + 1. Implementations may allow `promise2 === promise1`, provided the implementation meets all requirements. Each implementation should document whether it can produce `promise2 === promise1` and under what conditions. 1. The mechanism by which `promise2` assumes the state of `returnedPromise` is not specified. One reasonable approach is to call `returnedPromise.then(fulfillPromise2, rejectPromise2)`, where: