Skip to content
Permalink
Browse files

Auto merge of #25515 - pshaughn:checkpoints, r=nox

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. -->
  • Loading branch information
bors-servo committed Jan 14, 2020
2 parents b52ddc5 + e4a5d8d commit d8a7ae97ca24278ff5bbe95fb403a445cf32e663
@@ -21,6 +21,7 @@ use crate::dom::bindings::error::{
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::settings_stack::is_execution_stack_empty;
use crate::dom::bindings::str::DOMString;
use crate::dom::document::Document;
use crate::dom::domexception::{DOMErrorName, DOMException};
@@ -543,6 +544,14 @@ impl CustomElementDefinition {
}
}

// https://heycam.github.io/webidl/#construct-a-callback-function
// https://html.spec.whatwg.org/multipage/#clean-up-after-running-script
if is_execution_stack_empty() {
window
.upcast::<GlobalScope>()
.perform_a_microtask_checkpoint();
}

rooted!(in(*cx) let element_val = ObjectValue(element.get()));
let element: DomRoot<Element> =
match unsafe { DomRoot::from_jsval(*cx, element_val.handle(), ()) } {
@@ -690,6 +699,15 @@ fn run_upgrade_constructor(
} {
return Err(Error::JSFailed);
}

// https://heycam.github.io/webidl/#construct-a-callback-function
// https://html.spec.whatwg.org/multipage/#clean-up-after-running-script
if is_execution_stack_empty() {
window
.upcast::<GlobalScope>()
.perform_a_microtask_checkpoint();
}

// Step 8.3
let mut same = false;
rooted!(in(*cx) let construct_result_val = ObjectValue(construct_result.get()));
@@ -558,6 +558,19 @@ impl ServoParser {
Err(script) => script,
};

// https://html.spec.whatwg.org/multipage/#parsing-main-incdata
// branch "An end tag whose tag name is "script"
// The spec says to perform the microtask checkpoint before
// setting the insertion mode to Text, but this is not
// possible with the way servo and html5ever currently
// relate to each other, and hopefully it is not observable.
if is_execution_stack_empty() {
self.document
.window()
.upcast::<GlobalScope>()
.perform_a_microtask_checkpoint();
}

let script_nesting_level = self.script_nesting_level.get();

self.script_nesting_level.set(script_nesting_level + 1);

This file was deleted.

0 comments on commit d8a7ae9

Please sign in to comment.
You can’t perform that action at this time.