mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
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>
This commit is contained in:
parent
9faa7be302
commit
5a5d796988
9 changed files with 77 additions and 167 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue