mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
clippy: Add safety documentation and clean up unsafe methods (#33748)
This change: 1. Adds safety documentation where it was missing. 2. Limits the scope of unsafe code in some cases to where it is actually unsafe. 3. Converts some free functions to associated functions and methods, thereby making them more likely to be called safely. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
ed959d7a1a
commit
30abb99287
14 changed files with 409 additions and 347 deletions
|
@ -89,12 +89,24 @@ impl<'dom> ServoLayoutElement<'dom> {
|
|||
self.as_node().style_data()
|
||||
}
|
||||
|
||||
/// Unset the snapshot flags on the underlying DOM object for this element.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// This function accesses and modifies the underlying DOM object and should
|
||||
/// not be used by more than a single thread at once.
|
||||
pub unsafe fn unset_snapshot_flags(&self) {
|
||||
self.as_node()
|
||||
.node
|
||||
.set_flag(NodeFlags::HAS_SNAPSHOT | NodeFlags::HANDLED_SNAPSHOT, false);
|
||||
}
|
||||
|
||||
/// Unset the snapshot flags on the underlying DOM object for this element.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// This function accesses and modifies the underlying DOM object and should
|
||||
/// not be used by more than a single thread at once.
|
||||
pub unsafe fn set_has_snapshot(&self) {
|
||||
self.as_node().node.set_flag(NodeFlags::HAS_SNAPSHOT, true);
|
||||
}
|
||||
|
|
|
@ -76,6 +76,11 @@ impl<'dom> ServoLayoutNode<'dom> {
|
|||
ServoLayoutNode { node: n }
|
||||
}
|
||||
|
||||
/// Create a new [`ServoLayoutNode`] for this given [`TrustedNodeAddress`].
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The address pointed to by `address` should point to a valid node in memory.
|
||||
pub unsafe fn new(address: &TrustedNodeAddress) -> Self {
|
||||
ServoLayoutNode::from_layout_js(LayoutDom::from_trusted_node_address(*address))
|
||||
}
|
||||
|
|
|
@ -48,6 +48,12 @@ impl<'dom> ServoShadowRoot<'dom> {
|
|||
ServoShadowRoot { shadow_root }
|
||||
}
|
||||
|
||||
/// Flush the stylesheets for the underlying shadow root.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// This modifies a DOM object, so should care should be taken that only one
|
||||
/// thread has a reference to this object.
|
||||
pub unsafe fn flush_stylesheets(
|
||||
&self,
|
||||
stylist: &mut Stylist,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue