aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/layout_dom
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2024-04-03 10:41:19 +0200
committerGitHub <noreply@github.com>2024-04-03 08:41:19 +0000
commit18b37e676bcd50f754cd189444080fc547c9d48a (patch)
treeca2e235d13b6f9b19cff9172810b0c6f08265f3b /components/script/layout_dom
parent8aaff613342568c13e9141758b770788694d2f84 (diff)
downloadservo-18b37e676bcd50f754cd189444080fc547c9d48a.tar.gz
servo-18b37e676bcd50f754cd189444080fc547c9d48a.zip
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.
Diffstat (limited to 'components/script/layout_dom')
-rw-r--r--components/script/layout_dom/document.rs4
-rw-r--r--components/script/layout_dom/element.rs8
-rw-r--r--components/script/layout_dom/node.rs24
3 files changed, 18 insertions, 18 deletions
diff --git a/components/script/layout_dom/document.rs b/components/script/layout_dom/document.rs
index f068600a005..f55c198ef48 100644
--- a/components/script/layout_dom/document.rs
+++ b/components/script/layout_dom/document.rs
@@ -64,11 +64,11 @@ impl<'ld, LayoutDataType: LayoutDataTrait> ServoLayoutDocument<'ld, LayoutDataTy
}
pub fn needs_paint_from_layout(&self) {
- unsafe { self.document.needs_paint_from_layout() }
+ self.document.needs_paint_from_layout()
}
pub fn will_paint(&self) {
- unsafe { self.document.will_paint() }
+ self.document.will_paint()
}
pub fn style_shared_lock(&self) -> &StyleSharedRwLock {
diff --git a/components/script/layout_dom/element.rs b/components/script/layout_dom/element.rs
index 433369bbb89..48a0b86bb6a 100644
--- a/components/script/layout_dom/element.rs
+++ b/components/script/layout_dom/element.rs
@@ -323,7 +323,11 @@ impl<'dom, LayoutDataType: LayoutDataTrait> style::dom::TElement
unsafe fn clear_data(&self) {
if self.get_style_and_opaque_layout_data().is_some() {
- drop(self.as_node().take_style_and_opaque_layout_data());
+ drop(
+ self.as_node()
+ .get_jsmanaged()
+ .take_style_and_opaque_layout_data(),
+ );
}
}
@@ -758,7 +762,7 @@ impl<'dom, LayoutDataType: LayoutDataTrait> ThreadSafeLayoutElement<'dom>
self.as_node().type_id()
}
- unsafe fn unsafe_get(self) -> ServoLayoutElement<'dom, LayoutDataType> {
+ fn unsafe_get(self) -> ServoLayoutElement<'dom, LayoutDataType> {
self.element
}
diff --git a/components/script/layout_dom/node.rs b/components/script/layout_dom/node.rs
index c331f4aa5e3..cd5b1780cfa 100644
--- a/components/script/layout_dom/node.rs
+++ b/components/script/layout_dom/node.rs
@@ -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
}