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
|
@ -2934,40 +2934,40 @@ pub enum DocumentSource {
|
|||
#[allow(unsafe_code)]
|
||||
pub trait LayoutDocumentHelpers<'dom> {
|
||||
fn is_html_document_for_layout(self) -> bool;
|
||||
unsafe fn needs_paint_from_layout(self);
|
||||
unsafe fn will_paint(self);
|
||||
fn needs_paint_from_layout(self);
|
||||
fn will_paint(self);
|
||||
fn quirks_mode(self) -> QuirksMode;
|
||||
fn style_shared_lock(self) -> &'dom StyleSharedRwLock;
|
||||
fn shadow_roots(self) -> Vec<LayoutDom<'dom, ShadowRoot>>;
|
||||
fn shadow_roots_styles_changed(self) -> bool;
|
||||
unsafe fn flush_shadow_roots_stylesheets(self);
|
||||
fn flush_shadow_roots_stylesheets(self);
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
impl<'dom> LayoutDocumentHelpers<'dom> for LayoutDom<'dom, Document> {
|
||||
#[inline]
|
||||
fn is_html_document_for_layout(self) -> bool {
|
||||
unsafe { self.unsafe_get().is_html_document }
|
||||
self.unsafe_get().is_html_document
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn needs_paint_from_layout(self) {
|
||||
fn needs_paint_from_layout(self) {
|
||||
(self.unsafe_get()).needs_paint.set(true)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn will_paint(self) {
|
||||
fn will_paint(self) {
|
||||
(self.unsafe_get()).needs_paint.set(false)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn quirks_mode(self) -> QuirksMode {
|
||||
unsafe { self.unsafe_get().quirks_mode.get() }
|
||||
self.unsafe_get().quirks_mode.get()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn style_shared_lock(self) -> &'dom StyleSharedRwLock {
|
||||
unsafe { self.unsafe_get().style_shared_lock() }
|
||||
self.unsafe_get().style_shared_lock()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -2988,11 +2988,11 @@ impl<'dom> LayoutDocumentHelpers<'dom> for LayoutDom<'dom, Document> {
|
|||
|
||||
#[inline]
|
||||
fn shadow_roots_styles_changed(self) -> bool {
|
||||
unsafe { self.unsafe_get().shadow_roots_styles_changed.get() }
|
||||
self.unsafe_get().shadow_roots_styles_changed.get()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn flush_shadow_roots_stylesheets(self) {
|
||||
fn flush_shadow_roots_stylesheets(self) {
|
||||
(*self.unsafe_get()).flush_shadow_roots_stylesheets()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue