Re: [whatwg/streams] Add helpers to use initial values of Promise methods (#1010)

This became a bit more involved than I first anticipated.

I've added the following helpers:
* `uponFulfillment`: implements [_upon fulfillment of p with value v_](https://www.w3.org/2001/tag/doc/promises-guide/#upon-fulfillment)
* `uponRejection`: implements [_upon rejection of p with reason r_](https://www.w3.org/2001/tag/doc/promises-guide/#upon-rejection)
* `uponPromise`: combines `uponFulfillment` and `uponRejection` in a single call. This keeps the code simple, since the spec often uses _upon fulfillment_ and _upon rejection_ together in subsequent steps. (I'm not 100% sure about the function name. I guess `uponFulfillmentAndRejection` would be more accurate, but I find it a bit too verbose.)
* `transformPromiseWith`: implements [_transforming p with a fulfillment and/or rejection handler_](https://www.w3.org/2001/tag/doc/promises-guide/#transforming-by) (Again, suggestions for a better name are welcome. 😛)
* `setPromiseIsHandledToTrue`: sets `[[PromiseIsHandled]]` to true

Note that the `upon*` helpers do *not* return the created promise. Only `transformPromiseWith` returns a promise, as required by the "transforming a promise" definition.

The cool bit: these helpers also take care of re-throwing assertion errors where needed. Previously, we had a few places where we accidentally used `.catch(() => {})` instead of `.catch(rethrowAssertionErrorRejection)`. Since the helpers now always attach this rejection handler to the created promise, we no longer have to worry about it in the rest of the reference implementation. 😄

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/1010#issuecomment-523642956

Received on Wednesday, 21 August 2019 20:48:49 UTC