From 68d5cfffd500877333f88b98682520b5f680fcd1 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 31 Mar 2020 22:13:06 +0200 Subject: [PATCH] Make a bunch of LayoutNodeHelpers be safe --- components/layout_thread/dom_wrapper.rs | 12 +++--- components/layout_thread_2020/dom_wrapper.rs | 12 +++--- components/script/dom/node.rs | 45 +++++++++----------- 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/components/layout_thread/dom_wrapper.rs b/components/layout_thread/dom_wrapper.rs index 4e6f187d5d5..d6b33c40c99 100644 --- a/components/layout_thread/dom_wrapper.rs +++ b/components/layout_thread/dom_wrapper.rs @@ -135,7 +135,7 @@ impl<'ln> ServoLayoutNode<'ln> { } fn script_type_id(&self) -> NodeTypeId { - unsafe { self.node.type_id_for_layout() } + self.node.type_id_for_layout() } } @@ -211,23 +211,23 @@ impl<'ln> TNode for ServoLayoutNode<'ln> { } fn first_child(&self) -> Option { - unsafe { self.node.first_child_ref().map(Self::from_layout_js) } + self.node.first_child_ref().map(Self::from_layout_js) } fn last_child(&self) -> Option { - unsafe { self.node.last_child_ref().map(Self::from_layout_js) } + self.node.last_child_ref().map(Self::from_layout_js) } fn prev_sibling(&self) -> Option { - unsafe { self.node.prev_sibling_ref().map(Self::from_layout_js) } + self.node.prev_sibling_ref().map(Self::from_layout_js) } fn next_sibling(&self) -> Option { - unsafe { self.node.next_sibling_ref().map(Self::from_layout_js) } + self.node.next_sibling_ref().map(Self::from_layout_js) } fn owner_doc(&self) -> Self::ConcreteDocument { - ServoLayoutDocument::from_layout_js(unsafe { self.node.owner_doc_for_layout() }) + ServoLayoutDocument::from_layout_js(self.node.owner_doc_for_layout()) } fn traversal_parent(&self) -> Option> { diff --git a/components/layout_thread_2020/dom_wrapper.rs b/components/layout_thread_2020/dom_wrapper.rs index 15616315542..436a88b1d9e 100644 --- a/components/layout_thread_2020/dom_wrapper.rs +++ b/components/layout_thread_2020/dom_wrapper.rs @@ -142,7 +142,7 @@ impl<'ln> ServoLayoutNode<'ln> { } fn script_type_id(&self) -> NodeTypeId { - unsafe { self.node.type_id_for_layout() } + self.node.type_id_for_layout() } } @@ -218,23 +218,23 @@ impl<'ln> TNode for ServoLayoutNode<'ln> { } fn first_child(&self) -> Option { - unsafe { self.node.first_child_ref().map(Self::from_layout_js) } + self.node.first_child_ref().map(Self::from_layout_js) } fn last_child(&self) -> Option { - unsafe { self.node.last_child_ref().map(Self::from_layout_js) } + self.node.last_child_ref().map(Self::from_layout_js) } fn prev_sibling(&self) -> Option { - unsafe { self.node.prev_sibling_ref().map(Self::from_layout_js) } + self.node.prev_sibling_ref().map(Self::from_layout_js) } fn next_sibling(&self) -> Option { - unsafe { self.node.next_sibling_ref().map(Self::from_layout_js) } + self.node.next_sibling_ref().map(Self::from_layout_js) } fn owner_doc(&self) -> Self::ConcreteDocument { - ServoLayoutDocument::from_layout_js(unsafe { self.node.owner_doc_for_layout() }) + ServoLayoutDocument::from_layout_js(self.node.owner_doc_for_layout()) } fn traversal_parent(&self) -> Option> { diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index eaceeb9ea2c..a42f2371d3d 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -1305,22 +1305,22 @@ pub unsafe fn from_untrusted_node_address( #[allow(unsafe_code)] pub trait LayoutNodeHelpers<'dom> { - unsafe fn type_id_for_layout(self) -> NodeTypeId; + fn type_id_for_layout(self) -> NodeTypeId; unsafe fn composed_parent_node_ref(self) -> Option>; - unsafe fn first_child_ref(self) -> Option>; - unsafe fn last_child_ref(self) -> Option>; - unsafe fn prev_sibling_ref(self) -> Option>; - unsafe fn next_sibling_ref(self) -> Option>; + fn first_child_ref(self) -> Option>; + fn last_child_ref(self) -> Option>; + fn prev_sibling_ref(self) -> Option>; + fn next_sibling_ref(self) -> Option>; - unsafe fn owner_doc_for_layout(self) -> LayoutDom<'dom, Document>; + fn owner_doc_for_layout(self) -> LayoutDom<'dom, Document>; fn containing_shadow_root_for_layout(self) -> Option>; fn is_element_for_layout(self) -> bool; unsafe fn get_flag(self, flag: NodeFlags) -> bool; unsafe fn set_flag(self, flag: NodeFlags, value: bool); - unsafe fn children_count(self) -> u32; + fn children_count(self) -> u32; unsafe fn get_style_and_layout_data(self) -> Option; unsafe fn init_style_and_layout_data(self, _: OpaqueStyleAndLayoutData); @@ -1342,8 +1342,8 @@ pub trait LayoutNodeHelpers<'dom> { impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> { #[inline] #[allow(unsafe_code)] - unsafe fn type_id_for_layout(self) -> NodeTypeId { - (*self.unsafe_get()).type_id() + fn type_id_for_layout(self) -> NodeTypeId { + unsafe { self.unsafe_get().type_id() } } #[inline] @@ -1365,35 +1365,32 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> { #[inline] #[allow(unsafe_code)] - unsafe fn first_child_ref(self) -> Option> { - (*self.unsafe_get()).first_child.get_inner_as_layout() + fn first_child_ref(self) -> Option> { + unsafe { self.unsafe_get().first_child.get_inner_as_layout() } } #[inline] #[allow(unsafe_code)] - unsafe fn last_child_ref(self) -> Option> { - (*self.unsafe_get()).last_child.get_inner_as_layout() + fn last_child_ref(self) -> Option> { + unsafe { self.unsafe_get().last_child.get_inner_as_layout() } } #[inline] #[allow(unsafe_code)] - unsafe fn prev_sibling_ref(self) -> Option> { - (*self.unsafe_get()).prev_sibling.get_inner_as_layout() + fn prev_sibling_ref(self) -> Option> { + unsafe { self.unsafe_get().prev_sibling.get_inner_as_layout() } } #[inline] #[allow(unsafe_code)] - unsafe fn next_sibling_ref(self) -> Option> { - (*self.unsafe_get()).next_sibling.get_inner_as_layout() + fn next_sibling_ref(self) -> Option> { + unsafe { self.unsafe_get().next_sibling.get_inner_as_layout() } } #[inline] #[allow(unsafe_code)] - unsafe fn owner_doc_for_layout(self) -> LayoutDom<'dom, Document> { - (*self.unsafe_get()) - .owner_doc - .get_inner_as_layout() - .unwrap() + fn owner_doc_for_layout(self) -> LayoutDom<'dom, Document> { + unsafe { self.unsafe_get().owner_doc.get_inner_as_layout().unwrap() } } #[inline] @@ -1433,8 +1430,8 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> { #[inline] #[allow(unsafe_code)] - unsafe fn children_count(self) -> u32 { - (*self.unsafe_get()).children_count.get() + fn children_count(self) -> u32 { + unsafe { self.unsafe_get().children_count.get() } } #[inline]