-
Notifications
You must be signed in to change notification settings - Fork 175
Description
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 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:
- Authors can automatically pass
T
values to anyPromise<T>
argument. - Authors can also pass non-
T
values to anyPromise<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.)