mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 18:32:28 -05:00
LibWeb: Make serializing Supports rules infallible
This commit is contained in:
parent
91114c157b
commit
846c719e49
3 changed files with 22 additions and 22 deletions
|
@ -30,7 +30,7 @@ void CSSSupportsRule::initialize(JS::Realm& realm)
|
|||
|
||||
DeprecatedString CSSSupportsRule::condition_text() const
|
||||
{
|
||||
return m_supports->to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string();
|
||||
return m_supports->to_string().to_deprecated_string();
|
||||
}
|
||||
|
||||
void CSSSupportsRule::set_condition_text(DeprecatedString text)
|
||||
|
|
|
@ -74,43 +74,43 @@ bool Supports::Feature::evaluate() const
|
|||
});
|
||||
}
|
||||
|
||||
ErrorOr<String> Supports::Declaration::to_string() const
|
||||
String Supports::Declaration::to_string() const
|
||||
{
|
||||
return String::formatted("({})", declaration);
|
||||
return MUST(String::formatted("({})", declaration));
|
||||
}
|
||||
|
||||
ErrorOr<String> Supports::Selector::to_string() const
|
||||
String Supports::Selector::to_string() const
|
||||
{
|
||||
return String::formatted("selector({})", selector);
|
||||
return MUST(String::formatted("selector({})", selector));
|
||||
}
|
||||
|
||||
ErrorOr<String> Supports::Feature::to_string() const
|
||||
String Supports::Feature::to_string() const
|
||||
{
|
||||
return value.visit([](auto& it) { return it.to_string(); });
|
||||
}
|
||||
|
||||
ErrorOr<String> Supports::InParens::to_string() const
|
||||
String Supports::InParens::to_string() const
|
||||
{
|
||||
return value.visit(
|
||||
[](NonnullOwnPtr<Condition> const& condition) -> ErrorOr<String> { return String::formatted("({})", TRY(condition->to_string())); },
|
||||
[](Supports::Feature const& it) -> ErrorOr<String> { return it.to_string(); },
|
||||
[](GeneralEnclosed const& it) -> ErrorOr<String> { return it.to_string(); });
|
||||
[](NonnullOwnPtr<Condition> const& condition) { return MUST(String::formatted("({})", condition->to_string())); },
|
||||
[](Supports::Feature const& it) { return it.to_string(); },
|
||||
[](GeneralEnclosed const& it) { return it.to_string(); });
|
||||
}
|
||||
|
||||
ErrorOr<String> Supports::Condition::to_string() const
|
||||
String Supports::Condition::to_string() const
|
||||
{
|
||||
switch (type) {
|
||||
case Type::Not:
|
||||
return String::formatted("not {}", TRY(children.first().to_string()));
|
||||
return MUST(String::formatted("not {}", children.first().to_string()));
|
||||
case Type::And:
|
||||
return String::join(" and "sv, children);
|
||||
return MUST(String::join(" and "sv, children));
|
||||
case Type::Or:
|
||||
return String::join(" or "sv, children);
|
||||
return MUST(String::join(" or "sv, children));
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
ErrorOr<String> Supports::to_string() const
|
||||
String Supports::to_string() const
|
||||
{
|
||||
return m_condition->to_string();
|
||||
}
|
||||
|
|
|
@ -25,20 +25,20 @@ public:
|
|||
String declaration;
|
||||
JS::Handle<JS::Realm> realm;
|
||||
bool evaluate() const;
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
};
|
||||
|
||||
struct Selector {
|
||||
String selector;
|
||||
JS::Handle<JS::Realm> realm;
|
||||
bool evaluate() const;
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
};
|
||||
|
||||
struct Feature {
|
||||
Variant<Declaration, Selector> value;
|
||||
bool evaluate() const;
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
};
|
||||
|
||||
struct Condition;
|
||||
|
@ -46,7 +46,7 @@ public:
|
|||
Variant<NonnullOwnPtr<Condition>, Feature, GeneralEnclosed> value;
|
||||
|
||||
bool evaluate() const;
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
};
|
||||
|
||||
struct Condition {
|
||||
|
@ -59,7 +59,7 @@ public:
|
|||
Vector<InParens> children;
|
||||
|
||||
bool evaluate() const;
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
};
|
||||
|
||||
static NonnullRefPtr<Supports> create(NonnullOwnPtr<Condition>&& condition)
|
||||
|
@ -68,7 +68,7 @@ public:
|
|||
}
|
||||
|
||||
bool matches() const { return m_matches; }
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
|
||||
private:
|
||||
Supports(NonnullOwnPtr<Condition>&&);
|
||||
|
@ -83,6 +83,6 @@ template<>
|
|||
struct AK::Formatter<Web::CSS::Supports::InParens> : AK::Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Supports::InParens const& in_parens)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, TRY(in_parens.to_string()));
|
||||
return Formatter<StringView>::format(builder, in_parens.to_string());
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue