aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/layout_dom/element.rs
diff options
context:
space:
mode:
authorSimon Wülker <simon.wuelker@arcor.de>2025-02-07 02:05:27 +0100
committerGitHub <noreply@github.com>2025-02-07 01:05:27 +0000
commit5a5d796988789ce6fe0bc3f0d72bcb80506208ab (patch)
tree08852e8f24f3c766a2e3f9085b86a0ed26a63622 /components/script/layout_dom/element.rs
parent9faa7be302e97e33d66853843bd79272bab240d0 (diff)
downloadservo-5a5d796988789ce6fe0bc3f0d72bcb80506208ab.tar.gz
servo-5a5d796988789ce6fe0bc3f0d72bcb80506208ab.zip
Implement ServoLayoutNode::traversal_parent (#35338)
This fixes common crash related to slottables, currently present on wpt.fyi. Previously, the traversal parent of `Text` nodes was incorrectly assumed to always be the parent or shadow host. That caused crashes inside stylo's bloom filter. Now the traversal parent is the slot that the node is assigned to, if any, and the parent/shadow host otherwise. The slottable data for Text/Element nodes is now stored in NodeRareData. This is very cheap, because NodeRareData will already be instantiated for assigned slottables anyways, because the containing_shadow_root field will be set (since assigned slottables are always in a shadow tree). This change is necessary because we need to hand out references to the assigned slot to stylo and that is not possible to do (without unsafe code) if we need to downcast the node first. As a side effect, this reduces the size of `Text` from 256 to 232 bytes, because the slottable data is no longer stored there. Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Diffstat (limited to 'components/script/layout_dom/element.rs')
-rw-r--r--components/script/layout_dom/element.rs13
1 files changed, 2 insertions, 11 deletions
diff --git a/components/script/layout_dom/element.rs b/components/script/layout_dom/element.rs
index 05271793184..cdca829dca4 100644
--- a/components/script/layout_dom/element.rs
+++ b/components/script/layout_dom/element.rs
@@ -140,11 +140,6 @@ impl<'dom> ServoLayoutElement<'dom> {
Some(node) => matches!(node.script_type_id(), NodeTypeId::Document(_)),
}
}
-
- fn assigned_slot(&self) -> Option<Self> {
- let slot = self.element.get_assigned_slot()?;
- Some(Self::from_layout_js(slot.upcast()))
- }
}
pub enum DOMDescendantIterator<E>
@@ -204,11 +199,7 @@ impl<'dom> style::dom::TElement for ServoLayoutElement<'dom> {
}
fn traversal_parent(&self) -> Option<Self> {
- if let Some(assigned_slot) = self.assigned_slot() {
- Some(assigned_slot)
- } else {
- self.as_node().traversal_parent()
- }
+ self.as_node().traversal_parent()
}
fn is_html_element(&self) -> bool {
@@ -752,7 +743,7 @@ impl<'dom> ::selectors::Element for ServoLayoutElement<'dom> {
#[allow(unsafe_code)]
fn assigned_slot(&self) -> Option<Self> {
- self.assigned_slot()
+ self.as_node().assigned_slot()
}
fn is_html_element_in_html_document(&self) -> bool {