-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should we cancel promise resolution on an inactive context with an undefined handler? #4443
Comments
Per an offline discussion with @yuki3, we should probably use incumbent realm when the handler's realm is unavailable. |
cc @bzbarsky |
I'd vaguely think that it would be better for Web APIs (user agents) to return a promise created in the incumbent realm (not |
Please talk to @domenic, who has been trying to kill off the concept of incumbent realm. ;) But also, that doesn't really work for promises that are conceptually created as part of the object (e.g. the ready promise of For the original question, I would expect that Gecko just uses the Realm of the promise itself for the checks (though I have not verified this). And if all ES objects plan to grow a Realm, maybe we should just converge on that? |
Yeah, I knew @domenic's effort and it's not fun for me, too, to use the incumbent realm.
You're right.
I love that idea, but some of Web APIs seem not happy with that idea. @tzik, would you show a concrete example that a certain Web API (fullscreen API?) wants their promise to get resolved even after the browsing context navigated away? |
One example is from Payment Request API: https://w3c.github.io/payment-request/#show-method
crbug/941271 has a concrete example. |
(This issue reminded me of #2621 ; I can't quite tell how related they are, though.) Let me try to understand the issue a bit better. From what I can see, one issue is that when you do In the particular example, this then means we will make the job a no-op, because the iframe is inactive in that example. This is similar to if you do, for example: // (1)
fulfilledPromiseFromInactiveFrame.then(functionFromInactiveFrame); I don't know if we should try to "fix" this by using the incumbent realm. It seems that the goal is to not run the event loop for inactive frames, and we shouldn't poke holes in that. So, I think (1) should not run, probably? However, let's consider some more cases: // (2)
fulfilledPromiseFromInactiveIframe.then(functionFromActiveFrame); Should Then we come to a case that is basically the OP case: // (3)
fulfilledPromiseFromInactiveFrame.then().then(functionFromActiveFrame); I think (3) should behave the same as (2). So if (2) runs then we need to make (3) run. I am not sure where this leaves us. I will try to think harder, but concrete proposals and more thoughts are also welcome. Maybe one thing we should do is implement the resolution from #1426 (comment) ASAP, with a TODO remaining for undefined [[Handler]] that links to this thread. That will make the discussion a little more concrete, as right now we are all kind of assuming that resolution, but it is not specced very clearly anywhere. |
Right, Payment Request API is an example of such an Web API.
|
Right, the issue is we don't have the [[Handler]] that we can pull a browsing context from.
The latest Chrome implementation uses the handler's browsing context. So, it doesn't run (1)'s functionFromInactiveFrame, while it runs (2)'s functionFromActiveFrame. |
So that is an interesting case. This testcase:
does not log the "inactive" case in Firefox or Chrome. Safari doesn't seem to support unprefixed fullscreen, and webkitRequestFullscreen does not return a promise. In both Firefox and Chrome if I pass That's consistent with what I understand of Gecko's implementation and what @tzik describes for Chrome's implementation in #4443 (comment) and the two seem to match each other... Now maybe the reasons for the execution prevention simply don't apply to the " |
Boris's proposal makes much sense to me, although I'm not an expert in this area. I support the idea to not check the condition at all in case of |
Hmm, I'm reluctant to go that way, to be honest. |
On an example below, should we see "PASS" on
#output
?:https://jsfiddle.net/64eaqtr7/
promise
is the Promise constructor on the inactive (non fully-active) browsing context, andresolve()
returns a resolved promise on it.When
then()
is called, we run PerformPromiseThen, and run EnqueueJob for a PromiseReactionJob to perform the reaction, where [[Handler]] of the job is undefined. At the step 7.1 of EnqueueJob, we check if an appropriate browsing context is fully-active, and if it's not fully-active, we cancel the job.Then, according to a discussion of the appropriate browsing context, we should use [[Handler]]'s context for the check, but it's undefined on the example. If we choose the promise's creation context (the result of GetFunctionRealm of the constructor) as the second most appropriate one, the PromiseReactionJob will be cancelled, and the resulting Promise of
then()
is not resolved nor rejected.The text was updated successfully, but these errors were encountered: