mirror of
https://github.com/RGBCube/serenity
synced 2025-07-22 21:57:35 +00:00
LibWeb: Convert CSS Token/ComponentValue::to_debug_string() to String
These are only used for debugging, so I've decided that logging the ErrorOr<String> itself is fine instead of trying to handle that error more gracefully in those cases. If you're getting OOM trying to debug log things, you have bigger problems.
This commit is contained in:
parent
7fc72d3838
commit
2368e6c5f2
4 changed files with 35 additions and 35 deletions
|
@ -34,17 +34,17 @@ DeprecatedString ComponentValue::to_deprecated_string() const
|
||||||
[](NonnullRefPtr<Function> const& function) { return function->to_deprecated_string(); });
|
[](NonnullRefPtr<Function> const& function) { return function->to_deprecated_string(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString ComponentValue::to_debug_string() const
|
ErrorOr<String> ComponentValue::to_debug_string() const
|
||||||
{
|
{
|
||||||
return m_value.visit(
|
return m_value.visit(
|
||||||
[](Token const& token) {
|
[](Token const& token) -> ErrorOr<String> {
|
||||||
return DeprecatedString::formatted("Token: {}", token.to_debug_string());
|
return String::formatted("Token: {}", TRY(token.to_debug_string()));
|
||||||
},
|
},
|
||||||
[](NonnullRefPtr<Block> const& block) {
|
[](NonnullRefPtr<Block> const& block) -> ErrorOr<String> {
|
||||||
return DeprecatedString::formatted("Block: {}", block->to_deprecated_string());
|
return String::formatted("Block: {}", block->to_deprecated_string());
|
||||||
},
|
},
|
||||||
[](NonnullRefPtr<Function> const& function) {
|
[](NonnullRefPtr<Function> const& function) -> ErrorOr<String> {
|
||||||
return DeprecatedString::formatted("Function: {}", function->to_deprecated_string());
|
return String::formatted("Function: {}", function->to_deprecated_string());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ public:
|
||||||
operator Token() const { return m_value.get<Token>(); }
|
operator Token() const { return m_value.get<Token>(); }
|
||||||
|
|
||||||
DeprecatedString to_deprecated_string() const;
|
DeprecatedString to_deprecated_string() const;
|
||||||
DeprecatedString to_debug_string() const;
|
ErrorOr<String> to_debug_string() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Variant<Token, NonnullRefPtr<Function>, NonnullRefPtr<Block>> m_value;
|
Variant<Token, NonnullRefPtr<Function>, NonnullRefPtr<Block>> m_value;
|
||||||
|
|
|
@ -79,62 +79,62 @@ DeprecatedString Token::to_deprecated_string() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString Token::to_debug_string() const
|
ErrorOr<String> Token::to_debug_string() const
|
||||||
{
|
{
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case Type::Invalid:
|
case Type::Invalid:
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
|
|
||||||
case Type::EndOfFile:
|
case Type::EndOfFile:
|
||||||
return "__EOF__";
|
return String::from_utf8("__EOF__"sv);
|
||||||
case Type::Ident:
|
case Type::Ident:
|
||||||
return DeprecatedString::formatted("Ident: {}", ident());
|
return String::formatted("Ident: {}", ident());
|
||||||
case Type::Function:
|
case Type::Function:
|
||||||
return DeprecatedString::formatted("Function: {}", function());
|
return String::formatted("Function: {}", function());
|
||||||
case Type::AtKeyword:
|
case Type::AtKeyword:
|
||||||
return DeprecatedString::formatted("AtKeyword: {}", at_keyword());
|
return String::formatted("AtKeyword: {}", at_keyword());
|
||||||
case Type::Hash:
|
case Type::Hash:
|
||||||
return DeprecatedString::formatted("Hash: {} (hash_type: {})", hash_value(), m_hash_type == HashType::Unrestricted ? "Unrestricted" : "Id");
|
return String::formatted("Hash: {} (hash_type: {})", hash_value(), m_hash_type == HashType::Unrestricted ? "Unrestricted" : "Id");
|
||||||
case Type::String:
|
case Type::String:
|
||||||
return DeprecatedString::formatted("String: {}", string());
|
return String::formatted("String: {}", string());
|
||||||
case Type::BadString:
|
case Type::BadString:
|
||||||
return "BadString";
|
return String::from_utf8("BadString"sv);
|
||||||
case Type::Url:
|
case Type::Url:
|
||||||
return DeprecatedString::formatted("Url: {}", url());
|
return String::formatted("Url: {}", url());
|
||||||
case Type::BadUrl:
|
case Type::BadUrl:
|
||||||
return "BadUrl";
|
return String::from_utf8("BadUrl"sv);
|
||||||
case Type::Delim:
|
case Type::Delim:
|
||||||
return DeprecatedString::formatted("Delim: {}", m_value);
|
return String::formatted("Delim: {}", m_value);
|
||||||
case Type::Number:
|
case Type::Number:
|
||||||
return DeprecatedString::formatted("Number: {}{} (number_type: {})", m_number_value.value() > 0 && m_number_value.is_integer_with_explicit_sign() ? "+" : "", m_number_value.value(), m_number_value.is_integer() ? "Integer" : "Number");
|
return String::formatted("Number: {}{} (number_type: {})", m_number_value.value() > 0 && m_number_value.is_integer_with_explicit_sign() ? "+" : "", m_number_value.value(), m_number_value.is_integer() ? "Integer" : "Number");
|
||||||
case Type::Percentage:
|
case Type::Percentage:
|
||||||
return DeprecatedString::formatted("Percentage: {}% (number_type: {})", percentage(), m_number_value.is_integer() ? "Integer" : "Number");
|
return String::formatted("Percentage: {}% (number_type: {})", percentage(), m_number_value.is_integer() ? "Integer" : "Number");
|
||||||
case Type::Dimension:
|
case Type::Dimension:
|
||||||
return DeprecatedString::formatted("Dimension: {}{} (number_type: {})", dimension_value(), dimension_unit(), m_number_value.is_integer() ? "Integer" : "Number");
|
return String::formatted("Dimension: {}{} (number_type: {})", dimension_value(), dimension_unit(), m_number_value.is_integer() ? "Integer" : "Number");
|
||||||
case Type::Whitespace:
|
case Type::Whitespace:
|
||||||
return "Whitespace";
|
return String::from_utf8("Whitespace"sv);
|
||||||
case Type::CDO:
|
case Type::CDO:
|
||||||
return "CDO";
|
return String::from_utf8("CDO"sv);
|
||||||
case Type::CDC:
|
case Type::CDC:
|
||||||
return "CDC";
|
return String::from_utf8("CDC"sv);
|
||||||
case Type::Colon:
|
case Type::Colon:
|
||||||
return "Colon";
|
return String::from_utf8("Colon"sv);
|
||||||
case Type::Semicolon:
|
case Type::Semicolon:
|
||||||
return "Semicolon";
|
return String::from_utf8("Semicolon"sv);
|
||||||
case Type::Comma:
|
case Type::Comma:
|
||||||
return "Comma";
|
return String::from_utf8("Comma"sv);
|
||||||
case Type::OpenSquare:
|
case Type::OpenSquare:
|
||||||
return "OpenSquare";
|
return String::from_utf8("OpenSquare"sv);
|
||||||
case Type::CloseSquare:
|
case Type::CloseSquare:
|
||||||
return "CloseSquare";
|
return String::from_utf8("CloseSquare"sv);
|
||||||
case Type::OpenParen:
|
case Type::OpenParen:
|
||||||
return "OpenParen";
|
return String::from_utf8("OpenParen"sv);
|
||||||
case Type::CloseParen:
|
case Type::CloseParen:
|
||||||
return "CloseParen";
|
return String::from_utf8("CloseParen"sv);
|
||||||
case Type::OpenCurly:
|
case Type::OpenCurly:
|
||||||
return "OpenCurly";
|
return String::from_utf8("OpenCurly"sv);
|
||||||
case Type::CloseCurly:
|
case Type::CloseCurly:
|
||||||
return "CloseCurly";
|
return String::from_utf8("CloseCurly"sv);
|
||||||
}
|
}
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,7 +146,7 @@ public:
|
||||||
StringView bracket_mirror_string() const;
|
StringView bracket_mirror_string() const;
|
||||||
|
|
||||||
DeprecatedString to_deprecated_string() const;
|
DeprecatedString to_deprecated_string() const;
|
||||||
DeprecatedString to_debug_string() const;
|
ErrorOr<String> to_debug_string() const;
|
||||||
|
|
||||||
Position const& start_position() const { return m_start_position; }
|
Position const& start_position() const { return m_start_position; }
|
||||||
Position const& end_position() const { return m_end_position; }
|
Position const& end_position() const { return m_end_position; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue