From 9c8540af5c37c7df2d4c0dff27ca76e36a6e6c02 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 31 Mar 2020 21:59:01 +0200 Subject: [PATCH] Make layout methods accessing rare data be safe They don't do anything fancy so there is no additional unsafety calling them compared to using LayoutDom in the first place, the usual story of all those changes. --- components/layout_thread/dom_wrapper.rs | 18 +++++++---------- components/layout_thread_2020/dom_wrapper.rs | 18 +++++++---------- components/script/dom/element.rs | 21 ++++++++++---------- components/script/dom/node.rs | 20 ++++++++++--------- 4 files changed, 36 insertions(+), 41 deletions(-) diff --git a/components/layout_thread/dom_wrapper.rs b/components/layout_thread/dom_wrapper.rs index 7d3ad1e5c5a..3ad5927c89b 100644 --- a/components/layout_thread/dom_wrapper.rs +++ b/components/layout_thread/dom_wrapper.rs @@ -649,21 +649,17 @@ impl<'le> TElement for ServoLayoutElement<'le> { /// The shadow root this element is a host of. fn shadow_root(&self) -> Option> { - unsafe { - self.element - .get_shadow_root_for_layout() - .map(ServoShadowRoot::from_layout_js) - } + self.element + .get_shadow_root_for_layout() + .map(ServoShadowRoot::from_layout_js) } /// The shadow root which roots the subtree this element is contained in. fn containing_shadow(&self) -> Option> { - unsafe { - self.element - .upcast() - .containing_shadow_root_for_layout() - .map(ServoShadowRoot::from_layout_js) - } + self.element + .upcast() + .containing_shadow_root_for_layout() + .map(ServoShadowRoot::from_layout_js) } fn local_name(&self) -> &LocalName { diff --git a/components/layout_thread_2020/dom_wrapper.rs b/components/layout_thread_2020/dom_wrapper.rs index 4516a6c20d5..673f6d29db9 100644 --- a/components/layout_thread_2020/dom_wrapper.rs +++ b/components/layout_thread_2020/dom_wrapper.rs @@ -656,21 +656,17 @@ impl<'le> TElement for ServoLayoutElement<'le> { /// The shadow root this element is a host of. fn shadow_root(&self) -> Option> { - unsafe { - self.element - .get_shadow_root_for_layout() - .map(ServoShadowRoot::from_layout_js) - } + self.element + .get_shadow_root_for_layout() + .map(ServoShadowRoot::from_layout_js) } /// The shadow root which roots the subtree this element is contained in. fn containing_shadow(&self) -> Option> { - unsafe { - self.element - .upcast() - .containing_shadow_root_for_layout() - .map(ServoShadowRoot::from_layout_js) - } + self.element + .upcast() + .containing_shadow_root_for_layout() + .map(ServoShadowRoot::from_layout_js) } fn local_name(&self) -> &LocalName { diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index cca6ae7edbd..8bbdbf6e7dd 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -583,8 +583,7 @@ pub trait LayoutElementHelpers<'dom> { fn insert_selector_flags(self, flags: ElementSelectorFlags); fn has_selector_flags(self, flags: ElementSelectorFlags) -> bool; /// The shadow root this element is a host of. - #[allow(unsafe_code)] - unsafe fn get_shadow_root_for_layout(self) -> Option>; + fn get_shadow_root_for_layout(self) -> Option>; fn get_attr_for_layout( self, namespace: &Namespace, @@ -1038,14 +1037,16 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> { #[inline] #[allow(unsafe_code)] - unsafe fn get_shadow_root_for_layout(self) -> Option> { - self.unsafe_get() - .rare_data - .borrow_for_layout() - .as_ref()? - .shadow_root - .as_ref() - .map(|sr| sr.to_layout()) + fn get_shadow_root_for_layout(self) -> Option> { + unsafe { + self.unsafe_get() + .rare_data + .borrow_for_layout() + .as_ref()? + .shadow_root + .as_ref() + .map(|sr| sr.to_layout()) + } } #[inline] diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 61e164dbd12..5f8d518b514 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -1314,7 +1314,7 @@ pub trait LayoutNodeHelpers<'dom> { unsafe fn next_sibling_ref(self) -> Option>; unsafe fn owner_doc_for_layout(self) -> LayoutDom<'dom, Document>; - unsafe fn containing_shadow_root_for_layout(self) -> Option>; + fn containing_shadow_root_for_layout(self) -> Option>; unsafe fn is_element_for_layout(self) -> bool; unsafe fn get_flag(self, flag: NodeFlags) -> bool; @@ -1399,14 +1399,16 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> { #[inline] #[allow(unsafe_code)] - unsafe fn containing_shadow_root_for_layout(self) -> Option> { - self.unsafe_get() - .rare_data - .borrow_for_layout() - .as_ref()? - .containing_shadow_root - .as_ref() - .map(|sr| sr.to_layout()) + fn containing_shadow_root_for_layout(self) -> Option> { + unsafe { + self.unsafe_get() + .rare_data + .borrow_for_layout() + .as_ref()? + .containing_shadow_root + .as_ref() + .map(|sr| sr.to_layout()) + } } #[inline]