diff --git a/Userland/Libraries/LibWeb/CSS/MediaList.cpp b/Userland/Libraries/LibWeb/CSS/MediaList.cpp index 03bbe397cd..7227472324 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaList.cpp +++ b/Userland/Libraries/LibWeb/CSS/MediaList.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Sam Atkins + * Copyright (c) 2021-2023, Sam Atkins * Copyright (c) 2022-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause @@ -33,7 +33,7 @@ void MediaList::initialize(JS::Realm& realm) // https://www.w3.org/TR/cssom-1/#dom-medialist-mediatext DeprecatedString MediaList::media_text() const { - return serialize_a_media_query_list(m_media).release_value_but_fixme_should_propagate_errors().to_deprecated_string(); + return serialize_a_media_query_list(m_media).to_deprecated_string(); } // https://www.w3.org/TR/cssom-1/#dom-medialist-mediatext @@ -56,7 +56,7 @@ DeprecatedString MediaList::item(u32 index) const if (!is_supported_property_index(index)) return {}; - return m_media[index]->to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string(); + return m_media[index]->to_string().to_deprecated_string(); } // https://www.w3.org/TR/cssom-1/#dom-medialist-appendmedium @@ -70,9 +70,9 @@ void MediaList::append_medium(DeprecatedString medium) return; // 3. If comparing m with any of the media queries in the collection of media queries returns true, then return. - auto serialized = m->to_string().release_value_but_fixme_should_propagate_errors(); + auto serialized = m->to_string(); for (auto& existing_medium : m_media) { - if (existing_medium->to_string().release_value_but_fixme_should_propagate_errors() == serialized) + if (existing_medium->to_string() == serialized) return; } @@ -87,7 +87,7 @@ void MediaList::delete_medium(DeprecatedString medium) if (!m) return; m_media.remove_all_matching([&](auto& existing) -> bool { - return m->to_string().release_value_but_fixme_should_propagate_errors() == existing->to_string().release_value_but_fixme_should_propagate_errors(); + return m->to_string() == existing->to_string(); }); // FIXME: If nothing was removed, then throw a NotFoundError exception. } @@ -117,7 +117,7 @@ WebIDL::ExceptionOr MediaList::item_value(size_t index) const { if (index >= m_media.size()) return JS::js_undefined(); - return JS::PrimitiveString::create(vm(), m_media[index]->to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string()); + return JS::PrimitiveString::create(vm(), m_media[index]->to_string().to_deprecated_string()); } } diff --git a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp index 48e4af96ce..73a54b3ee2 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp +++ b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Sam Atkins + * Copyright (c) 2021-2023, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -21,7 +21,7 @@ NonnullRefPtr MediaQuery::create_not_all() return adopt_ref(*media_query); } -ErrorOr MediaFeatureValue::to_string() const +String MediaFeatureValue::to_string() const { return m_value.visit( [](ValueID const& ident) { return MUST(String::from_utf8(string_from_value_id(ident))); }, @@ -41,7 +41,7 @@ bool MediaFeatureValue::is_same_type(MediaFeatureValue const& other) const [&](float) { return other.is_number(); }); } -ErrorOr MediaFeature::to_string() const +String MediaFeature::to_string() const { auto comparison_string = [](Comparison comparison) -> StringView { switch (comparison) { @@ -61,18 +61,18 @@ ErrorOr MediaFeature::to_string() const switch (m_type) { case Type::IsTrue: - return String::from_utf8(string_from_media_feature_id(m_id)); + return MUST(String::from_utf8(string_from_media_feature_id(m_id))); case Type::ExactValue: - return String::formatted("{}:{}", string_from_media_feature_id(m_id), TRY(m_value->to_string())); + return MUST(String::formatted("{}:{}", string_from_media_feature_id(m_id), m_value->to_string())); case Type::MinValue: - return String::formatted("min-{}:{}", string_from_media_feature_id(m_id), TRY(m_value->to_string())); + return MUST(String::formatted("min-{}:{}", string_from_media_feature_id(m_id), m_value->to_string())); case Type::MaxValue: - return String::formatted("max-{}:{}", string_from_media_feature_id(m_id), TRY(m_value->to_string())); + return MUST(String::formatted("max-{}:{}", string_from_media_feature_id(m_id), m_value->to_string())); case Type::Range: if (!m_range->right_comparison.has_value()) - return String::formatted("{} {} {}", TRY(m_range->left_value.to_string()), comparison_string(m_range->left_comparison), string_from_media_feature_id(m_id)); + return MUST(String::formatted("{} {} {}", m_range->left_value.to_string(), comparison_string(m_range->left_comparison), string_from_media_feature_id(m_id))); - return String::formatted("{} {} {} {} {}", TRY(m_range->left_value.to_string()), comparison_string(m_range->left_comparison), string_from_media_feature_id(m_id), comparison_string(*m_range->right_comparison), TRY(m_range->right_value->to_string())); + return MUST(String::formatted("{} {} {} {} {}", m_range->left_value.to_string(), comparison_string(m_range->left_comparison), string_from_media_feature_id(m_id), comparison_string(*m_range->right_comparison), m_range->right_value->to_string())); } VERIFY_NOT_REACHED(); @@ -276,17 +276,17 @@ NonnullOwnPtr MediaCondition::from_or_list(Vector MediaCondition::to_string() const +String MediaCondition::to_string() const { StringBuilder builder; builder.append('('); switch (type) { case Type::Single: - builder.append(TRY(feature->to_string())); + builder.append(feature->to_string()); break; case Type::Not: builder.append("not "sv); - builder.append(TRY(conditions.first()->to_string())); + builder.append(conditions.first()->to_string()); break; case Type::And: builder.join(" and "sv, conditions); @@ -299,7 +299,7 @@ ErrorOr MediaCondition::to_string() const break; } builder.append(')'); - return builder.to_string(); + return MUST(builder.to_string()); } MatchResult MediaCondition::evaluate(HTML::Window const& window) const @@ -319,7 +319,7 @@ MatchResult MediaCondition::evaluate(HTML::Window const& window) const VERIFY_NOT_REACHED(); } -ErrorOr MediaQuery::to_string() const +String MediaQuery::to_string() const { StringBuilder builder; @@ -333,10 +333,10 @@ ErrorOr MediaQuery::to_string() const } if (m_media_condition) { - builder.append(TRY(m_media_condition->to_string())); + builder.append(m_media_condition->to_string()); } - return builder.to_string(); + return MUST(builder.to_string()); } bool MediaQuery::evaluate(HTML::Window const& window) @@ -380,7 +380,7 @@ bool MediaQuery::evaluate(HTML::Window const& window) } // https://www.w3.org/TR/cssom-1/#serialize-a-media-query-list -ErrorOr serialize_a_media_query_list(Vector> const& media_queries) +String serialize_a_media_query_list(Vector> const& media_queries) { // 1. If the media query list is empty, then return the empty string. if (media_queries.is_empty()) @@ -388,7 +388,7 @@ ErrorOr serialize_a_media_query_list(Vector> c // 2. Serialize each media query in the list of media queries, in the same order as they // appear in the media query list, and then serialize the list. - return String::join(", "sv, media_queries); + return MUST(String::join(", "sv, media_queries)); } bool is_media_feature_name(StringView name) diff --git a/Userland/Libraries/LibWeb/CSS/MediaQuery.h b/Userland/Libraries/LibWeb/CSS/MediaQuery.h index 942b8296b2..135dbcde35 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaQuery.h +++ b/Userland/Libraries/LibWeb/CSS/MediaQuery.h @@ -46,7 +46,7 @@ public: { } - ErrorOr to_string() const; + String to_string() const; bool is_ident() const { return m_value.has(); } bool is_length() const { return m_value.has(); } @@ -145,7 +145,7 @@ public: } bool evaluate(HTML::Window const&) const; - ErrorOr to_string() const; + String to_string() const; private: enum class Type { @@ -201,7 +201,7 @@ struct MediaCondition { static NonnullOwnPtr from_or_list(Vector>&&); MatchResult evaluate(HTML::Window const&) const; - ErrorOr to_string() const; + String to_string() const; private: MediaCondition() = default; @@ -240,7 +240,7 @@ public: bool matches() const { return m_matches; } bool evaluate(HTML::Window const&); - ErrorOr to_string() const; + String to_string() const; private: MediaQuery() = default; @@ -254,7 +254,7 @@ private: bool m_matches { false }; }; -ErrorOr serialize_a_media_query_list(Vector> const&); +String serialize_a_media_query_list(Vector> const&); bool is_media_feature_name(StringView name); @@ -269,7 +269,7 @@ template<> struct Formatter : Formatter { ErrorOr format(FormatBuilder& builder, Web::CSS::MediaFeature const& media_feature) { - return Formatter::format(builder, TRY(media_feature.to_string())); + return Formatter::format(builder, media_feature.to_string()); } }; @@ -277,7 +277,7 @@ template<> struct Formatter : Formatter { ErrorOr format(FormatBuilder& builder, Web::CSS::MediaCondition const& media_condition) { - return Formatter::format(builder, TRY(media_condition.to_string())); + return Formatter::format(builder, media_condition.to_string()); } }; @@ -285,7 +285,7 @@ template<> struct Formatter : Formatter { ErrorOr format(FormatBuilder& builder, Web::CSS::MediaQuery const& media_query) { - return Formatter::format(builder, TRY(media_query.to_string())); + return Formatter::format(builder, media_query.to_string()); } }; diff --git a/Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp b/Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp index b306655ad7..1190975634 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp +++ b/Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp @@ -43,7 +43,7 @@ void MediaQueryList::visit_edges(Cell::Visitor& visitor) // https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-media DeprecatedString MediaQueryList::media() const { - return serialize_a_media_query_list(m_media).release_value_but_fixme_should_propagate_errors().to_deprecated_string(); + return serialize_a_media_query_list(m_media).to_deprecated_string(); } // https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-matches