diff --git a/Libraries/LibWeb/CSS/CSSImportRule.cpp b/Libraries/LibWeb/CSS/CSSImportRule.cpp index ea5773c50bb..56dc2764712 100644 --- a/Libraries/LibWeb/CSS/CSSImportRule.cpp +++ b/Libraries/LibWeb/CSS/CSSImportRule.cpp @@ -156,7 +156,7 @@ void CSSImportRule::fetch() } auto decoded = decoded_or_error.release_value(); - auto* imported_style_sheet = parse_css_stylesheet(Parser::ParsingParams(*strong_this->m_document, parsed_url), decoded, parsed_url, strong_this->m_media_query_list); + auto imported_style_sheet = parse_css_stylesheet(Parser::ParsingParams(*strong_this->m_document, parsed_url), decoded, parsed_url, strong_this->m_media_query_list); // 5. Set importedStylesheet’s origin-clean flag to parentStylesheet’s origin-clean flag. imported_style_sheet->set_origin_clean(parent_style_sheet->is_origin_clean()); @@ -166,7 +166,7 @@ void CSSImportRule::fetch() imported_style_sheet->set_origin_clean(false); // 7. Set rule’s styleSheet to importedStylesheet. - strong_this->set_style_sheet(*imported_style_sheet); + strong_this->set_style_sheet(imported_style_sheet); }); } diff --git a/Libraries/LibWeb/CSS/CSSStyleSheet.cpp b/Libraries/LibWeb/CSS/CSSStyleSheet.cpp index f79ab359ae0..399996d48ed 100644 --- a/Libraries/LibWeb/CSS/CSSStyleSheet.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleSheet.cpp @@ -207,7 +207,7 @@ GC::Ref CSSStyleSheet::replace(String text) HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; // 1. Let rules be the result of running parse a stylesheet’s contents from text. - auto* parsed_stylesheet = parse_css_stylesheet(make_parsing_params(), text); + auto parsed_stylesheet = parse_css_stylesheet(make_parsing_params(), text); auto& rules = parsed_stylesheet->rules(); // 2. If rules contains one or more @import rules, remove those rules from rules. @@ -240,7 +240,7 @@ WebIDL::ExceptionOr CSSStyleSheet::replace_sync(StringView text) return WebIDL::NotAllowedError::create(realm(), "Can't call replaceSync() on non-modifiable stylesheets"_string); // 2. Let rules be the result of running parse a stylesheet’s contents from text. - auto* parsed_stylesheet = parse_css_stylesheet(make_parsing_params(), text); + auto parsed_stylesheet = parse_css_stylesheet(make_parsing_params(), text); auto& rules = parsed_stylesheet->rules(); // 3. If rules contains one or more @import rules, remove those rules from rules. diff --git a/Libraries/LibWeb/CSS/Parser/Helpers.cpp b/Libraries/LibWeb/CSS/Parser/Helpers.cpp index 6d194b2c954..1aacfacc679 100644 --- a/Libraries/LibWeb/CSS/Parser/Helpers.cpp +++ b/Libraries/LibWeb/CSS/Parser/Helpers.cpp @@ -42,7 +42,7 @@ GC::Ref internal_css_realm() return *realm; } -CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingParams const& context, StringView css, Optional<::URL::URL> location, Vector> media_query_list) +GC::Ref parse_css_stylesheet(CSS::Parser::ParsingParams const& context, StringView css, Optional<::URL::URL> location, Vector> media_query_list) { if (css.is_empty()) { auto rule_list = CSS::CSSRuleList::create_empty(*context.realm); @@ -51,7 +51,7 @@ CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingParams const& conte style_sheet->set_source_text({}); return style_sheet; } - auto* style_sheet = CSS::Parser::Parser::create(context, css).parse_as_css_stylesheet(location, move(media_query_list)); + auto style_sheet = CSS::Parser::Parser::create(context, css).parse_as_css_stylesheet(location, move(media_query_list)); // FIXME: Avoid this copy style_sheet->set_source_text(MUST(String::from_utf8(css))); return style_sheet; diff --git a/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Libraries/LibWeb/CSS/Parser/Parser.cpp index 5b4f7a2c422..c450f01ecf6 100644 --- a/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -119,7 +119,7 @@ Vector Parser::parse_a_stylesheets_contents(TokenStream& input) } // https://drafts.csswg.org/css-syntax/#parse-a-css-stylesheet -CSSStyleSheet* Parser::parse_as_css_stylesheet(Optional<::URL::URL> location, Vector> media_query_list) +GC::Ref Parser::parse_as_css_stylesheet(Optional<::URL::URL> location, Vector> media_query_list) { // To parse a CSS stylesheet, first parse a stylesheet. auto const& style_sheet = parse_a_stylesheet(m_token_stream, location); diff --git a/Libraries/LibWeb/CSS/Parser/Parser.h b/Libraries/LibWeb/CSS/Parser/Parser.h index 0931aa232f9..42f0fd74c95 100644 --- a/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Libraries/LibWeb/CSS/Parser/Parser.h @@ -90,7 +90,7 @@ class Parser { public: static Parser create(ParsingParams const&, StringView input, StringView encoding = "utf-8"sv); - CSSStyleSheet* parse_as_css_stylesheet(Optional<::URL::URL> location, Vector> media_query_list = {}); + GC::Ref parse_as_css_stylesheet(Optional<::URL::URL> location, Vector> media_query_list = {}); struct PropertiesAndCustomProperties { Vector properties; @@ -520,7 +520,7 @@ private: namespace Web { -CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingParams const&, StringView, Optional<::URL::URL> location = {}, Vector> = {}); +GC::Ref parse_css_stylesheet(CSS::Parser::ParsingParams const&, StringView, Optional<::URL::URL> location = {}, Vector> = {}); CSS::Parser::Parser::PropertiesAndCustomProperties parse_css_style_attribute(CSS::Parser::ParsingParams const&, StringView); Vector parse_css_list_of_descriptors(CSS::Parser::ParsingParams const&, CSS::AtRuleID, StringView); RefPtr parse_css_value(CSS::Parser::ParsingParams const&, StringView, CSS::PropertyID property_id = CSS::PropertyID::Invalid); diff --git a/Libraries/LibWeb/CSS/StyleSheetList.cpp b/Libraries/LibWeb/CSS/StyleSheetList.cpp index 0bed4af8a7f..bd25d75bd87 100644 --- a/Libraries/LibWeb/CSS/StyleSheetList.cpp +++ b/Libraries/LibWeb/CSS/StyleSheetList.cpp @@ -61,20 +61,13 @@ void StyleSheetList::add_a_css_style_sheet(CSS::CSSStyleSheet& sheet) } // https://www.w3.org/TR/cssom/#create-a-css-style-sheet -GC::Ptr StyleSheetList::create_a_css_style_sheet(String const& css_text, String type, DOM::Element* owner_node, String media, String title, Alternate alternate, OriginClean origin_clean, Optional<::URL::URL> location, CSSStyleSheet* parent_style_sheet, CSSRule* owner_rule) +GC::Ref StyleSheetList::create_a_css_style_sheet(String const& css_text, String type, DOM::Element* owner_node, String media, String title, Alternate alternate, OriginClean origin_clean, Optional<::URL::URL> location, CSSStyleSheet* parent_style_sheet, CSSRule* owner_rule) { // 1. Create a new CSS style sheet object and set its properties as specified. // AD-HOC: The spec never tells us when to parse this style sheet, but the most logical place is here. // AD-HOC: Are we supposed to use the document's URL for the stylesheet's location during parsing? Not doing it breaks things. auto location_url = location.value_or(document().url()); - auto* sheet = parse_css_stylesheet(Parser::ParsingParams { document(), location_url }, css_text, location_url); - - // AD-HOC: Exit out if parsing failed. - // FIXME: What should we actually do here? - if (!sheet) { - dbgln_if(CSS_LOADER_DEBUG, "StyleSheetList::create_a_css_style_sheet(): Failed to parse stylesheet at {}", location_url); - return nullptr; - } + auto sheet = parse_css_stylesheet(Parser::ParsingParams { document(), location_url }, css_text, location_url); sheet->set_parent_css_style_sheet(parent_style_sheet); sheet->set_owner_css_rule(owner_rule); diff --git a/Libraries/LibWeb/CSS/StyleSheetList.h b/Libraries/LibWeb/CSS/StyleSheetList.h index f757722e5c4..6472b0dafa1 100644 --- a/Libraries/LibWeb/CSS/StyleSheetList.h +++ b/Libraries/LibWeb/CSS/StyleSheetList.h @@ -30,7 +30,7 @@ public: No, Yes, }; - GC::Ptr create_a_css_style_sheet(String const& css_text, String type, DOM::Element* owner_node, String media, String title, Alternate, OriginClean, Optional<::URL::URL> location, CSSStyleSheet* parent_style_sheet, CSSRule* owner_rule); + GC::Ref create_a_css_style_sheet(String const& css_text, String type, DOM::Element* owner_node, String media, String title, Alternate, OriginClean, Optional<::URL::URL> location, CSSStyleSheet* parent_style_sheet, CSSRule* owner_rule); Vector> const& sheets() const { return m_sheets; } Vector>& sheets() { return m_sheets; }