Intl.NumberFormat.prototype.format must preserve sign of -0
https://bugs.webkit.org/show_bug.cgi?id=209880

Reviewed by Keith Miller.

JSTests:

* test262/config.yaml:
This test was skipped as ICU version-dependent, but it shouldn't be.

* test262/expectations.yaml:
Mark four test cases as passing.

Source/JavaScriptCore:

The spec changed here two years ago:
https://github.com/tc39/ecma402/pull/232

* runtime/IntlNumberFormat.cpp:
(JSC::IntlNumberFormat::formatNumber):
Do NOT throw away the sign of -0.

LayoutTests:

* js/intl-numberformat-expected.txt:
* js/script-tests/intl-numberformat.js:
Fix test accordingly.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@259370 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JSTests/ChangeLog b/JSTests/ChangeLog
index 9f94eb2c..a990fe1 100644
--- a/JSTests/ChangeLog
+++ b/JSTests/ChangeLog
@@ -1,3 +1,16 @@
+2020-04-01  Ross Kirsling  <ross.kirsling@sony.com>
+
+        Intl.NumberFormat.prototype.format must preserve sign of -0
+        https://bugs.webkit.org/show_bug.cgi?id=209880
+
+        Reviewed by Keith Miller.
+
+        * test262/config.yaml:
+        This test was skipped as ICU version-dependent, but it shouldn't be.
+
+        * test262/expectations.yaml:
+        Mark four test cases as passing.
+
 2020-04-01  Justin Michaud  <justin@justinmichaud.com>
 
         Delete IC incorrectly caches for proxies
diff --git a/JSTests/test262/config.yaml b/JSTests/test262/config.yaml
index b95f363..4715d24 100644
--- a/JSTests/test262/config.yaml
+++ b/JSTests/test262/config.yaml
@@ -115,8 +115,6 @@
     # https://bugs.webkit.org/show_bug.cgi?id=192920
     - test/intl402/PluralRules/prototype/resolvedOptions/order.js
     - test/intl402/PluralRules/prototype/resolvedOptions/pluralCategories.js
-    - test/intl402/NumberFormat/prototype/format/format-fraction-digits.js
-    - test/intl402/NumberFormat/prototype/format/format-significant-digits.js
 
     # https://bugs.webkit.org/show_bug.cgi?id=190800
     - test/built-ins/TypedArray/prototype/set/src-typedarray-big-throws.js
diff --git a/JSTests/test262/expectations.yaml b/JSTests/test262/expectations.yaml
index 1c1b807..4de552b 100644
--- a/JSTests/test262/expectations.yaml
+++ b/JSTests/test262/expectations.yaml
@@ -1998,9 +1998,6 @@
 test/intl402/NumberFormat/proto-from-ctor-realm.js:
   default: 'Test262Error: newTarget.prototype is undefined Expected SameValue(«[object Object]», «[object Object]») to be true'
   strict mode: 'Test262Error: newTarget.prototype is undefined Expected SameValue(«[object Object]», «[object Object]») to be true'
-test/intl402/NumberFormat/prototype/format/format-negative-numbers.js:
-  default: 'Test262Error: Intl.NumberFormat is formatting 0 and -0 the same way. Expected SameValue(«0», «0») to be false'
-  strict mode: 'Test262Error: Intl.NumberFormat is formatting 0 and -0 the same way. Expected SameValue(«0», «0») to be false'
 test/intl402/PluralRules/proto-from-ctor-realm.js:
   default: 'Test262Error: newTarget.prototype is undefined Expected SameValue(«[object Object]», «[object Object]») to be true'
   strict mode: 'Test262Error: newTarget.prototype is undefined Expected SameValue(«[object Object]», «[object Object]») to be true'
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 1e21368..4faaaa2 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,14 @@
+2020-04-01  Ross Kirsling  <ross.kirsling@sony.com>
+
+        Intl.NumberFormat.prototype.format must preserve sign of -0
+        https://bugs.webkit.org/show_bug.cgi?id=209880
+
+        Reviewed by Keith Miller.
+
+        * js/intl-numberformat-expected.txt:
+        * js/script-tests/intl-numberformat.js:
+        Fix test accordingly.
+
 2020-04-01  Per Arne Vollan  <pvollan@apple.com>
 
         [macOS] Deny mach-lookup access to "com.apple.lsd.mapdb" in sandbox
diff --git a/LayoutTests/js/intl-numberformat-expected.txt b/LayoutTests/js/intl-numberformat-expected.txt
index 62b5da7..d72bc0c 100644
--- a/LayoutTests/js/intl-numberformat-expected.txt
+++ b/LayoutTests/js/intl-numberformat-expected.txt
@@ -201,7 +201,7 @@
 PASS Intl.NumberFormat('en').format(Infinity) is '∞'
 PASS Intl.NumberFormat('en').format(-Infinity) is '-∞'
 PASS Intl.NumberFormat('en').format(0) is '0'
-PASS Intl.NumberFormat('en').format(-0) is '0'
+PASS Intl.NumberFormat('en').format(-0) is '-0'
 PASS Intl.NumberFormat('en').format(Number.MIN_VALUE) is '0'
 PASS Intl.NumberFormat('en', { maximumSignificantDigits: 15 }).format(Number.MAX_VALUE) is '179,769,313,486,232,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000'
 PASS Intl.NumberFormat('en').format(1234.567) is '1,234.567'
diff --git a/LayoutTests/js/script-tests/intl-numberformat.js b/LayoutTests/js/script-tests/intl-numberformat.js
index 4114ebf..4e1fd60 100644
--- a/LayoutTests/js/script-tests/intl-numberformat.js
+++ b/LayoutTests/js/script-tests/intl-numberformat.js
@@ -317,7 +317,7 @@
 shouldBe("Intl.NumberFormat('en').format(Infinity)", "'∞'");
 shouldBe("Intl.NumberFormat('en').format(-Infinity)", "'-∞'");
 shouldBe("Intl.NumberFormat('en').format(0)", "'0'");
-shouldBe("Intl.NumberFormat('en').format(-0)", "'0'");
+shouldBe("Intl.NumberFormat('en').format(-0)", "'-0'");
 shouldBe("Intl.NumberFormat('en').format(Number.MIN_VALUE)", "'0'");
 shouldBe("Intl.NumberFormat('en', { maximumSignificantDigits: 15 }).format(Number.MAX_VALUE)", "'179,769,313,486,232,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000'");
 
diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog
index f219eb6..c8b58ea 100644
--- a/Source/JavaScriptCore/ChangeLog
+++ b/Source/JavaScriptCore/ChangeLog
@@ -1,3 +1,17 @@
+2020-04-01  Ross Kirsling  <ross.kirsling@sony.com>
+
+        Intl.NumberFormat.prototype.format must preserve sign of -0
+        https://bugs.webkit.org/show_bug.cgi?id=209880
+
+        Reviewed by Keith Miller.
+
+        The spec changed here two years ago:
+        https://github.com/tc39/ecma402/pull/232
+
+        * runtime/IntlNumberFormat.cpp:
+        (JSC::IntlNumberFormat::formatNumber):
+        Do NOT throw away the sign of -0.
+
 2020-04-01  Justin Michaud  <justin@justinmichaud.com>
 
         Delete IC incorrectly caches for proxies
diff --git a/Source/JavaScriptCore/runtime/IntlNumberFormat.cpp b/Source/JavaScriptCore/runtime/IntlNumberFormat.cpp
index 1a28807..7903db1 100644
--- a/Source/JavaScriptCore/runtime/IntlNumberFormat.cpp
+++ b/Source/JavaScriptCore/runtime/IntlNumberFormat.cpp
@@ -344,10 +344,6 @@
     if (!m_initializedNumberFormat)
         return throwTypeError(globalObject, scope, "Intl.NumberFormat.prototype.format called on value that's not an object initialized as a NumberFormat"_s);
 
-    // Map negative zero to positive zero.
-    if (!number)
-        number = 0.0;
-
     UErrorCode status = U_ZERO_ERROR;
     Vector<UChar, 32> buffer(32);
     auto length = unum_formatDouble(m_numberFormat.get(), number, buffer.data(), buffer.size(), nullptr, &status);