Fix the infinite loop in ecma_date_year_from_time
JerryScript-DCO-1.0-Signed-off-by: Szilard Ledan szledan.u-szeged@partner.samsung.com
This commit is contained in:
committed by
László Langó
parent
9edae36b00
commit
7c1622855d
@@ -187,13 +187,19 @@ ecma_date_year_from_time (ecma_number_t time) /**< time value */
|
||||
/* ECMA-262 v5, 15.9.1.1 define the largest year that is
|
||||
* representable (285616) forward from 01 January, 1970 UTC.
|
||||
*/
|
||||
ecma_number_t year = (ecma_number_t) (285616 + 1970);
|
||||
ecma_number_t year = (ecma_number_t) (1970 + 285616);
|
||||
ecma_number_t lower_year_boundary = (ecma_number_t) (1970 - 285616);
|
||||
|
||||
while (ecma_date_time_from_year (year) > time)
|
||||
{
|
||||
if (ecma_date_time_from_year ((ecma_number_t) floor (year / 2)) > time)
|
||||
ecma_number_t year_boundary = (ecma_number_t) floor (lower_year_boundary + (year - lower_year_boundary) / 2);
|
||||
if (ecma_date_time_from_year (year_boundary) > time)
|
||||
{
|
||||
year = (ecma_number_t) floor (year / 2);
|
||||
year = year_boundary;
|
||||
}
|
||||
else
|
||||
{
|
||||
lower_year_boundary = year_boundary;
|
||||
}
|
||||
year--;
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ assert (isNaN (d.getTimezoneOffset()));
|
||||
|
||||
/* 5. test case */
|
||||
assert (new Date(2013, -1).getMonth() === 11);
|
||||
assert (new Date(-2, -2).getFullYear() === -3);
|
||||
assert (new Date(-1, -1).getFullYear() === -2);
|
||||
assert (new Date(-1, -1, -1).getMonth() === 10);
|
||||
assert (new Date(-1, -1, -1, -1).getDate() === 28);
|
||||
|
||||
@@ -81,6 +81,7 @@ main (int __attr_unused___ argc,
|
||||
JERRY_ASSERT (ecma_date_year_from_time (-1970 * MS_PER_YEAR) == 1);
|
||||
JERRY_ASSERT (ecma_date_year_from_time (START_OF_GREGORIAN_CALENDAR) == 0);
|
||||
JERRY_ASSERT (ecma_date_year_from_time (START_OF_GREGORIAN_CALENDAR - 1) == -1);
|
||||
JERRY_ASSERT (ecma_date_year_from_time (START_OF_GREGORIAN_CALENDAR - 3 * MS_PER_YEAR) == -3);
|
||||
|
||||
/* int ecma_date_day_within_year (time) */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user