Title: [248738] trunk
Revision
248738
Author
commit-qu...@webkit.org
Date
2019-08-15 12:31:13 -0700 (Thu, 15 Aug 2019)

Log Message

DateConversion::formatDateTime incorrectly formats negative years
https://bugs.webkit.org/show_bug.cgi?id=199964

Patch by Alexey Shvayka <shvaikal...@gmail.com> on 2019-08-15
Reviewed by Ross Kirsling.

JSTests:

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

Source/_javascript_Core:

Currently, year is always padded to max length of 4, including the minus sign "-".
With this change, only absolute value of year is padded to max length of 4 and
preceded by minus sign "-" if the year is negative.
(steps 6-10 of https://tc39.es/ecma262/#sec-datestring)

* runtime/DateConversion.cpp:
(JSC::appendNumber):

Modified Paths

Diff

Modified: trunk/JSTests/ChangeLog (248737 => 248738)


--- trunk/JSTests/ChangeLog	2019-08-15 19:18:43 UTC (rev 248737)
+++ trunk/JSTests/ChangeLog	2019-08-15 19:31:13 UTC (rev 248738)
@@ -1,3 +1,12 @@
+2019-08-15  Alexey Shvayka  <shvaikal...@gmail.com>
+
+        DateConversion::formatDateTime incorrectly formats negative years
+        https://bugs.webkit.org/show_bug.cgi?id=199964
+
+        Reviewed by Ross Kirsling.
+
+        * test262/expectations.yaml: Mark 6 test cases as passing.
+
 2019-08-15  Mark Lam  <mark....@apple.com>
 
         More missing exception checks in String.prototype.

Modified: trunk/JSTests/test262/expectations.yaml (248737 => 248738)


--- trunk/JSTests/test262/expectations.yaml	2019-08-15 19:18:43 UTC (rev 248737)
+++ trunk/JSTests/test262/expectations.yaml	2019-08-15 19:31:13 UTC (rev 248738)
@@ -858,9 +858,6 @@
 test/built-ins/Date/proto-from-ctor-realm-zero.js:
   default: 'TypeError: Type error'
   strict mode: 'TypeError: Type error'
-test/built-ins/Date/prototype/toDateString/negative-year.js:
-  default: 'Test262Error: Date.prototype.toDateString serializes year -1 to "-0001" Expected SameValue(«-001», «-0001») to be true'
-  strict mode: 'Test262Error: Date.prototype.toDateString serializes year -1 to "-0001" Expected SameValue(«-001», «-0001») to be true'
 test/built-ins/Date/prototype/toJSON/invoke-result.js:
   default: 'TypeError: toISOString did not return a primitive value'
   strict mode: 'TypeError: toISOString did not return a primitive value'
@@ -873,12 +870,6 @@
 test/built-ins/Date/prototype/toJSON/to-primitive-value-of.js:
   default: 'TypeError: toISOString did not return a primitive value'
   strict mode: 'TypeError: toISOString did not return a primitive value'
-test/built-ins/Date/prototype/toString/negative-year.js:
-  default: 'Test262Error: Date.prototype.toString serializes year -1 to "-0001" Expected SameValue(«-001», «-0001») to be true'
-  strict mode: 'Test262Error: Date.prototype.toString serializes year -1 to "-0001" Expected SameValue(«-001», «-0001») to be true'
-test/built-ins/Date/prototype/toUTCString/negative-year.js:
-  default: 'Test262Error: Date.prototype.toUTCString serializes year -1 to "-0001" Expected SameValue(«-001», «-0001») to be true'
-  strict mode: 'Test262Error: Date.prototype.toUTCString serializes year -1 to "-0001" Expected SameValue(«-001», «-0001») to be true'
 test/built-ins/Error/proto-from-ctor-realm.js:
   default: 'Test262Error: Expected SameValue(«Error», «Error») to be true'
   strict mode: 'Test262Error: Expected SameValue(«Error», «Error») to be true'

Modified: trunk/Source/_javascript_Core/ChangeLog (248737 => 248738)


--- trunk/Source/_javascript_Core/ChangeLog	2019-08-15 19:18:43 UTC (rev 248737)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-08-15 19:31:13 UTC (rev 248738)
@@ -1,3 +1,18 @@
+2019-08-15  Alexey Shvayka  <shvaikal...@gmail.com>
+
+        DateConversion::formatDateTime incorrectly formats negative years
+        https://bugs.webkit.org/show_bug.cgi?id=199964
+
+        Reviewed by Ross Kirsling.
+
+        Currently, year is always padded to max length of 4, including the minus sign "-".
+        With this change, only absolute value of year is padded to max length of 4 and
+        preceded by minus sign "-" if the year is negative.
+        (steps 6-10 of https://tc39.es/ecma262/#sec-datestring)
+
+        * runtime/DateConversion.cpp:
+        (JSC::appendNumber):
+
 2019-08-15  Mark Lam  <mark....@apple.com>
 
         More missing exception checks in String.prototype.

Modified: trunk/Source/_javascript_Core/runtime/DateConversion.cpp (248737 => 248738)


--- trunk/Source/_javascript_Core/runtime/DateConversion.cpp	2019-08-15 19:18:43 UTC (rev 248737)
+++ trunk/Source/_javascript_Core/runtime/DateConversion.cpp	2019-08-15 19:31:13 UTC (rev 248738)
@@ -41,14 +41,12 @@
 template<int width>
 static inline void appendNumber(StringBuilder& builder, int value)
 {
-    int fillingZerosCount = width;
     if (value < 0) {
         builder.append('-');
         value = -value;
-        --fillingZerosCount;
     }
     String valueString = String::number(value);
-    fillingZerosCount -= valueString.length();
+    int fillingZerosCount = width - valueString.length();
     for (int i = 0; i < fillingZerosCount; ++i)
         builder.append('0');
     builder.append(valueString);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to