Fix bug http://code.google.com/p/v8/issues/detail?id=659. Move the limits check for...
authoroleg@chromium.org <oleg@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 23 Mar 2010 14:47:02 +0000 (14:47 +0000)
committeroleg@chromium.org <oleg@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 23 Mar 2010 14:47:02 +0000 (14:47 +0000)
Review URL: http://codereview.chromium.org/1075016

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4232 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/date.js
src/macros.py
test/mjsunit/date.js

index 6c27d69..c7c3940 100644 (file)
@@ -223,6 +223,10 @@ function LocalTime(time) {
 }
 
 function LocalTimeNoCheck(time) {
+  if (time < -MAX_TIME_MS || time > MAX_TIME_MS) {
+    return $NaN;
+  }
+
   // Inline the DST offset cache checks for speed.
   var cache = DST_offset_cache;
   if (cache.start <= time && time <= cache.end) {
@@ -265,8 +269,7 @@ var ymd_from_time_cached_time = $NaN;
 
 function YearFromTime(t) {
   if (t !== ymd_from_time_cached_time) {
-    // Limits according to ECMA 262 15.9.1.1
-    if (!$isFinite(t) || t < -8640000000000000 || t > 8640000000000000) {
+    if (!$isFinite(t)) {
       return $NaN;
     }
 
@@ -279,8 +282,7 @@ function YearFromTime(t) {
 
 function MonthFromTime(t) {
   if (t !== ymd_from_time_cached_time) {
-    // Limits according to ECMA 262 15.9.1.1
-    if (!$isFinite(t) || t < -8640000000000000 || t > 8640000000000000) {
+    if (!$isFinite(t)) {
       return $NaN;
     }
     %DateYMDFromTime(t, ymd_from_time_cache);
@@ -292,8 +294,7 @@ function MonthFromTime(t) {
 
 function DateFromTime(t) {
   if (t !== ymd_from_time_cached_time) {
-    // Limits according to ECMA 262 15.9.1.1
-    if (!$isFinite(t) || t < -8640000000000000 || t > 8640000000000000) {
+    if (!$isFinite(t)) {
       return $NaN;
     }
 
index 840c272..414b4c0 100644 (file)
@@ -128,6 +128,9 @@ const REGEXP_FIRST_CAPTURE = 3;
 # REGEXP_NUMBER_OF_CAPTURES
 macro NUMBER_OF_CAPTURES(array) = ((array)[0]);
 
+# Limit according to ECMA 262 15.9.1.1
+const MAX_TIME_MS = 8640000000000000;
+
 # Gets the value of a Date object. If arg is not a Date object
 # a type error is thrown.
 macro DATE_VALUE(arg) = (%_ClassOf(arg) === 'Date' ? %_ValueOf(arg) : ThrowDateTypeError());
index a592e4c..23b5fdc 100644 (file)
@@ -46,12 +46,18 @@ assertEquals(date2, date3);
 
 var dMax = new Date(8.64e15);
 assertEquals(8.64e15, dMax.getTime());
+assertEquals(275760, dMax.getFullYear());
+assertEquals(8, dMax.getMonth());
+assertEquals(13, dMax.getDate());
 
 var dOverflow = new Date(8.64e15+1);
 assertTrue(isNaN(dOverflow.getTime()));
 
 var dMin = new Date(-8.64e15);
 assertEquals(-8.64e15, dMin.getTime());
+assertEquals(-271821, dMin.getFullYear());
+assertEquals(3, dMin.getMonth());
+assertEquals(20, dMin.getDate());
 
 var dUnderflow = new Date(-8.64e15-1);
 assertTrue(isNaN(dUnderflow.getTime()));