Skip to content

Commit e693854

Browse files
rerobikadbatyai
authored andcommitted
Fix array-indexed property name calculation for fast access mode arrays in property name listing (#3533)
This patch fixes #3532. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 3c5fb34 commit e693854

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,18 @@ ecma_fast_array_set_property (ecma_object_t *object_p, /**< fast access mode arr
301301
return true;
302302
} /* ecma_fast_array_set_property */
303303

304+
/**
305+
* Get the number of array holes in a fast access array object
306+
*
307+
* @return number of array holes in a fast access array object
308+
*/
309+
inline uint32_t JERRY_ATTR_ALWAYS_INLINE
310+
ecma_fast_array_get_hole_count (ecma_object_t *obj_p) /**< fast access mode array object */
311+
{
312+
JERRY_ASSERT (ecma_op_object_is_fast_array (obj_p));
313+
314+
return ((ecma_extended_object_t *) obj_p)->u.array.u.hole_count >> ECMA_FAST_ARRAY_HOLE_SHIFT;
315+
} /* ecma_fast_array_get_hole_count */
304316

305317
/**
306318
* Extend the underlying buffer of a fast mode access array for the given new length

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ ecma_op_object_is_fast_array (ecma_object_t *object_p);
7474
bool
7575
ecma_op_array_is_fast_array (ecma_extended_object_t *array_p);
7676

77+
uint32_t
78+
ecma_fast_array_get_hole_count (ecma_object_t *obj_p);
79+
7780
ecma_value_t *
7881
ecma_fast_array_extend (ecma_object_t *object_p, uint32_t new_lengt);
7982

jerry-core/ecma/operations/ecma-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2015,7 +2015,7 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
20152015
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) prototype_chain_iter_p;
20162016

20172017
uint32_t length = ext_obj_p->u.array.length;
2018-
array_index_named_properties_count = length;
2018+
array_index_named_properties_count = length - ecma_fast_array_get_hole_count (prototype_chain_iter_p);
20192019

20202020
ecma_value_t *values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, prop_iter_cp);
20212021

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
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 reached = false;
16+
17+
function dConstr () {}
18+
dConstr.prototype = [, ]
19+
for (var $ in new dConstr()) {
20+
reached = true;
21+
}
22+
23+
assert(!reached);

0 commit comments

Comments
 (0)