whatwg / webidl

Web IDL Standard
https://webidl.spec.whatwg.org/
Other
409 stars 163 forks source link

Promises: resolve algorithm should accept a promise #957

Open annevk opened 3 years ago

annevk commented 3 years ago

It seems like you currently cannot resolve a promise with another one.

This came up in https://github.com/privacycg/storage-access/pull/70.

tabatkins commented 2 years ago

This just came up for me, when writing spec text for Shared Element Transitions. I have a method that accepts an async callback and returns a promise, which should resolve with the callback's returned promise.

As far as I can tell, the existing algorithm already works perfectly; we'd skip step 1 since the value isn't undefined, step 2 will convert the IDL promise into an ES promise, and then step 3 will resolve one promise with the other, which is what we want. Literally all we need to do is change the argument to the algo from

with x (a value of type T)

to

with x (a value of type T or Promise<T>)

I think?

annevk commented 2 years ago

That sounds right.

(There might also be problems with having a JS object and treating it as an IDL object and vice versa, but that's kind of an existing problem we need to tackle at some point.)