-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Fix the entry settings object for promise callbacks #5212
Conversation
We came up with a test where Chrome doesn't correctly thread the backup incumbent settings object for promise callbacks, though not in a way I yet understand... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These semantics (and the ones proposed at #4571 (comment)) seem reasonable to me.
Looks like this PR is about the entry Realm, not the backup incumbent settings object, so I don't see why mismatches there should block it from landing. (I'm not surprised if V8 doesn't handle this in the way Firefox does, and I'm worried it could be a bit complex to correct it.)
Minor: For entry, I'd editorially prefer it if we passed the realm up into HTML from the JS spec, but I'm fine with this landing as is; we can do whatever refactor later.
Thanks @littledan! I agree there are definitely better editorial/layering ways to do this if we can make changes on the 262 side. (That holds for incumbent too, I think: #5213.) |
@bzbarsky ping on this, the tests at web-platform-tests/wpt#21206, and perhaps the discussion in #5213. |
So in terms of what Firefox implements here... For a For a For a There are certainly some interesting questions there. For example, if an async function is awaiting a promise and its window gets unloaded, and then the promise gets resolved, should the async function resume? In Gecko, I think it would, as long as the resolution happened from a window that was not yet unloaded. Per proposed spec it would in all cases, because the "check if we can run script" check gets skipped. What behavior do we want here? |
I think the proposed spec is fairly reasonable, in that it tries to maintain a symmetry between |
Sure, but the thing that |
Hmm, I might be confused then. The spec only skips the check if there's no handler, whereas await has a handler which performs a continuation. Right? |
Ah, interesting. So in terms of specification |
325bff9
to
380763b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming here that arguments, arguments[2], and arguments[0] can never be undefined or equivalent.
Is there an issue somewhere that tracks the further refactoring @littledan mentioned?
Thanks! I double-checked, and yeah, those are never undefined. I think tc39/ecma262#735 is the refactoring. |
I agree that these are never undefined. I think we'd need the further refactoring I alluded to in #5212 (review) to make this cleaner, but let's wait on that until tc39/ecma262#1597 goes through (which is the new tc39/ecma262#735). |
… for promise jobs, a=testonly Automatic update from web-platform-tests Test entry and incumbent settings object for promise jobs Follows whatwg/html#5212 and whatwg/html#5213. -- wpt-commits: bc4ddbbddc566c3602d1af8d73c0225f8335855d wpt-pr: 21206
… for promise jobs, a=testonly Automatic update from web-platform-tests Test entry and incumbent settings object for promise jobs Follows whatwg/html#5212 and whatwg/html#5213. -- wpt-commits: bc4ddbbddc566c3602d1af8d73c0225f8335855d wpt-pr: 21206
… for promise jobs, a=testonly Automatic update from web-platform-tests Test entry and incumbent settings object for promise jobs Follows whatwg/html#5212 and whatwg/html#5213. -- wpt-commits: bc4ddbbddc566c3602d1af8d73c0225f8335855d wpt-pr: 21206 UltraBlame original commit: 3017b5083bf29149178a2c1357796936a5a95065
… for promise jobs, a=testonly Automatic update from web-platform-tests Test entry and incumbent settings object for promise jobs Follows whatwg/html#5212 and whatwg/html#5213. -- wpt-commits: bc4ddbbddc566c3602d1af8d73c0225f8335855d wpt-pr: 21206 UltraBlame original commit: 3017b5083bf29149178a2c1357796936a5a95065
… for promise jobs, a=testonly Automatic update from web-platform-tests Test entry and incumbent settings object for promise jobs Follows whatwg/html#5212 and whatwg/html#5213. -- wpt-commits: bc4ddbbddc566c3602d1af8d73c0225f8335855d wpt-pr: 21206 UltraBlame original commit: 3017b5083bf29149178a2c1357796936a5a95065
When a microtask is executed, we need to use an appropriate, non-detached Context for its execution. Currently with PromiseResolveThenableJobs [1], the Context used is always drawn from the realm of the Promise constructor being used. This may cause non-intuitive behavior, such as in the following case: const DeadPromise = iframe.contentWindow.Promise; const p = DeadPromise.resolve({ then() { return { success: true }; } }); p.then(result => { console.log(result); }); // Some time later, but synchronously... iframe.src = "http://example.com"; // navigate away. // DeadPromise's Context is detached state now. // p never gets resolved, and its reaction handler never gets called. To fix this behavior, when PromiseResolveThenableJob is being queued up, the `then` method of the thenable should be used to determine the context of the resultant microtask. Doing so aligns with Firefox, and also with the latest HTML spec [2][3]. This change is analogous to CL 1465902, which uses the realm of the reaction handlers to determine the Context PromiseReactionJobs run in. [1]: https://tc39.es/ecma262/#sec-promiseresolvethenablejob [2]: https://html.spec.whatwg.org/C/#enqueuejob(queuename,-job,-arguments) [3]: whatwg/html#5212 Bug: v8:10200 Change-Id: I2312788eeea0f9e870c13cf3cb5730a87d15609e Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2071624 Commit-Queue: Timothy Gu <timothygu@chromium.org> Reviewed-by: Toon Verwaest <verwaest@chromium.org> Reviewed-by: Shu-yu Guo <syg@chromium.org> Cr-Commit-Position: refs/heads/master@{#66507}
This reverts commit 9325397. Reason for revert: Causing blink layout failures. See https://ci.chromium.org/p/v8/builders/ci/V8%20Blink%20Linux%20Future/2684 Original change's description: > Use context of then function for PromiseResolveThenableJob > > When a microtask is executed, we need to use an appropriate, > non-detached Context for its execution. Currently with > PromiseResolveThenableJobs [1], the Context used is always drawn from > the realm of the Promise constructor being used. This may cause > non-intuitive behavior, such as in the following case: > > const DeadPromise = iframe.contentWindow.Promise; > const p = DeadPromise.resolve({ > then() { > return { success: true }; > } > }); > p.then(result => { console.log(result); }); > > // Some time later, but synchronously... > iframe.src = "http://example.com"; // navigate away. > // DeadPromise's Context is detached state now. > // p never gets resolved, and its reaction handler never gets called. > > To fix this behavior, when PromiseResolveThenableJob is being queued up, > the `then` method of the thenable should be used to determine the > context of the resultant microtask. Doing so aligns with Firefox, and > also with the latest HTML spec [2][3]. > > This change is analogous to CL 1465902, which uses the realm of the > reaction handlers to determine the Context PromiseReactionJobs run in. > > [1]: https://tc39.es/ecma262/#sec-promiseresolvethenablejob > [2]: https://html.spec.whatwg.org/C/#enqueuejob(queuename,-job,-arguments) > [3]: whatwg/html#5212 > > Bug: v8:10200 > Change-Id: I2312788eeea0f9e870c13cf3cb5730a87d15609e > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2071624 > Commit-Queue: Timothy Gu <timothygu@chromium.org> > Reviewed-by: Toon Verwaest <verwaest@chromium.org> > Reviewed-by: Shu-yu Guo <syg@chromium.org> > Cr-Commit-Position: refs/heads/master@{#66507} TBR=verwaest@chromium.org,timothygu@chromium.org,syg@chromium.org Change-Id: I81737750f8b369567ba586c5a2cfb489836b7e74 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: v8:10200 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2081091 Reviewed-by: Francis McCabe <fgm@chromium.org> Commit-Queue: Francis McCabe <fgm@chromium.org> Cr-Commit-Position: refs/heads/master@{#66510}
This is a reland of 9325397 Original change's description: > Use context of then function for PromiseResolveThenableJob > > When a microtask is executed, we need to use an appropriate, > non-detached Context for its execution. Currently with > PromiseResolveThenableJobs [1], the Context used is always drawn from > the realm of the Promise constructor being used. This may cause > non-intuitive behavior, such as in the following case: > > const DeadPromise = iframe.contentWindow.Promise; > const p = DeadPromise.resolve({ > then() { > return { success: true }; > } > }); > p.then(result => { console.log(result); }); > > // Some time later, but synchronously... > iframe.src = "http://example.com"; // navigate away. > // DeadPromise's Context is detached state now. > // p never gets resolved, and its reaction handler never gets called. > > To fix this behavior, when PromiseResolveThenableJob is being queued up, > the `then` method of the thenable should be used to determine the > context of the resultant microtask. Doing so aligns with Firefox, and > also with the latest HTML spec [2][3]. > > This change is analogous to CL 1465902, which uses the realm of the > reaction handlers to determine the Context PromiseReactionJobs run in. > > [1]: https://tc39.es/ecma262/#sec-promiseresolvethenablejob > [2]: https://html.spec.whatwg.org/C/#enqueuejob(queuename,-job,-arguments) > [3]: whatwg/html#5212 > > Bug: v8:10200 > Change-Id: I2312788eeea0f9e870c13cf3cb5730a87d15609e > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2071624 > Commit-Queue: Timothy Gu <timothygu@chromium.org> > Reviewed-by: Toon Verwaest <verwaest@chromium.org> > Reviewed-by: Shu-yu Guo <syg@chromium.org> > Cr-Commit-Position: refs/heads/master@{#66507} Bug: v8:10200 Change-Id: I5af003a06c60b0c8cd19de47f847a947d40d046c Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2082109 Reviewed-by: Toon Verwaest <verwaest@chromium.org> Commit-Queue: Timothy Gu <timothygu@chromium.org> Cr-Commit-Position: refs/heads/master@{#66586}
Closes #1426.
/cc @syg @littledan @bzbarsky @tschneidereit.
I was kind of waiting for tc39/ecma262#735 to land since that will change things, but I guess we should just fix this now, especially since #4571 needs to add something similar.
(See WHATWG Working Mode: Changes for more details.)
/infrastructure.html ( diff )
/webappapis.html ( diff )