Commit fe6522e8 authored by oleg@chromium.org's avatar oleg@chromium.org

Fix bug http://code.google.com/p/v8/issues/detail?id=659. Move the limits...

Fix bug http://code.google.com/p/v8/issues/detail?id=659. Move the limits check for date before the time zone offset is applied.

Review URL: http://codereview.chromium.org/1075016

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4232 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 3672624b
......@@ -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;
}
......
......@@ -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());
......
......@@ -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()));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment