Make a bunch of LayoutDocumentHelpers be safe

The other methods are actually unsafe.
This commit is contained in:
Anthony Ramine 2020-03-31 21:24:07 +02:00
parent e561911066
commit 72c0771299
3 changed files with 27 additions and 21 deletions

View file

@ -345,11 +345,11 @@ impl<'ld> TDocument for ServoLayoutDocument<'ld> {
} }
fn quirks_mode(&self) -> QuirksMode { fn quirks_mode(&self) -> QuirksMode {
unsafe { self.document.quirks_mode() } self.document.quirks_mode()
} }
fn is_html_document(&self) -> bool { fn is_html_document(&self) -> bool {
unsafe { self.document.is_html_document_for_layout() } self.document.is_html_document_for_layout()
} }
} }

View file

@ -352,11 +352,11 @@ impl<'ld> TDocument for ServoLayoutDocument<'ld> {
} }
fn quirks_mode(&self) -> QuirksMode { fn quirks_mode(&self) -> QuirksMode {
unsafe { self.document.quirks_mode() } self.document.quirks_mode()
} }
fn is_html_document(&self) -> bool { fn is_html_document(&self) -> bool {
unsafe { self.document.is_html_document_for_layout() } self.document.is_html_document_for_layout()
} }
} }

View file

@ -2606,21 +2606,21 @@ pub enum DocumentSource {
#[allow(unsafe_code)] #[allow(unsafe_code)]
pub trait LayoutDocumentHelpers<'dom> { pub trait LayoutDocumentHelpers<'dom> {
unsafe fn is_html_document_for_layout(self) -> bool; fn is_html_document_for_layout(self) -> bool;
unsafe fn needs_paint_from_layout(self); unsafe fn needs_paint_from_layout(self);
unsafe fn will_paint(self); unsafe fn will_paint(self);
unsafe fn quirks_mode(self) -> QuirksMode; fn quirks_mode(self) -> QuirksMode;
unsafe fn style_shared_lock(self) -> &'dom StyleSharedRwLock; unsafe fn style_shared_lock(self) -> &'dom StyleSharedRwLock;
unsafe fn shadow_roots(self) -> Vec<LayoutDom<'dom, ShadowRoot>>; fn shadow_roots(self) -> Vec<LayoutDom<'dom, ShadowRoot>>;
unsafe fn shadow_roots_styles_changed(self) -> bool; fn shadow_roots_styles_changed(self) -> bool;
unsafe fn flush_shadow_roots_stylesheets(self); unsafe fn flush_shadow_roots_stylesheets(self);
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
impl<'dom> LayoutDocumentHelpers<'dom> for LayoutDom<'dom, Document> { impl<'dom> LayoutDocumentHelpers<'dom> for LayoutDom<'dom, Document> {
#[inline] #[inline]
unsafe fn is_html_document_for_layout(self) -> bool { fn is_html_document_for_layout(self) -> bool {
(*self.unsafe_get()).is_html_document unsafe { self.unsafe_get().is_html_document }
} }
#[inline] #[inline]
@ -2634,8 +2634,8 @@ impl<'dom> LayoutDocumentHelpers<'dom> for LayoutDom<'dom, Document> {
} }
#[inline] #[inline]
unsafe fn quirks_mode(self) -> QuirksMode { fn quirks_mode(self) -> QuirksMode {
(*self.unsafe_get()).quirks_mode() unsafe { self.unsafe_get().quirks_mode.get() }
} }
#[inline] #[inline]
@ -2644,18 +2644,24 @@ impl<'dom> LayoutDocumentHelpers<'dom> for LayoutDom<'dom, Document> {
} }
#[inline] #[inline]
unsafe fn shadow_roots(self) -> Vec<LayoutDom<'dom, ShadowRoot>> { fn shadow_roots(self) -> Vec<LayoutDom<'dom, ShadowRoot>> {
(*self.unsafe_get()) // FIXME(nox): We should just return a
.shadow_roots // &'dom HashSet<LayoutDom<'dom, ShadowRoot>> here but not until
.borrow_for_layout() // I rework the ToLayout trait as mentioned in
.iter() // LayoutDom::to_layout_slice.
.map(|sr| sr.to_layout()) unsafe {
.collect() self.unsafe_get()
.shadow_roots
.borrow_for_layout()
.iter()
.map(|sr| sr.to_layout())
.collect()
}
} }
#[inline] #[inline]
unsafe fn shadow_roots_styles_changed(self) -> bool { fn shadow_roots_styles_changed(self) -> bool {
(*self.unsafe_get()).shadow_roots_styles_changed() unsafe { self.unsafe_get().shadow_roots_styles_changed.get() }
} }
#[inline] #[inline]