mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
LibWeb/CSS: Make non-finite Numbers serialize as themselves
We're required to serialize NaN, infinity, and -infinity as their keyword names, even after they've been converted to Numbers.
This commit is contained in:
parent
c3d61020e7
commit
46b9497a66
Notes:
github-actions[bot]
2025-01-30 18:33:39 +00:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/LadybirdBrowser/ladybird/commit/46b9497a66c Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3383
5 changed files with 31 additions and 10 deletions
|
@ -89,6 +89,7 @@ set(SOURCES
|
|||
CSS/MediaQuery.cpp
|
||||
CSS/MediaQueryList.cpp
|
||||
CSS/MediaQueryListEvent.cpp
|
||||
CSS/Number.cpp
|
||||
CSS/Parser/ComponentValue.cpp
|
||||
CSS/Parser/GradientParsing.cpp
|
||||
CSS/Parser/Helpers.cpp
|
||||
|
|
25
Libraries/LibWeb/CSS/Number.cpp
Normal file
25
Libraries/LibWeb/CSS/Number.cpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (c) 2022-2025, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Math.h>
|
||||
#include <LibWeb/CSS/Number.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
String Number::to_string() const
|
||||
{
|
||||
if (m_type == Type::IntegerWithExplicitSign)
|
||||
return MUST(String::formatted("{:+}", m_value));
|
||||
if (m_value == AK::Infinity<double>)
|
||||
return "infinity"_string;
|
||||
if (m_value == -AK::Infinity<double>)
|
||||
return "-infinity"_string;
|
||||
if (isnan(m_value))
|
||||
return "NaN"_string;
|
||||
return String::number(m_value);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2022-2025, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -70,12 +70,7 @@ public:
|
|||
return { Type::Number, m_value / other.m_value };
|
||||
}
|
||||
|
||||
String to_string() const
|
||||
{
|
||||
if (m_type == Type::IntegerWithExplicitSign)
|
||||
return MUST(String::formatted("{:+}", m_value));
|
||||
return String::number(m_value);
|
||||
}
|
||||
String to_string() const;
|
||||
|
||||
bool operator==(Number const& other) const
|
||||
{
|
||||
|
|
|
@ -871,11 +871,10 @@ CalculatedStyleValue::CalculationResult ConstantCalculationNode::resolve(Calcula
|
|||
return { AK::E<double>, CSSNumericType {} };
|
||||
case ConstantType::Pi:
|
||||
return { AK::Pi<double>, CSSNumericType {} };
|
||||
// FIXME: We need to keep track of Infinity and NaN across all nodes, since they require special handling.
|
||||
case ConstantType::Infinity:
|
||||
return { NumericLimits<double>::max(), CSSNumericType {} };
|
||||
return { AK::Infinity<double>, CSSNumericType {} };
|
||||
case ConstantType::MinusInfinity:
|
||||
return { NumericLimits<double>::lowest(), CSSNumericType {} };
|
||||
return { -AK::Infinity<double>, CSSNumericType {} };
|
||||
case ConstantType::NaN:
|
||||
return { AK::NaN<double>, CSSNumericType {} };
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ source_set("CSS") {
|
|||
"MediaQuery.cpp",
|
||||
"MediaQueryList.cpp",
|
||||
"MediaQueryListEvent.cpp",
|
||||
"Number.cpp",
|
||||
"ParsedFontFace.cpp",
|
||||
"PreferredColorScheme.cpp",
|
||||
"PreferredContrast.cpp",
|
||||
|
|
Loading…
Add table
Reference in a new issue