From 20533c2594a8963fb03f34faafbc8a3d034c2d25 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 19 Jul 2022 09:59:34 -0400 Subject: [PATCH] LibJS: Avoid FormatNumericToString spec issue more carefully This becomes more of an issue when implementing the Intl mathematical value, where negative zero is treated as a special enum value. In that case, we already previously changed the value from -0 to +0 in step 1b. Entering the branch for step 4 will then set it back to -0. The math that follows after these steps worked fine with both +0/-0, but assertions will be reached in the Intl MV implementation. --- Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp index 148ac58213..e064ecccc8 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp @@ -552,11 +552,11 @@ FormatResult format_numeric_to_string(GlobalObject& global_object, NumberFormatB // 3. If x < 0, let isNegative be true; else let isNegative be false. // FIXME: Spec issue: this step would override step 1a, see https://github.com/tc39/proposal-intl-numberformat-v3/issues/67 - is_negative |= is_less_than_zero(number); + if (is_less_than_zero(number)) { + is_negative = true; - // 4. If isNegative, then - if (is_negative) { - // a. Let x be -x. + // 4. If isNegative, then + // a. Let x be -x. number = multiply(global_object, number, -1); }