Skip to content

Commit 1c43e5b

Browse files
committed
Fix Date construct helper
Correct behaviour of step 8, 15.9.3.1, ECMA-262 v5.1. - Change ToInt32(y) to ToInteger(y). - If ToInteger(y) is not between 0 and 99 then yr = y Related issue: #1071 JerryScript-DCO-1.0-Signed-off-by: Hanjoung Lee [email protected] JerryScript-DCO-1.0-Signed-off-by: Hanjoung Lee [email protected]
1 parent 372a2bb commit 1c43e5b

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

jerry-core/ecma/base/ecma-helpers-number.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,8 @@ ecma_number_negate (ecma_number_t num) /**< ecma-number */
619619
ecma_number_t
620620
ecma_number_trunc (ecma_number_t num) /**< ecma-number */
621621
{
622+
JERRY_ASSERT (!ecma_number_is_nan (num));
623+
622624
uint64_t fraction;
623625
int32_t exponent;
624626
const int32_t dot_shift = ecma_number_get_fraction_and_exponent (num, &fraction, &exponent);

jerry-core/ecma/builtin-objects/ecma-builtin-date.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,14 @@ ecma_date_construct_helper (const ecma_value_t *args, /**< arguments passed to t
136136

137137
if (ecma_is_value_empty (ret_value))
138138
{
139-
if (!ecma_number_is_nan (year) && !ecma_number_is_infinity (year))
139+
if (!ecma_number_is_nan (year))
140140
{
141141
/* 8. */
142-
int32_t y = ecma_number_to_int32 (year);
142+
ecma_number_t y = ecma_number_trunc (year);
143143

144144
if (y >= 0 && y <= 99)
145145
{
146-
year = (ecma_number_t) (1900 + y);
147-
}
148-
else
149-
{
150-
year = (ecma_number_t) y;
146+
year = 1900 + y;
151147
}
152148
}
153149

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2016 Samsung Electronics Co., Ltd.
2+
// Copyright 2016 University of Szeged.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
var d = new Date(864858163349847396, 1, 1, 1, 1, 1, 1, 1)
17+
assert (d.toGMTString() === "Invalid Date");
18+
19+
d = new Date(864858, 1, 1, 1, 1, 1, 1, 1)
20+
assert (d.toGMTString() === "Invalid Date");
21+
22+
d = new Date(86485, 1, 1, 1, 1, 1, 1, 1)
23+
assert (d.toGMTString() !== "Invalid Date");

0 commit comments

Comments
 (0)