diff options
author | Simon Wülker <simon.wuelker@arcor.de> | 2025-02-07 02:05:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-07 01:05:27 +0000 |
commit | 5a5d796988789ce6fe0bc3f0d72bcb80506208ab (patch) | |
tree | 08852e8f24f3c766a2e3f9085b86a0ed26a63622 /components/script/dom/element.rs | |
parent | 9faa7be302e97e33d66853843bd79272bab240d0 (diff) | |
download | servo-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/dom/element.rs')
-rw-r--r-- | components/script/dom/element.rs | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 24e760d510c..66e977bf2b5 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -613,43 +613,6 @@ impl Element { Some(node) => node.is::<Document>(), } } - - pub(crate) fn assigned_slot(&self) -> Option<DomRoot<HTMLSlotElement>> { - let assigned_slot = self - .rare_data - .borrow() - .as_ref()? - .slottable_data - .assigned_slot - .as_ref()? - .as_rooted(); - Some(assigned_slot) - } - - pub(crate) fn set_assigned_slot(&self, assigned_slot: Option<&HTMLSlotElement>) { - self.ensure_rare_data().slottable_data.assigned_slot = assigned_slot.map(Dom::from_ref); - } - - pub(crate) fn manual_slot_assignment(&self) -> Option<DomRoot<HTMLSlotElement>> { - let manually_assigned_slot = self - .rare_data - .borrow() - .as_ref()? - .slottable_data - .manual_slot_assignment - .as_ref()? - .as_rooted(); - Some(manually_assigned_slot) - } - - pub(crate) fn set_manual_slot_assignment( - &self, - manually_assigned_slot: Option<&HTMLSlotElement>, - ) { - self.ensure_rare_data() - .slottable_data - .manual_slot_assignment = manually_assigned_slot.map(Dom::from_ref); - } } /// <https://dom.spec.whatwg.org/#valid-shadow-host-name> @@ -727,7 +690,6 @@ pub(crate) trait LayoutElementHelpers<'dom> { ) -> Option<&'dom AttrValue>; fn get_attr_val_for_layout(self, namespace: &Namespace, name: &LocalName) -> Option<&'dom str>; fn get_attr_vals_for_layout(self, name: &LocalName) -> Vec<&'dom AttrValue>; - fn get_assigned_slot(&self) -> Option<LayoutDom<'dom, HTMLSlotElement>>; } impl LayoutDom<'_, Element> { @@ -1261,20 +1223,6 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> { }) .collect() } - - #[allow(unsafe_code)] - fn get_assigned_slot(&self) -> Option<LayoutDom<'dom, HTMLSlotElement>> { - unsafe { - self.unsafe_get() - .rare_data - .borrow_for_layout() - .as_ref()? - .slottable_data - .assigned_slot - .as_ref() - .map(|slot| slot.to_layout()) - } - } } impl Element { |