1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:27:35 +00:00

LibWeb: Make factory method of CSS::MediaList fallible

This commit is contained in:
Kenneth Myhra 2023-02-13 10:50:45 +01:00 committed by Linus Groh
parent a49ea467ad
commit 5d9bc378c3
3 changed files with 10 additions and 6 deletions

View file

@ -9,12 +9,13 @@
#include <LibWeb/Bindings/MediaListPrototype.h>
#include <LibWeb/CSS/MediaList.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::CSS {
MediaList* MediaList::create(JS::Realm& realm, NonnullRefPtrVector<MediaQuery>&& media)
WebIDL::ExceptionOr<JS::NonnullGCPtr<MediaList>> MediaList::create(JS::Realm& realm, NonnullRefPtrVector<MediaQuery>&& media)
{
return realm.heap().allocate<MediaList>(realm, realm, move(media)).release_allocated_value_but_fixme_should_propagate_errors();
return MUST_OR_THROW_OOM(realm.heap().allocate<MediaList>(realm, realm, move(media)));
}
MediaList::MediaList(JS::Realm& realm, NonnullRefPtrVector<MediaQuery>&& media)

View file

@ -20,7 +20,7 @@ class MediaList final : public Bindings::LegacyPlatformObject {
WEB_PLATFORM_OBJECT(MediaList, Bindings::LegacyPlatformObject);
public:
static MediaList* create(JS::Realm&, NonnullRefPtrVector<MediaQuery>&& media);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<MediaList>> create(JS::Realm&, NonnullRefPtrVector<MediaQuery>&& media);
~MediaList() = default;
DeprecatedString media_text() const;

View file

@ -128,7 +128,8 @@ CSSStyleSheet* Parser::parse_as_css_stylesheet(Optional<AK::URL> 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<SelectorList> Parser::parse_as_selector(SelectorParsingMode parsing_mode)
@ -3057,8 +3058,9 @@ CSSRule* Parser::convert_to_rule(NonnullRefPtr<Rule> 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);