NaN must not be passed to date getter functions. (#1620)

Fixes #1547

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg 2017-02-27 11:19:29 +01:00 committed by GitHub
parent df4064c18e
commit 3de72af712
2 changed files with 20 additions and 2 deletions

View File

@ -511,7 +511,8 @@ ecma_date_make_day (ecma_number_t year, /**< year value */
* To find this time it starts from the beginning of the year (ym)
* then find the first day of the month.
*/
if (ecma_date_year_from_time (time) == ym)
if (!ecma_number_is_nan (time)
&& ecma_date_year_from_time (time) == ym)
{
/* Get the month */
time += 31 * mn * ECMA_DATE_MS_PER_DAY;
@ -519,7 +520,9 @@ ecma_date_make_day (ecma_number_t year, /**< year value */
/* Get the month's first day */
time += ((ecma_number_t) 1.0 - ecma_date_date_from_time (time)) * ECMA_DATE_MS_PER_DAY;
if (ecma_date_month_from_time (time) == mn && ecma_date_date_from_time (time) == 1)
if (!ecma_number_is_nan (time)
&& ecma_date_month_from_time (time) == mn
&& ecma_date_date_from_time (time) == 1)
{
/* 8. */
return ecma_date_day (time) + dt - ((ecma_number_t) 1.0);

View File

@ -0,0 +1,15 @@
// Copyright JS Foundation and other contributors, http://js.foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
assert(new Date(Number.MAX_VALUE, Number.MAX_VALUE).toString() == "Invalid Date");