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:
Sam Atkins 2025-01-27 10:39:00 +00:00 committed by Andreas Kling
commit 46b9497a66
Notes: github-actions[bot] 2025-01-30 18:33:39 +00:00
5 changed files with 31 additions and 10 deletions

View 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);
}
}