[whatwg/webidl] Spec should be clearer than a `Promise<T>` argument also accepts `T` objects (Issue #1494)

tabatkins created an issue (whatwg/webidl#1494)

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

As far as I can tell, when an argument is of type `Promise<T>`, no verification is done on the value itself. Instead, when such an argument passes from JS into IDL, [the algorithm](https://webidl.spec.whatwg.org/#js-promise) just wraps the value in a new promise capability (which absorbs a passed promise, but also absorbs arbitrary thenables, and in fact any value at all). (This is presumably why it's not allowed to put `Promise<>` in a union, because it already absorbs all possible input types and thus isn't distinguishable from anything.)

This implies a few things that I think are useful for spec authors to know, neither of which are spelled out in the spec:

1. Authors can automatically pass `T` values to any `Promise<T>` argument.
2. Authors can also pass *non-`T`* values to any `Promise<T>` argument, so the function's algorithm needs to manually verify that it's the right type when responding to the promise.

I'm happy to PR some Note text, if y'all agree this is worth fixing.

(Context: a Googler spec author was asking how they should write their IDL to accept both a `T` and `Promise<T>` for an argument.)

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

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

Received on Friday, 13 June 2025 22:39:28 UTC