Closed ExE-Boss closed 4 years ago
Can you remove the T conversion entirely? As I pointed out, it does not exist in the Web IDL spec.
It does exist in the “to react to a Promise<T>
” algorithm.
Right. When the spec reacts to it, it can do the conversion. We shouldn't do it automatically, especially since nobody reacts to return types.
I'm sorry, perhaps I wasn't clear enough. The type conversion logic should not live in webidl2js at all.
Most notably, this fixes the bug where rejected promises were being converted into resolved promises and that
Promise.resolve(x)
returnsx
whenx
is aPromise
object from the same realm as thePromise.resolve
function, whereas WebIDL requires the conversion to always return a newPromise
object.Note that there still is a small timing difference for non‑
void
promises due to the fact that the IDL conversion and promise reaction are being performed in separatethen
callbacks, whereasWebIDL
runs them in the samethen
callback. (See the “to react to aPromise<T>
” algorithm)Fixing this minor timing discrepancy would require the type conversion to be performed manually in implementation classes or overriding the
then
method of the convertedPromise
instance.P.S.: If you still want
then
to be called with two arguments, then the correct callback is:Which is the default behaviour when
null
orundefined
is passed.