Truly independent web browser
LibWeb/CSS: Skip environment moves for elements removed during flight
Andreas Kling39df165b25e4
diff --git a/Libraries/LibWeb/CSS/UpdateStyle.cpp b/Libraries/LibWeb/CSS/UpdateStyle.cppindex ef08f9c68dc..fbf6c0a6280 100644--- a/Libraries/LibWeb/CSS/UpdateStyle.cpp+++ b/Libraries/LibWeb/CSS/UpdateStyle.cpp@@ -386,8 +386,12 @@ static void move_custom_property_environment_below(StyleReactionApplication& appvoid StyleEngineFFI::web_css_republish_moved_environment(StyleReactionApplication* application, u32 style_node, u64 style_record, u64 replaced, void const* new_inheritable_data){auto& style_engine = application->document->style_computer().style_engine();- auto element = application->document->style_computer().element_for_style_node(style_node);- VERIFY(element);+ auto element = application->document->style_computer().element_for_lane_style_node(style_node);+ // A task running beside a flown transaction can remove the element, whose style node the engine's tree still holds+ // until the tree delta applies, and another element can have taken the style node's slot by then. Nothing is left+ // to republish then.+ if (!element)+ return;RefPtr new_inheritable = static_cast<CustomPropertyData const*>(new_inheritable_data);for (auto kind = 0; kind < to_underlying(PseudoElement::KnownPseudoElementCount); ++kind) {auto pseudo_element = static_cast<PseudoElement>(kind);@@ -412,8 +416,10 @@ void StyleEngineFFI::web_css_rebuild_custom_property_environment(StyleReactionAp{auto const& read = application->read;auto& document = *application->document;- auto element = document.style_computer().element_for_style_node(style_node);- VERIFY(element);+ auto element = document.style_computer().element_for_lane_style_node(style_node);+ // As above, the element can be gone, and its descendants with it.+ if (!element)+ return;auto existing_base = custom_property_environment_base(*element, element->custom_property_data({}));VERIFY(existing_base && existing_base->declared_count() > 0);if (existing_base->parent().ptr() == new_parent_inheritable_data)diff --git a/Tests/LibWeb/Crash/CSS/custom-property-change-while-elements-are-removed-beside-style-flight.html b/Tests/LibWeb/Crash/CSS/custom-property-change-while-elements-are-removed-beside-style-flight.htmlnew file mode 100644index 00000000000..559a66488d9--- /dev/null+++ b/Tests/LibWeb/Crash/CSS/custom-property-change-while-elements-are-removed-beside-style-flight.html@@ -0,0 +1,34 @@+<!DOCTYPE html>+<!-- A custom property on the root changes every few milliseconds while tasks remove the elements inheriting it, so+ some are removed while a style transaction moving their environment is in flight. -->+<html class="test-wait">+<body>+<div id="root"></div>+<script>+ const ELEMENT_COUNT = 2000;+ const leaves = [];+ for (let i = 0; i < ELEMENT_COUNT; ++i) {+ const leaf = document.createElement("div");+ root.append(leaf);+ leaves.push(leaf);+ }+ const channel = new MessageChannel();+ channel.port1.onmessage = () => {+ const leaf = leaves.pop();+ if (!leaf)+ return;+ leaf.remove();+ channel.port2.postMessage(0);+ };+ channel.port2.postMessage(0);+ const start = performance.now();+ (function tick(n) {+ document.documentElement.style.setProperty("--a", n + "px");+ if (leaves.length && performance.now() - start < 3000)+ setTimeout(tick, 4, n + 1);+ else+ document.documentElement.classList.remove("test-wait");+ })(0);+</script>+</body>+</html>