script: Pass the right base URI to inline sheets (#40554)

HTMLStyleElement was creating stylesheets using the URI of the document,
ignoring `<base>`.

To avoid having to create the UrlExtraData twice (or clone it), this
inlines the `stylesheetcontents_create_callback`.

Testing: 2 WPT are now passing
Fixes: #40550

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Oriol Brufau
2025-11-11 18:59:22 +09:00
committed by GitHub
parent a094a0bbbc
commit cb906a6219
4 changed files with 26 additions and 35 deletions

View File

@@ -11,9 +11,13 @@ use std::rc::Rc;
use servo_arc::Arc as ServoArc;
use style::context::QuirksMode;
use style::shared_lock::SharedRwLock;
use style::stylesheets::{CssRule, StylesheetContents, UrlExtraData};
use style::stylesheets::{AllowImportRules, CssRule, Origin, StylesheetContents, UrlExtraData};
use stylo_atoms::Atom;
use crate::dom::node::NodeTraits;
use crate::dom::types::HTMLElement;
use crate::stylesheet_loader::ElementStylesheetLoader;
const MAX_LENGTH_OF_TEXT_INSERTED_INTO_TABLE: usize = 1024;
const UNIQUE_OWNED: usize = 2;
@@ -81,7 +85,7 @@ impl StylesheetContentsCache {
shared_lock: &SharedRwLock,
url_data: UrlExtraData,
quirks_mode: QuirksMode,
stylesheetcontents_create_callback: impl FnOnce() -> ServoArc<StylesheetContents>,
element: &HTMLElement,
) -> (
Option<StylesheetContentsCacheKey>,
ServoArc<StylesheetContents>,
@@ -100,7 +104,22 @@ impl StylesheetContentsCache {
)
},
Entry::Vacant(vacant_entry) => {
let contents = stylesheetcontents_create_callback();
let contents = {
#[cfg(feature = "tracing")]
let _span = tracing::trace_span!("ParseStylesheet", servo_profiling = true)
.entered();
StylesheetContents::from_str(
stylesheet_text,
url_data,
Origin::Author,
shared_lock,
Some(&ElementStylesheetLoader::new(element)),
element.owner_window().css_error_reporter(),
quirks_mode,
AllowImportRules::Yes,
/* sanitized_output = */ None,
)
};
if Self::contents_can_be_cached(&contents, shared_lock) {
let occupied_entry = vacant_entry.insert_entry(contents.clone());
// Use a copy of the cache key from `Entry` instead of the newly created one above