mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
Make a bunch of LayoutNodeHelpers be safe
This commit is contained in:
parent
f014da9565
commit
68d5cfffd5
3 changed files with 33 additions and 36 deletions
|
@ -135,7 +135,7 @@ impl<'ln> ServoLayoutNode<'ln> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn script_type_id(&self) -> NodeTypeId {
|
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<Self> {
|
fn first_child(&self) -> Option<Self> {
|
||||||
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<Self> {
|
fn last_child(&self) -> Option<Self> {
|
||||||
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<Self> {
|
fn prev_sibling(&self) -> Option<Self> {
|
||||||
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<Self> {
|
fn next_sibling(&self) -> Option<Self> {
|
||||||
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 {
|
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<ServoLayoutElement<'ln>> {
|
fn traversal_parent(&self) -> Option<ServoLayoutElement<'ln>> {
|
||||||
|
|
|
@ -142,7 +142,7 @@ impl<'ln> ServoLayoutNode<'ln> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn script_type_id(&self) -> NodeTypeId {
|
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<Self> {
|
fn first_child(&self) -> Option<Self> {
|
||||||
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<Self> {
|
fn last_child(&self) -> Option<Self> {
|
||||||
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<Self> {
|
fn prev_sibling(&self) -> Option<Self> {
|
||||||
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<Self> {
|
fn next_sibling(&self) -> Option<Self> {
|
||||||
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 {
|
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<ServoLayoutElement<'ln>> {
|
fn traversal_parent(&self) -> Option<ServoLayoutElement<'ln>> {
|
||||||
|
|
|
@ -1305,22 +1305,22 @@ pub unsafe fn from_untrusted_node_address(
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub trait LayoutNodeHelpers<'dom> {
|
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<LayoutDom<'dom, Node>>;
|
unsafe fn composed_parent_node_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
||||||
unsafe fn first_child_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
fn first_child_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
||||||
unsafe fn last_child_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
fn last_child_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
||||||
unsafe fn prev_sibling_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
fn prev_sibling_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
||||||
unsafe fn next_sibling_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
fn next_sibling_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
||||||
|
|
||||||
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<LayoutDom<'dom, ShadowRoot>>;
|
fn containing_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>>;
|
||||||
|
|
||||||
fn is_element_for_layout(self) -> bool;
|
fn is_element_for_layout(self) -> bool;
|
||||||
unsafe fn get_flag(self, flag: NodeFlags) -> bool;
|
unsafe fn get_flag(self, flag: NodeFlags) -> bool;
|
||||||
unsafe fn set_flag(self, flag: NodeFlags, value: 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<OpaqueStyleAndLayoutData>;
|
unsafe fn get_style_and_layout_data(self) -> Option<OpaqueStyleAndLayoutData>;
|
||||||
unsafe fn init_style_and_layout_data(self, _: OpaqueStyleAndLayoutData);
|
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> {
|
impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn type_id_for_layout(self) -> NodeTypeId {
|
fn type_id_for_layout(self) -> NodeTypeId {
|
||||||
(*self.unsafe_get()).type_id()
|
unsafe { self.unsafe_get().type_id() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1365,35 +1365,32 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn first_child_ref(self) -> Option<LayoutDom<'dom, Node>> {
|
fn first_child_ref(self) -> Option<LayoutDom<'dom, Node>> {
|
||||||
(*self.unsafe_get()).first_child.get_inner_as_layout()
|
unsafe { self.unsafe_get().first_child.get_inner_as_layout() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn last_child_ref(self) -> Option<LayoutDom<'dom, Node>> {
|
fn last_child_ref(self) -> Option<LayoutDom<'dom, Node>> {
|
||||||
(*self.unsafe_get()).last_child.get_inner_as_layout()
|
unsafe { self.unsafe_get().last_child.get_inner_as_layout() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn prev_sibling_ref(self) -> Option<LayoutDom<'dom, Node>> {
|
fn prev_sibling_ref(self) -> Option<LayoutDom<'dom, Node>> {
|
||||||
(*self.unsafe_get()).prev_sibling.get_inner_as_layout()
|
unsafe { self.unsafe_get().prev_sibling.get_inner_as_layout() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn next_sibling_ref(self) -> Option<LayoutDom<'dom, Node>> {
|
fn next_sibling_ref(self) -> Option<LayoutDom<'dom, Node>> {
|
||||||
(*self.unsafe_get()).next_sibling.get_inner_as_layout()
|
unsafe { self.unsafe_get().next_sibling.get_inner_as_layout() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn owner_doc_for_layout(self) -> LayoutDom<'dom, Document> {
|
fn owner_doc_for_layout(self) -> LayoutDom<'dom, Document> {
|
||||||
(*self.unsafe_get())
|
unsafe { self.unsafe_get().owner_doc.get_inner_as_layout().unwrap() }
|
||||||
.owner_doc
|
|
||||||
.get_inner_as_layout()
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1433,8 +1430,8 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn children_count(self) -> u32 {
|
fn children_count(self) -> u32 {
|
||||||
(*self.unsafe_get()).children_count.get()
|
unsafe { self.unsafe_get().children_count.get() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue