From 5d9bc378c386a5b9e96f17c1e26a120a2bf0f24d Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Mon, 13 Feb 2023 10:50:45 +0100 Subject: [PATCH] LibWeb: Make factory method of CSS::MediaList fallible --- Userland/Libraries/LibWeb/CSS/MediaList.cpp | 5 +++-- Userland/Libraries/LibWeb/CSS/MediaList.h | 2 +- Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 9 ++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/MediaList.cpp b/Userland/Libraries/LibWeb/CSS/MediaList.cpp index ca0a470c6a..3b850a64d1 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaList.cpp +++ b/Userland/Libraries/LibWeb/CSS/MediaList.cpp @@ -9,12 +9,13 @@ #include #include #include +#include namespace Web::CSS { -MediaList* MediaList::create(JS::Realm& realm, NonnullRefPtrVector&& media) +WebIDL::ExceptionOr> MediaList::create(JS::Realm& realm, NonnullRefPtrVector&& media) { - return realm.heap().allocate(realm, realm, move(media)).release_allocated_value_but_fixme_should_propagate_errors(); + return MUST_OR_THROW_OOM(realm.heap().allocate(realm, realm, move(media))); } MediaList::MediaList(JS::Realm& realm, NonnullRefPtrVector&& media) diff --git a/Userland/Libraries/LibWeb/CSS/MediaList.h b/Userland/Libraries/LibWeb/CSS/MediaList.h index 2650f6a555..7290f32061 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaList.h +++ b/Userland/Libraries/LibWeb/CSS/MediaList.h @@ -20,7 +20,7 @@ class MediaList final : public Bindings::LegacyPlatformObject { WEB_PLATFORM_OBJECT(MediaList, Bindings::LegacyPlatformObject); public: - static MediaList* create(JS::Realm&, NonnullRefPtrVector&& media); + static WebIDL::ExceptionOr> create(JS::Realm&, NonnullRefPtrVector&& media); ~MediaList() = default; DeprecatedString media_text() const; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 609439247e..63b5a51f25 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -128,7 +128,8 @@ CSSStyleSheet* Parser::parse_as_css_stylesheet(Optional location) } auto rule_list = CSSRuleList::create(m_context.realm(), rules).release_value_but_fixme_should_propagate_errors(); - return CSSStyleSheet::create(m_context.realm(), rule_list, *MediaList::create(m_context.realm(), {}), move(location)).release_value_but_fixme_should_propagate_errors(); + auto media_list = MediaList::create(m_context.realm(), {}).release_value_but_fixme_should_propagate_errors(); + return CSSStyleSheet::create(m_context.realm(), rule_list, media_list, move(location)).release_value_but_fixme_should_propagate_errors(); } Optional Parser::parse_as_selector(SelectorParsingMode parsing_mode) @@ -3057,8 +3058,9 @@ CSSRule* Parser::convert_to_rule(NonnullRefPtr rule) if (auto* child_rule = convert_to_rule(raw_rule)) child_rules.append(child_rule); } + auto media_list = MediaList::create(m_context.realm(), move(media_query_list)).release_value_but_fixme_should_propagate_errors(); auto rule_list = CSSRuleList::create(m_context.realm(), child_rules).release_value_but_fixme_should_propagate_errors(); - return CSSMediaRule::create(m_context.realm(), *MediaList::create(m_context.realm(), move(media_query_list)), rule_list).release_value_but_fixme_should_propagate_errors(); + return CSSMediaRule::create(m_context.realm(), media_list, rule_list).release_value_but_fixme_should_propagate_errors(); } if (rule->at_rule_name().equals_ignoring_case("supports"sv)) { auto supports_tokens = TokenStream { rule->prelude() }; @@ -7398,7 +7400,8 @@ CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingContext const& cont { if (css.is_empty()) { auto rule_list = CSS::CSSRuleList::create_empty(context.realm()).release_value_but_fixme_should_propagate_errors(); - return CSS::CSSStyleSheet::create(context.realm(), rule_list, *CSS::MediaList::create(context.realm(), {}), location).release_value_but_fixme_should_propagate_errors(); + auto media_list = CSS::MediaList::create(context.realm(), {}).release_value_but_fixme_should_propagate_errors(); + return CSS::CSSStyleSheet::create(context.realm(), rule_list, media_list, location).release_value_but_fixme_should_propagate_errors(); } CSS::Parser::Parser parser(context, css); return parser.parse_as_css_stylesheet(location);