From 15db31769cb0172be610fe2d731533c30c40fa76 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 27 Apr 2020 10:59:38 +0200 Subject: [PATCH] Make DomRefCell not mutate the borrow flag non-atomically --- components/script/dom/bindings/cell.rs | 9 +++++---- components/script/dom/shadowroot.rs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/components/script/dom/bindings/cell.rs b/components/script/dom/bindings/cell.rs index e3f5ad71bee2..5807138c948e 100644 --- a/components/script/dom/bindings/cell.rs +++ b/components/script/dom/bindings/cell.rs @@ -45,11 +45,12 @@ impl DomRefCell { &mut *self.value.as_ptr() } - /// Version of the above that we use during restyle while the script thread - /// is blocked. - pub fn borrow_mut_for_layout(&self) -> RefMut { + /// Mutably borrow a cell for layout. Ideally this would use + /// `RefCell::try_borrow_mut_unguarded` but that doesn't exist yet. + #[allow(unsafe_code)] + pub unsafe fn borrow_mut_for_layout(&self) -> &mut T { debug_assert!(thread_state::get().is_layout()); - self.value.borrow_mut() + &mut *self.value.as_ptr() } } diff --git a/components/script/dom/shadowroot.rs b/components/script/dom/shadowroot.rs index f1c0567a3991..c70c13d8cefd 100644 --- a/components/script/dom/shadowroot.rs +++ b/components/script/dom/shadowroot.rs @@ -281,7 +281,7 @@ impl<'dom> LayoutShadowRootHelpers<'dom> for LayoutDom<'dom, ShadowRoot> { quirks_mode: QuirksMode, guard: &SharedRwLockReadGuard, ) { - let mut author_styles = (*self.unsafe_get()).author_styles.borrow_mut_for_layout(); + let author_styles = self.unsafe_get().author_styles.borrow_mut_for_layout(); if author_styles.stylesheets.dirty() { author_styles.flush::(device, quirks_mode, guard); }