From 8f4d78295272ad59d9fa90c294e5f3d6fdc93c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 22 May 2023 10:07:21 +0200 Subject: [PATCH] style: Don't EnsureUniqueInner from the cssRules getter Instead, fix up the various content data structures when the stylesheet is mutated. This makes reading a stylesheet not disable style sharing. Differential Revision: https://phabricator.services.mozilla.com/D115203 --- components/style/gecko/data.rs | 9 ++++++++- components/style/stylesheets/import_rule.rs | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs index 0689aa6c0c4..39f7d7cc8d8 100644 --- a/components/style/gecko/data.rs +++ b/components/style/gecko/data.rs @@ -56,10 +56,17 @@ impl GeckoStyleSheet { /// already holds a strong reference. #[inline] pub unsafe fn from_addrefed(s: *const DomStyleSheet) -> Self { - debug_assert!(!s.is_null()); + assert!(!s.is_null()); GeckoStyleSheet(s) } + /// HACK(emilio): This is so that we can avoid crashing release due to + /// bug 1719963 and can hopefully get a useful report from fuzzers. + #[inline] + pub fn hack_is_null(&self) -> bool { + self.0.is_null() + } + /// Get the raw `StyleSheet` that we're wrapping. pub fn raw(&self) -> &DomStyleSheet { unsafe { &*self.0 } diff --git a/components/style/stylesheets/import_rule.rs b/components/style/stylesheets/import_rule.rs index 396be242024..8f518f29bac 100644 --- a/components/style/stylesheets/import_rule.rs +++ b/components/style/stylesheets/import_rule.rs @@ -56,7 +56,13 @@ impl ImportSheet { /// exists. pub fn as_sheet(&self) -> Option<&crate::gecko::data::GeckoStyleSheet> { match *self { - ImportSheet::Sheet(ref s) => Some(s), + ImportSheet::Sheet(ref s) => { + debug_assert!(!s.hack_is_null()); + if s.hack_is_null() { + return None; + } + Some(s) + }, ImportSheet::Pending(_) => None, } }