Make LayoutNodeHelpers::composed_parent_node_ref be safe

For clarity, I introduce <LayoutDom<Element>>::parent_node_ref to contain
the remaining unsafety bits out of composed_parent_node_ref which is more
complex than just a field access.
This commit is contained in:
Anthony Ramine 2020-03-31 22:32:35 +02:00
parent f712b0bcf8
commit fc07a5147c
4 changed files with 44 additions and 50 deletions

View file

@ -203,11 +203,9 @@ impl<'ln> TNode for ServoLayoutNode<'ln> {
type ConcreteShadowRoot = ServoShadowRoot<'ln>;
fn parent_node(&self) -> Option<Self> {
unsafe {
self.node
.composed_parent_node_ref()
.map(Self::from_layout_js)
}
self.node
.composed_parent_node_ref()
.map(Self::from_layout_js)
}
fn first_child(&self) -> Option<Self> {
@ -745,12 +743,10 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
}
fn parent_element(&self) -> Option<ServoLayoutElement<'le>> {
unsafe {
self.element
.upcast()
.composed_parent_node_ref()
.and_then(as_element)
}
self.element
.upcast()
.composed_parent_node_ref()
.and_then(as_element)
}
fn parent_node_is_shadow_root(&self) -> bool {