Title: [91576] trunk
Revision
91576
Author
[email protected]
Date
2011-07-22 11:00:52 -0700 (Fri, 22 Jul 2011)

Log Message

Date.prototype.toISOString doesn't handle negative years or years > 9999 correctly.
https://bugs.webkit.org/show_bug.cgi?id=63986

Patch by Mark Hahnenberg <[email protected]> on 2011-07-22
Reviewed by Geoffrey Garen.

Source/_javascript_Core:

Changed the implementation of Date.prototype.toISOString() to use the extended year
format (+/-yyyyyy) for years outside of [0,9999] to be in compliance with ES 15.9.1.15.1.

* runtime/DatePrototype.cpp:
(JSC::dateProtoFuncToISOString):

LayoutTests:

Changed the implementation of Date.prototype.toISOString() to use the extended year
format (+/-yyyyyy) for years outside of [0,9999] to be in compliance with ES 15.9.1.15.1.
Altered one test that tested for incorrect behavior on years > 9999, and added another test for
years < 0 (i.e. BCE).

* fast/js/date-toisostring-expected.txt:
* fast/js/script-tests/date-toisostring.js:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (91575 => 91576)


--- trunk/LayoutTests/ChangeLog	2011-07-22 17:55:10 UTC (rev 91575)
+++ trunk/LayoutTests/ChangeLog	2011-07-22 18:00:52 UTC (rev 91576)
@@ -1,3 +1,18 @@
+2011-07-22  Mark Hahnenberg  <[email protected]>
+
+        Date.prototype.toISOString doesn't handle negative years or years > 9999 correctly.
+        https://bugs.webkit.org/show_bug.cgi?id=63986
+
+        Reviewed by Geoffrey Garen.
+
+        Changed the implementation of Date.prototype.toISOString() to use the extended year
+        format (+/-yyyyyy) for years outside of [0,9999] to be in compliance with ES 15.9.1.15.1.
+        Altered one test that tested for incorrect behavior on years > 9999, and added another test for 
+        years < 0 (i.e. BCE).
+
+        * fast/js/date-toisostring-expected.txt:
+        * fast/js/script-tests/date-toisostring.js:
+
 2011-07-22  Kent Tamura  <[email protected]>
 
         REGRESSION(r88757): The thumb of a vertical range slider is offset to the right on non-Mac.

Modified: trunk/LayoutTests/fast/js/date-toisostring-expected.txt (91575 => 91576)


--- trunk/LayoutTests/fast/js/date-toisostring-expected.txt	2011-07-22 17:55:10 UTC (rev 91575)
+++ trunk/LayoutTests/fast/js/date-toisostring-expected.txt	2011-07-22 18:00:52 UTC (rev 91576)
@@ -9,7 +9,8 @@
 PASS new Date('1 January 1500 UTC').toISOString() is '1500-01-01T00:00:00.000Z'
 PASS new Date('1 January 2000 UTC').toISOString() is '2000-01-01T00:00:00.000Z'
 PASS new Date('1 January 4000 UTC').toISOString() is '4000-01-01T00:00:00.000Z'
-PASS new Date('1 January 100000 UTC').toISOString() is '100000-01-01T00:00:00.000Z'
+PASS new Date('1 January 100000 UTC').toISOString() is '+100000-01-01T00:00:00.000Z'
+PASS new Date('1 January -1 UTC').toISOString() is '-000001-01-01T00:00:00.000Z'
 PASS new Date('10 March 2000 UTC').toISOString() is '2000-03-10T00:00:00.000Z'
 PASS new Date(NaN).toISOString() is 'Invalid Date'
 PASS successfullyParsed is true

Modified: trunk/LayoutTests/fast/js/script-tests/date-toisostring.js (91575 => 91576)


--- trunk/LayoutTests/fast/js/script-tests/date-toisostring.js	2011-07-22 17:55:10 UTC (rev 91575)
+++ trunk/LayoutTests/fast/js/script-tests/date-toisostring.js	2011-07-22 18:00:52 UTC (rev 91576)
@@ -7,7 +7,8 @@
 shouldBe("new Date('1 January 1500 UTC').toISOString()", "'1500-01-01T00:00:00.000Z'");
 shouldBe("new Date('1 January 2000 UTC').toISOString()", "'2000-01-01T00:00:00.000Z'");
 shouldBe("new Date('1 January 4000 UTC').toISOString()", "'4000-01-01T00:00:00.000Z'");
-shouldBe("new Date('1 January 100000 UTC').toISOString()", "'100000-01-01T00:00:00.000Z'");
+shouldBe("new Date('1 January 100000 UTC').toISOString()", "'+100000-01-01T00:00:00.000Z'");
+shouldBe("new Date('1 January -1 UTC').toISOString()", "'-000001-01-01T00:00:00.000Z'");
 shouldBe("new Date('10 March 2000 UTC').toISOString()", "'2000-03-10T00:00:00.000Z'");
 shouldBe("new Date(NaN).toISOString()", "'Invalid Date'");
 

Modified: trunk/Source/_javascript_Core/ChangeLog (91575 => 91576)


--- trunk/Source/_javascript_Core/ChangeLog	2011-07-22 17:55:10 UTC (rev 91575)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-07-22 18:00:52 UTC (rev 91576)
@@ -1,3 +1,16 @@
+2011-07-22  Mark Hahnenberg  <[email protected]>
+
+        Date.prototype.toISOString doesn't handle negative years or years > 9999 correctly.
+        https://bugs.webkit.org/show_bug.cgi?id=63986
+
+        Reviewed by Geoffrey Garen.
+
+        Changed the implementation of Date.prototype.toISOString() to use the extended year
+        format (+/-yyyyyy) for years outside of [0,9999] to be in compliance with ES 15.9.1.15.1.
+
+        * runtime/DatePrototype.cpp:
+        (JSC::dateProtoFuncToISOString):
+
 2011-07-21  Gavin Barraclough  <[email protected]>
 
         Windows build fix

Modified: trunk/Source/_javascript_Core/runtime/DatePrototype.cpp (91575 => 91576)


--- trunk/Source/_javascript_Core/runtime/DatePrototype.cpp	2011-07-22 17:55:10 UTC (rev 91575)
+++ trunk/Source/_javascript_Core/runtime/DatePrototype.cpp	2011-07-22 18:00:52 UTC (rev 91576)
@@ -498,10 +498,14 @@
     const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTimeUTC(exec);
     if (!gregorianDateTime)
         return JSValue::encode(jsNontrivialString(exec, "Invalid Date"));
-    // Maximum amount of space we need in buffer: 6 (max. digits in year) + 2 * 5 (2 characters each for month, day, hour, minute, second) + 4 (. + 3 digits for milliseconds)
-    // 6 for formatting and one for null termination = 27.  We add one extra character to allow us to force null termination.
-    char buffer[28];
-    snprintf(buffer, sizeof(buffer) - 1, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", 1900 + gregorianDateTime->year, gregorianDateTime->month + 1, gregorianDateTime->monthDay, gregorianDateTime->hour, gregorianDateTime->minute, gregorianDateTime->second, static_cast<int>(fmod(thisDateObj->internalNumber(), 1000)));
+    // Maximum amount of space we need in buffer: 7 (max. digits in year) + 2 * 5 (2 characters each for month, day, hour, minute, second) + 4 (. + 3 digits for milliseconds)
+    // 6 for formatting and one for null termination = 28. We add one extra character to allow us to force null termination.
+    char buffer[29];
+    // If the year is outside the bounds of 0 and 9999 inclusive we want to use the extended year format (ES 15.9.1.15.1).
+    if (gregorianDateTime->year > 8099 || gregorianDateTime->year < -1900)
+        snprintf(buffer, sizeof(buffer) - 1, "%+07d-%02d-%02dT%02d:%02d:%02d.%03dZ", 1900 + gregorianDateTime->year, gregorianDateTime->month + 1, gregorianDateTime->monthDay, gregorianDateTime->hour, gregorianDateTime->minute, gregorianDateTime->second, static_cast<int>(fmod(thisDateObj->internalNumber(), 1000)));
+    else
+        snprintf(buffer, sizeof(buffer) - 1, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", 1900 + gregorianDateTime->year, gregorianDateTime->month + 1, gregorianDateTime->monthDay, gregorianDateTime->hour, gregorianDateTime->minute, gregorianDateTime->second, static_cast<int>(fmod(thisDateObj->internalNumber(), 1000)));
     buffer[sizeof(buffer) - 1] = 0;
     return JSValue::encode(jsNontrivialString(exec, buffer));
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to