Skip to content

Commit

Permalink
Specify the this value must not be special. Closes #58.
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Feb 16, 2013
1 parent b6ba05a commit 223b599
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions README.md
Expand Up @@ -59,18 +59,19 @@ 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);
```

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.
Expand All @@ -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:
Expand Down

0 comments on commit 223b599

Please sign in to comment.