Reviewers: Mads Ager, antonm,

Description:
Fix broken test in WebKit test suite and add the test in question to V8 tests.


Please review this at http://codereview.chromium.org/661466

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
  M     src/runtime.cc
  M     test/mjsunit/date.js


Index: src/runtime.cc
===================================================================
--- src/runtime.cc      (revision 4006)
+++ src/runtime.cc      (working copy)
@@ -4969,8 +4969,19 @@
   ASSERT(month >= 0);
   ASSERT(month < 12);

-  static const int base_day = 365*1969 + 1969/4 - 1969/100 + 1969/400;
-  int year1 = year - 1;
+  // year_delta is an arbitrary number such that:
+  // a) year_delta = -1 (mod 400)
+  // b) year + year_delta > 0 for years in the range defined by
+  //    ECMA 262 - 15.9.1.1, i.e. upto 100,000,000 days on either side of
+  //    Jan 1 1970. This is required so that we wouldn't run into integer
+  //    division of negative numbers.
+  // c) there shouldn't be overflow for 32-bit integers in the following
+  //    operations.
+  static const int year_delta = 399999;
+ static const int base_day = 365*(1970 + year_delta) + (1970 + year_delta)/4 - + (1970 + year_delta)/100 + (1970 + year_delta)/400;
+
+  int year1 = year + year_delta;
   int day_from_year = 365 * year1 + year1 / 4 - year1 / 100 + year1 / 400 -
                       base_day;

Index: test/mjsunit/date.js
===================================================================
--- test/mjsunit/date.js        (revision 4006)
+++ test/mjsunit/date.js        (working copy)
@@ -147,3 +147,17 @@
 }

 testToLocaleTimeString();
+
+
+// Modified test from WebKit
+// LayoutTests/fast/js/script-tests/date-utc-timeclip.js:
+
+assertEquals(Date.UTC(275760, 8, 12, 23, 59, 59, 999), 8639999999999999);
+assertEquals(Date.UTC(275760, 8, 13), 8640000000000000);
+assertTrue(isNaN(Date.UTC(275760, 8, 13, 0, 0, 0, 1)));
+assertTrue(isNaN(Date.UTC(275760, 8, 14)));
+
+assertEquals(Date.UTC(-271821, 3, 20, 0, 0, 0, 1), -8639999999999999);
+assertEquals(Date.UTC(-271821, 3, 20), -8640000000000000);
+assertTrue(isNaN(Date.UTC(-271821, 3, 19, 23, 59, 59, 999)));
+assertTrue(isNaN(Date.UTC(-271821, 3, 19)));


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to