diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-date.c b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-date.c index c79af7b10..34ea26a56 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-date.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-date.c @@ -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); diff --git a/tests/jerry/regression-test-issue-1547.js b/tests/jerry/regression-test-issue-1547.js new file mode 100644 index 000000000..1a06966a8 --- /dev/null +++ b/tests/jerry/regression-test-issue-1547.js @@ -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");