mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
script: Wrapping unsafe code in unsafe
blocks for basic DOM types (#37997)
There is a new default cargo clippy lint, `unsafe_op_in_unsafe_fn`, which requires unsafe code to be wrapped in unsafe blocks, even inside functions marked as unsafe. The lint is disabled as much of our code doesn't fulfill this contract. The thing itself is pretty useful in order to gradually remove unsafety, so this change starts adding `unsafe` blocks so we can eventually enable this lint. Testing: This doesn't change behavior so existings tests should suffice. Fixes: This is part of #35955. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
a13cc1b25a
commit
2366a8bf9e
6 changed files with 51 additions and 30 deletions
|
@ -77,7 +77,8 @@ impl<'dom> ServoLayoutNode<'dom> {
|
|||
///
|
||||
/// 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))
|
||||
let node = unsafe { LayoutDom::from_trusted_node_address(*address) };
|
||||
ServoLayoutNode::from_layout_js(node)
|
||||
}
|
||||
|
||||
pub(super) fn script_type_id(&self) -> NodeTypeId {
|
||||
|
@ -194,10 +195,10 @@ impl<'dom> LayoutNode<'dom> for ServoLayoutNode<'dom> {
|
|||
unsafe fn initialize_style_and_layout_data<RequestedLayoutDataType: LayoutDataTrait>(&self) {
|
||||
let inner = self.get_jsmanaged();
|
||||
if inner.style_data().is_none() {
|
||||
inner.initialize_style_data();
|
||||
unsafe { inner.initialize_style_data() };
|
||||
}
|
||||
if inner.layout_data().is_none() {
|
||||
inner.initialize_layout_data(Box::<RequestedLayoutDataType>::default());
|
||||
unsafe { inner.initialize_layout_data(Box::<RequestedLayoutDataType>::default()) };
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -251,7 +252,8 @@ impl<'dom> ServoThreadSafeLayoutNode<'dom> {
|
|||
/// Get the first child of this node. Important: this is not safe for
|
||||
/// layout to call, so it should *never* be made public.
|
||||
unsafe fn dangerous_first_child(&self) -> Option<Self> {
|
||||
self.get_jsmanaged()
|
||||
let js_managed = unsafe { self.get_jsmanaged() };
|
||||
js_managed
|
||||
.first_child_ref()
|
||||
.map(ServoLayoutNode::from_layout_js)
|
||||
.map(Self::new)
|
||||
|
@ -260,7 +262,8 @@ impl<'dom> ServoThreadSafeLayoutNode<'dom> {
|
|||
/// Get the next sibling of this node. Important: this is not safe for
|
||||
/// layout to call, so it should *never* be made public.
|
||||
unsafe fn dangerous_next_sibling(&self) -> Option<Self> {
|
||||
self.get_jsmanaged()
|
||||
let js_managed = unsafe { self.get_jsmanaged() };
|
||||
js_managed
|
||||
.next_sibling_ref()
|
||||
.map(ServoLayoutNode::from_layout_js)
|
||||
.map(Self::new)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue