whatwg / webidl

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

Realm to use for promises #932

Open annevk opened 4 years ago

annevk commented 4 years ago

I think we should give more advice to specifications how to deal with promises and realms.

I think typically promises are created in the relevant realm of this.

However, this might lead to inconsistencies for immediately rejected promises depending on how they are implemented. Implementations might rely on throwing being tackled by the IDL layer, which would use the current realm for such rejected promises.

Given what we have, the simplest advice to me would be that for promise-returning methods you throw in the synchronous section and let IDL deal with it, and create a promise in the relevant realm of this that you return at the end of the synchronous section (and operate on in the in parallel part).

This is fairly subjective though so I would love to hear other perspectives.

domenic commented 4 years ago

In my opinion, promises do not need any special treatment here. So I think this just reduces to #135.

annevk commented 4 years ago

@domenic that's fair, but I think that still leaves exceptions getting wrapped in promises that end up using the current realm.

domenic commented 4 years ago

Yeah, that's part of why I've discouraged specs from throwing exceptions... I guess we could just as easily wrap them in the relevant realm of this.

karlt commented 4 years ago

A key difference with the relevant realm is when it involves a discarded browsing context and awaiting the promise will never resume.