You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Timing of custom element microtasks isn't the way WPT expects it to be #25016
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.
changed the title [-]Timing of custom element microtasks[/-][+]Timing of custom element microtasks isn't the way WPT expects it to be[/+]on Dec 2, 2019
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 <script> block. The simplest case for this is named "Microtasks evaluate immediately when the stack is empty inside the parser.", which gives some clue where to look.
assert_false(xBad.hasAttribute("attribute"),"The attribute must not be present");
assert_true(xBadinstanceofHTMLUnknownElement,"The element must be a HTMLUnknownElement");
I don't yet understand why this constructor is supposed to fail and leave us with an HTMLUnknownElement, but Firefox and Chrome agree that it does; it fails in Servo by making an HTMLElement with an attribute.
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.
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.
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.
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.
Activity
[-]Timing of custom element microtasks[/-][+]Timing of custom element microtasks isn't the way WPT expects it to be[/+]jdm commentedon Dec 2, 2019
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.
pshaughn commentedon Jan 13, 2020
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
<script>block. The simplest case for this is named "Microtasks evaluate immediately when the stack is empty inside the parser.", which gives some clue where to look.jdm commentedon Jan 13, 2020
One question I have - given:
servo/components/script/dom/htmlscriptelement.rs
Line 792 in 0131952
servo/components/script/dom/globalscope.rs
Line 1712 in 0131952
servo/components/script/dom/bindings/settings_stack.rs
Lines 78 to 80 in 0131952
Why doesn't the microtask checkpoint occur?
pshaughn commentedon Jan 13, 2020
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.
pshaughn commentedon Jan 13, 2020
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.
jdm commentedon Jan 13, 2020
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.
jdm commentedon Jan 13, 2020
Either that or https://heycam.github.io/webidl/#construct-a-callback-function from the Upgrade path.
pshaughn commentedon Jan 13, 2020
I am think it's case "An end tag whose name is
<script>" in https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-incdata actually. It looks like the INSTANT the HTML parser sees a</script>, before actually javascript-parsing the script itself, we are supposed to get a checkpoint.jdm commentedon Jan 13, 2020
Hmm, good point!
pshaughn commentedon Jan 13, 2020
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.
pshaughn commentedon Jan 13, 2020
servo/tests/wpt/web-platform-tests/custom-elements/microtasks-and-constructors.html
Lines 54 to 70 in 904fcb4
pshaughn commentedon Jan 13, 2020
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.
jdm commentedon Jan 13, 2020
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
pshaughn commentedon Jan 13, 2020
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.
pshaughn commentedon Jan 13, 2020
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.
jdm commentedon Jan 13, 2020
Ooh, that's good to know. We should probably add an AutoEntryScript, in that case.
pshaughn commentedon Jan 13, 2020
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.
jdm commentedon Jan 13, 2020
Totally believable!
pshaughn commentedon Jan 13, 2020
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.
pshaughn commentedon Jan 13, 2020
Opened #25514 for that so I can close this.
Auto merge of #25515 - pshaughn:checkpoints, r=nox
Auto merge of #25515 - pshaughn:checkpoints, r=<try>
Auto merge of #25515 - pshaughn:checkpoints, r=jdm
Auto merge of #25515 - pshaughn:checkpoints, r=jdm