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
Timing of custom element microtasks isn't the way WPT expects it to be #25016
Comments
Marking this as high-value since tests that expose issues in Servo's timing/ordering of microtasks could plausibly have broader web compatibility impact. The real question is whether this is limited to the custom-elements tasks or whether this is exposing an issue in when Servo runs microtasks at all. |
We're missing a microtask checkpoint that should be coming from inside the parser: when a custom element constructor enqueues a microtask, that microtask should fire BEFORE the start of the next element, but instead in Servo the microtask hangs around in the queue until the checkpoint at the end of the next |
One question I have - given:
Why doesn't the microtask checkpoint occur? |
That one does! The microtask that was supposed to fire earlier and didn't does fire at that point. servo/tests/wpt/web-platform-tests/custom-elements/microtasks-and-constructors.html Lines 37 to 61 in 0131952
We get checkpoints at 43 and 60; we're also supposed to be getting a checkpoint at 45. |
https://html.spec.whatwg.org/multipage/parsing.html#create-an-element-for-the-token says to perform a checkpoint, but it looks like it's saying to do it before the custom element constructor call rather than after, so it doesn't seem to be the one this test wants. |
It probably comes from https://heycam.github.io/webidl/#invoke-a-callback-function which comes from https://html.spec.whatwg.org/multipage/custom-elements.html#invoke-custom-element-reactions which comes from step 9 in that algorithm. |
Either that or https://heycam.github.io/webidl/#construct-a-callback-function from the Upgrade path. |
I am think it's case "An end tag whose name is |
Hmm, good point! |
Adding a checkpoint at line 560 here: servo/components/script/dom/servoparser/mod.rs Lines 556 to 561 in 904fcb4
passes some of the tests, but not all. |
servo/tests/wpt/web-platform-tests/custom-elements/microtasks-and-constructors.html Lines 54 to 70 in 904fcb4
|
I think I've found it; it zig-zags across three specs. https://dom.spec.whatwg.org/#concept-create-element says "the result of constructing C", with a link to the WebIDL spec. https://heycam.github.io/webidl/#construct-a-callback-function includes "Clean up after running script" before returning, with a link to the HTML spec. https://html.spec.whatwg.org/multipage/webappapis.html#clean-up-after-running-script says we run a checkpoint here. That checkpoint would thus call setAttribute while we are still on step 6.1.2 of "create an element", meaning that when we get to step 6.1.5 we have an attribute and need to throw. |
Implementation detail that may help - the codegen for webidl callbacks is based on servo/components/script/dom/bindings/callback.rs Lines 220 to 283 in 904fcb4
|
The "result of constructing C" phrase only appears twice and both times are about custom element definitions, so I don't think this will require a codegen change. |
These actually aren't going through an AutoEntryScript; they're creating a js::jsapi::JSAutoRealm then calling directly into js::rust::wrappers::Construct1. The only other piece of code doing this is PaintWorkletGlobalScope::invoke_a_paint_callback. In the paint worklet's case, the spec says "the result of Construct(paintCtor)" and is linking to ECMAScript, not WebIDL, for the definition of "Construct", so the paint worklet doesn't need to perform a microtask checkpoint on the way out of constructing and is of no concern here. |
Ooh, that's good to know. We should probably add an AutoEntryScript, in that case. |
I don't know whether AutoEntryScript applies here. Adding a checkpoint after exiting the Construct1 call's realm, combined with the checkpoint in the tokenizer, passes every test in microtasks_and_constructors.html. None of this has resolved the failures in perform-a-microtask-before-construction.html. The most obvious difference I can see between the tests is that where microtasks-and-checkpoints.html does everything in the content document of a normally fetched top-level window, perform-a-microtask-before-construction.html sets the srcdoc of an iframe. My first thought is that this one might involve Servo checking the wrong global's custom element registry. |
Totally believable! |
The element is upgraded to custom, so it's the right registry, but the microtask checkpoint on upgrading doesn't fire, and this is almost definitely another timing problem in HTMLIFrameElement::navigate_or_reload_child_browsing_context (#24901, #25098), since that's what assigning to srcdoc actually calls and we already know it's getting things wrong. I will dig a little more to confirm that's what's happening, then if it is I'll do a PR for just the microtasks-and-constructors.html part. |
Opened #25514 for that so I can close this. |
Add microtask checkpoints to script elements and custom elements Servo had a microtask checkpoint at the end of running a script, but there was also supposed to be one at the end of HTML-parsing a script element before Javascript-parsing the script itself, and there were supposed to be checkpoints immediately after the call to a custom element constructor. This adds those, passing all cases of one WPT test file. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #25016 except for the remaining not-really-about-microtasks case #25514 <!-- Either: --> - [X] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Add microtask checkpoints to script elements and custom elements Servo had a microtask checkpoint at the end of running a script, but there was also supposed to be one at the end of HTML-parsing a script element before Javascript-parsing the script itself, and there were supposed to be checkpoints immediately after the call to a custom element constructor. This adds those, passing all cases of one WPT test file. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #25016 except for the remaining not-really-about-microtasks case #25514 <!-- Either: --> - [X] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Add microtask checkpoints to script elements and custom elements Servo had a microtask checkpoint at the end of running a script, but there was also supposed to be one at the end of HTML-parsing a script element before Javascript-parsing the script itself, and there were supposed to be checkpoints immediately after the call to a custom element constructor. This adds those, passing all cases of one WPT test file. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #25016 except for the remaining not-really-about-microtasks case #25514 <!-- Either: --> - [X] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
WPT custom-elements/microtasks-and-constructors.html and perform-microtask-checkpoint-before-construction.html test many specific expectations about when the microtasks of custom elements happen, and Servo violates many of those expectations.
The microtasks-and-constructors test is a little hard to read, since it's broken up into separate script elements to make interesting event orders happen while the document is still being parsed. My reading of it is that multiple script bodies seem to be firing in a row, where the callbacks of custom elements between those scripts are expected be firing in between them. I'm not sure I understand it, though.
The text was updated successfully, but these errors were encountered: