Skip to content

Commit 98cec9a

Browse files
yichoiejjeong
authored andcommitted
[[DefaultValue]] should be called twice when setting object as Array length
In section 15.4.5.1, both step 3.c and 3.d should call [[DefaultValue]]. JerryScript-DCO-1.0-Signed-off-by: Youngil Choi [email protected]
1 parent db176aa commit 98cec9a

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

jerry-core/ecma/operations/ecma-array-object.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,13 @@ ecma_op_array_object_define_own_property (ecma_object_t *obj_p, /**< the array o
198198
uint32_t new_len_uint32 = ecma_number_to_uint32 (new_len_num);
199199

200200
// d.
201+
if (ecma_is_value_object (property_desc_p->value))
202+
{
203+
ecma_value_t compared_num_val = ecma_op_to_number (property_desc_p->value);
204+
new_len_num = ecma_get_number_from_value (compared_num_val);
205+
ecma_free_value (compared_num_val);
206+
}
207+
201208
if (((ecma_number_t) new_len_uint32) != new_len_num)
202209
{
203210
return ecma_raise_range_error (ECMA_ERR_MSG (""));
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 Samsung Electronics Co., Ltd.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
var count = 0;
16+
[].length = { valueOf: function() { count++; return 1; } };
17+
assert(count == 2);
18+

0 commit comments

Comments
 (0)