Browse Source

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.
Timothy Flynn 3 years ago
parent
commit
20533c2594
1 changed files with 4 additions and 4 deletions
  1. 4 4
      Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp

+ 4 - 4
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);
     }