Auto merge of #29873 - Loirooriol:import-assert, r=mrobinson

Avoid assert failure when using @import

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #29872

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because they only affect debug builds, and tests run in release builds.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2023-06-14 18:42:59 +02:00 committed by GitHub
commit fa266abd29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View file

@ -114,7 +114,7 @@ impl HTMLMetaElement {
let shared_lock = document.style_shared_lock(); let shared_lock = document.style_shared_lock();
let rule = CssRule::Viewport(Arc::new(shared_lock.wrap(translated_rule))); let rule = CssRule::Viewport(Arc::new(shared_lock.wrap(translated_rule)));
let sheet = Arc::new(Stylesheet { let sheet = Arc::new(Stylesheet {
contents: StylesheetContents::from_shared_data( contents: StylesheetContents::from_data(
CssRules::new(vec![rule], shared_lock), CssRules::new(vec![rule], shared_lock),
Origin::Author, Origin::Author,
window_from_node(self).get_url(), window_from_node(self).get_url(),

View file

@ -361,7 +361,7 @@ impl<'a> StyleStylesheetLoader for StylesheetLoader<'a> {
layer: Option<ImportLayer>, layer: Option<ImportLayer>,
) -> Arc<Locked<ImportRule>> { ) -> Arc<Locked<ImportRule>> {
let sheet = Arc::new(Stylesheet { let sheet = Arc::new(Stylesheet {
contents: StylesheetContents::from_shared_data( contents: StylesheetContents::from_data(
CssRules::new(Vec::new(), lock), CssRules::new(Vec::new(), lock),
context.stylesheet_origin, context.stylesheet_origin,
context.url_data.clone(), context.url_data.clone(),

View file

@ -125,13 +125,12 @@ impl StylesheetContents {
/// An empty namespace map should be fine, as it is only used for parsing, /// An empty namespace map should be fine, as it is only used for parsing,
/// not serialization of existing selectors. Since UA sheets are read only, /// not serialization of existing selectors. Since UA sheets are read only,
/// we should never need the namespace map. /// we should never need the namespace map.
pub fn from_shared_data( pub fn from_data(
rules: Arc<Locked<CssRules>>, rules: Arc<Locked<CssRules>>,
origin: Origin, origin: Origin,
url_data: UrlExtraData, url_data: UrlExtraData,
quirks_mode: QuirksMode, quirks_mode: QuirksMode,
) -> Arc<Self> { ) -> Arc<Self> {
debug_assert!(rules.is_static());
Arc::new(Self { Arc::new(Self {
rules, rules,
origin, origin,
@ -144,6 +143,17 @@ impl StylesheetContents {
}) })
} }
/// Same as above, but ensuring that the rules are static.
pub fn from_shared_data(
rules: Arc<Locked<CssRules>>,
origin: Origin,
url_data: UrlExtraData,
quirks_mode: QuirksMode,
) -> Arc<Self> {
debug_assert!(rules.is_static());
Self::from_data(rules, origin, url_data, quirks_mode)
}
/// Returns a reference to the list of rules. /// Returns a reference to the list of rules.
#[inline] #[inline]
pub fn rules<'a, 'b: 'a>(&'a self, guard: &'b SharedRwLockReadGuard) -> &'a [CssRule] { pub fn rules<'a, 'b: 'a>(&'a self, guard: &'b SharedRwLockReadGuard) -> &'a [CssRule] {