[whatwg/webidl] Should react to a Promise steps return a PromiseCapability instead of a Promise? (Issue #1443)

### What is the issue with the Web IDL Standard?

In https://webidl.spec.whatwg.org/#dfn-perform-steps-once-promise-is-settled the steps say:

> 6. Let newCapability be [?](https://tc39.es/ecma262/#sec-returnifabrupt-shorthands) [NewPromiseCapability](https://tc39.es/ecma262/multipage/control-abstraction-objects.html#sec-newpromisecapability)(constructor).
> Note: Not all callers will use the returned [Promise](https://webidl.spec.whatwg.org/#idl-promise). Implementations might wish to avoid creating newCapability in those cases.
> 7. Return [PerformPromiseThen](https://tc39.es/ecma262/multipage/control-abstraction-objects.html#sec-performpromisethen)(promise.[[Promise]], onFulfilled, onRejected, newCapability).

`PerformPromiseThen` will return `newCapability.[[Promise]]` when called this way, which results in the WebIDL algorithm returning a JS Promise object rather than a JS PromiseCapability object. Is this intentional?

I believe going off of https://webidl.spec.whatwg.org/#js-promise that the WebIDL algorithms should prefer to only expose the PromiseCapability to callers, and not the underlying [[Promise]] slot until converting back to JS at the WebIDL <-> JS Boundary.

I might rewrite the last step as

> 7.  [PerformPromiseThen](https://tc39.es/ecma262/multipage/control-abstraction-objects.html#sec-performpromisethen)(promise.[[Promise]], onFulfilled, onRejected, newCapability).
> 8. Return newCapability.

cc @domenic 

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

Message ID: <whatwg/webidl/issues/1443@github.com>

Received on Wednesday, 23 October 2024 21:41:37 UTC