Skip to content
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

Remove layout blockers before invoking arbitrary content callbacks #34482

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions components/script/dom/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@ impl Node {
child.parent_node.set(None);
self.children_count.set(self.children_count.get() - 1);

// Since all the nodes have been removed at this point, it is safe for
// script/layout to observe the state of the DOM.
self.owner_doc().remove_script_and_layout_blocker();

Self::complete_remove_subtree(child, &context);
}

Expand Down Expand Up @@ -2091,6 +2095,11 @@ impl Node {
}
}
}

// Since all the nodes have been inserted at this point, it is safe for
// script/layout to observe the state of the DOM.
node.owner_doc().remove_script_and_layout_blocker();

if let SuppressObserver::Unsuppressed = suppress_observers {
vtable_for(parent).children_changed(&ChildrenMutation::insert(
previous_sibling.as_deref(),
Expand All @@ -2106,7 +2115,6 @@ impl Node {
};
MutationObserver::queue_a_mutation_record(parent, mutation);
}
node.owner_doc().remove_script_and_layout_blocker();

ScriptThread::note_rendering_opportunity(window_from_node(parent).pipeline_id());
}
Expand Down Expand Up @@ -2140,6 +2148,11 @@ impl Node {
if let Some(node) = node {
Node::insert(node, parent, None, SuppressObserver::Suppressed);
}

// Since all the nodes have been inserted at this point, it is safe for
// script/layout to observe the state of the DOM.
parent.owner_doc().remove_script_and_layout_blocker();

// Step 6.
vtable_for(parent).children_changed(&ChildrenMutation::replace_all(
removed_nodes.r(),
Expand All @@ -2155,7 +2168,6 @@ impl Node {
};
MutationObserver::queue_a_mutation_record(parent, mutation);
}
parent.owner_doc().remove_script_and_layout_blocker();
}

/// <https://dom.spec.whatwg.org/multipage/#string-replace-all>
Expand Down Expand Up @@ -2213,6 +2225,7 @@ impl Node {
// Steps 9-10 are handled in unbind_from_tree.
parent.remove_child(node, cached_index);
// Step 11. transient registered observers

// Step 12.
if let SuppressObserver::Unsuppressed = suppress_observers {
vtable_for(parent).children_changed(&ChildrenMutation::replace(
Expand All @@ -2231,7 +2244,7 @@ impl Node {
};
MutationObserver::queue_a_mutation_record(parent, mutation);
}
parent.owner_doc().remove_script_and_layout_blocker();

ScriptThread::note_rendering_opportunity(window_from_node(parent).pipeline_id());
}

Expand Down
7 changes: 7 additions & 0 deletions tests/wpt/mozilla/meta/MANIFEST.json
Original file line number Diff line number Diff line change
Expand Up @@ -13529,6 +13529,13 @@
{}
]
],
"layout_blocker_operations.html": [
"2df68bf1c13179688708c97eab19361608b0de82",
[
null,
{}
]
],
"lenient_this.html": [
"960c74613f3c2809bb1f2ee6121bf14f28267051",
[
Expand Down
34 changes: 34 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/layout_blocker_operations.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="foo"></div>

<script>
function verifyLayoutAllowed(t) {
t.step(() => {
assert_equals(getComputedStyle(document.querySelector('#foo')).display, "block");
t.done();
})
}

var insertionTest;
async_test(function(t) {
insertionTest = t;
let script = document.createElement('script');
document.body.appendChild(script);
script.appendChild(document.createTextNode("verifyLayoutAllowed(insertionTest)"));
}, "Insertion");

var replacementTest;
async_test(function(t) {
replacementTest = t;
let script = document.createElement('script');
document.body.appendChild(script);
script.innerHTML = "verifyLayoutAllowed(replacementTest)";
}, "Replace");
</script>
</body>
</html>
Loading