Skip to content

Commit

Permalink
LibWeb/CSS: Make CSSNumericType dump() infallible
Browse files Browse the repository at this point in the history
This is a remnant of the tiny-OOM-propagation party.
  • Loading branch information
AtkinsSJ authored and awesomekling committed Dec 21, 2024
1 parent 9cbd08a commit 0d19007
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
10 changes: 5 additions & 5 deletions Libraries/LibWeb/CSS/CSSNumericType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
11 changes: 10 additions & 1 deletion Libraries/LibWeb/CSS/CSSNumericType.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <AK/Array.h>
#include <AK/Optional.h>
#include <AK/String.h>
#include <LibWeb/CSS/PropertyID.h>

namespace Web::CSS {
Expand Down Expand Up @@ -93,7 +94,7 @@ class CSSNumericType {

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;
Expand All @@ -112,3 +113,11 @@ class CSSNumericType {
};

}

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());
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ OwnPtr<CalculationNode> Parser::parse_math_function(PropertyID property_id, Func
function_generator.set("type_check", generate_calculation_type_check("argument_type"sv, parameter_type_string));
function_generator.append(R"~~~(
if (!(@type_check@)) {
dbgln_if(CSS_PARSER_DEBUG, "@name:lowercase@() argument #{} type ({}) is not an accepted type", parsed_arguments.size(), MUST(argument_type.dump()));
dbgln_if(CSS_PARSER_DEBUG, "@name:lowercase@() argument #{} type ({}) is not an accepted type", parsed_arguments.size(), argument_type.dump());
return nullptr;
}
if (parsed_arguments.is_empty()) {
determined_argument_type = move(argument_type);
} else {
if (determined_argument_type != argument_type) {
dbgln_if(CSS_PARSER_DEBUG, "@name:lowercase@() argument #{} type ({}) doesn't match type of previous arguments ({})", parsed_arguments.size(), MUST(argument_type.dump()), MUST(determined_argument_type.dump()));
dbgln_if(CSS_PARSER_DEBUG, "@name:lowercase@() argument #{} type ({}) doesn't match type of previous arguments ({})", parsed_arguments.size(), argument_type.dump(), determined_argument_type.dump());
return nullptr;
}
}
Expand Down Expand Up @@ -287,7 +287,7 @@ OwnPtr<CalculationNode> Parser::parse_math_function(PropertyID property_id, Func
auto argument_type_@parameter_index@ = maybe_argument_type_@[email protected]_value();
if (!(@type_check@)) {
dbgln_if(CSS_PARSER_DEBUG, "@name:lowercase@() argument '@parameter_name@' type ({}) is not an accepted type", MUST(argument_type_@[email protected]()));
dbgln_if(CSS_PARSER_DEBUG, "@name:lowercase@() argument '@parameter_name@' type ({}) is not an accepted type", argument_type_@[email protected]());
return nullptr;
}
)~~~");
Expand All @@ -297,7 +297,7 @@ OwnPtr<CalculationNode> Parser::parse_math_function(PropertyID property_id, Func
if (previous_parameter_type_string == parameter_type_string) {
parameter_generator.append(R"~~~(
if (argument_type_@parameter_index@ != previous_argument_type) {
dbgln_if(CSS_PARSER_DEBUG, "@name:lowercase@() argument '@parameter_name@' type ({}) doesn't match type of previous arguments ({})", MUST(argument_type_@[email protected]()), MUST(previous_argument_type.dump()));
dbgln_if(CSS_PARSER_DEBUG, "@name:lowercase@() argument '@parameter_name@' type ({}) doesn't match type of previous arguments ({})", argument_type_@[email protected](), previous_argument_type.dump());
return nullptr;
}
)~~~");
Expand Down

0 comments on commit 0d19007

Please sign in to comment.