[heycam/webidl] "React to a promise" is not equivalent to Promise.prototype.then with missing handlers (#921)

The "react to a promise" algorithm seems to be a spec-level version of `Promise.prototype.then`, except that when it's called with a missing handler, a default handler is substituted which simply resolves the promise with `undefined`.

In other words, you would expect "react to a promise" to be equivalent to:
```js
// promise: Promise<T>
// onFulfillment?: (T) => U
// onRejection?: (any) => U
promise.then(onFulfillment, onRejection) // Promise<U>
```
and it's instead:
```js
promise.then(onFulfillment ?? () => undefined, onRejection ?? () => undefined) // Promise<U | undefined>
```

I understand that, even when there's no fulfillment handler given, the conversion to IDL of the resolved value must happen, so the promise can reject if the conversion throws (see also #782). But even in that case, the return value shouldn't be `undefined`. And for the rejection handler even that is unnecessary, since converting an ECMAScript value to `any` cannot fail.

The fact that this is the intended behavior is borne out by the definitions of "upon fulfillment" and "upon rejection", as well as by the usage of these operations in the Fetch, Streams, Background Fetch and Service Worker specs.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/issues/921

Received on Thursday, 17 September 2020 16:34:57 UTC