LibWeb/CSS: Make CSSNumericType dump() infallible

This is a remnant of the tiny-OOM-propagation party.
This commit is contained in:
Sam Atkins 2024-12-12 16:51:39 +00:00 committed by Andreas Kling
commit 0d19007cb5
Notes: github-actions[bot] 2024-12-21 17:15:32 +00:00
3 changed files with 19 additions and 10 deletions

View file

@ -479,21 +479,21 @@ bool CSSNumericType::matches_dimension() const
return number_of_one_exponents == 0 || number_of_one_exponents == 1;
}
ErrorOr<String> CSSNumericType::dump() const
String CSSNumericType::dump() const
{
StringBuilder builder;
TRY(builder.try_appendff("{{ hint: {}", m_percent_hint.map([](auto base_type) { return base_type_name(base_type); })));
builder.appendff("{{ hint: {}", m_percent_hint.map([](auto base_type) { return base_type_name(base_type); }));
for (auto i = 0; i < to_underlying(BaseType::__Count); ++i) {
auto base_type = static_cast<BaseType>(i);
auto type_exponent = exponent(base_type);
if (type_exponent.has_value())
TRY(builder.try_appendff(", \"{}\" → {}", base_type_name(base_type), type_exponent.value()));
builder.appendff(", \"{}\" → {}", base_type_name(base_type), type_exponent.value());
}
TRY(builder.try_append(" }"sv));
return builder.to_string();
builder.append(" }"sv);
return builder.to_string_without_validation();
}
}

View file

@ -8,6 +8,7 @@
#include <AK/Array.h>
#include <AK/Optional.h>
#include <AK/String.h>
#include <LibWeb/CSS/PropertyID.h>
namespace Web::CSS {
@ -93,7 +94,7 @@ public:
bool operator==(CSSNumericType const& other) const = default;
ErrorOr<String> dump() const;
String dump() const;
private:
bool contains_all_the_non_zero_entries_of_other_with_the_same_value(CSSNumericType const& other) const;
@ -112,3 +113,11 @@ private:
};
}
template<>
struct AK::Formatter<Web::CSS::CSSNumericType> : Formatter<StringView> {
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::CSSNumericType const& value)
{
return Formatter<StringView>::format(builder, value.dump());
}
};