webidl icon indicating copy to clipboard operation
webidl copied to clipboard

Realm to use for promises

Open annevk opened this issue 3 years ago • 4 comments

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.

annevk avatar Oct 15 '20 09:10 annevk

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

domenic avatar Oct 15 '20 15:10 domenic

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

annevk avatar Oct 15 '20 15:10 annevk

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.

domenic avatar Oct 15 '20 15:10 domenic

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

karlt avatar Oct 19 '20 21:10 karlt