mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
script: Reduce the use of unsafe
in LayoutDom (#31979)
Remove the use of unsafe code in the layout wrappers of the DOM. The main change here is that `unsafe_get()` no longer needs to be an unsafe method, which allows us to transitively remove or reduce unsafe blocks from callers. The function itself is not renamed, because it's still a bit dangerous to start removing the layers of abstraction from actual DOM nodes. In addition `init_style_and_opaque_layout_data` can be merged into `initialize_data`, which removes one more unsafe method. Finally, a "Safety" section is added to some unsafe methods.
This commit is contained in:
parent
8aaff61334
commit
18b37e676b
19 changed files with 89 additions and 86 deletions
|
@ -207,21 +207,17 @@ impl<'dom, LayoutDataType: LayoutDataTrait> LayoutNode<'dom>
|
|||
}
|
||||
|
||||
unsafe fn initialize_data(&self) {
|
||||
if self.get_style_and_opaque_layout_data().is_none() {
|
||||
let opaque = StyleAndOpaqueLayoutData::new(
|
||||
StyleData::default(),
|
||||
AtomicRefCell::new(LayoutDataType::default()),
|
||||
);
|
||||
self.init_style_and_opaque_layout_data(opaque);
|
||||
};
|
||||
}
|
||||
if self.get_style_and_opaque_layout_data().is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
unsafe fn init_style_and_opaque_layout_data(&self, data: Box<StyleAndOpaqueLayoutData>) {
|
||||
self.get_jsmanaged().init_style_and_opaque_layout_data(data);
|
||||
}
|
||||
let opaque = StyleAndOpaqueLayoutData::new(
|
||||
StyleData::default(),
|
||||
AtomicRefCell::new(LayoutDataType::default()),
|
||||
);
|
||||
|
||||
unsafe fn take_style_and_opaque_layout_data(&self) -> Box<StyleAndOpaqueLayoutData> {
|
||||
self.get_jsmanaged().take_style_and_opaque_layout_data()
|
||||
self.get_jsmanaged()
|
||||
.init_style_and_opaque_layout_data(opaque);
|
||||
}
|
||||
|
||||
fn is_connected(&self) -> bool {
|
||||
|
@ -402,7 +398,7 @@ impl<'dom, LayoutDataType: LayoutDataTrait> ThreadSafeLayoutNode<'dom>
|
|||
}
|
||||
}
|
||||
|
||||
unsafe fn unsafe_get(self) -> Self::ConcreteNode {
|
||||
fn unsafe_get(self) -> Self::ConcreteNode {
|
||||
self.node
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue