Skip to content

Commit 3060656

Browse files
authored
Fix lazy property listing for [[Enumerate]] (#3794)
This patch fixes #3784. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent edaf4ef commit 3060656

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,8 +2053,6 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
20532053
ecma_collection_t *ret_p = ecma_new_collection ();
20542054
ecma_collection_t *skipped_non_enumerable_p = ecma_new_collection ();
20552055

2056-
const ecma_object_type_t type = ecma_get_object_type (obj_p);
2057-
const bool obj_is_builtin = ecma_get_object_is_builtin (obj_p);
20582056
const bool is_enumerable_only = (opts & ECMA_LIST_ENUMERABLE) != 0;
20592057
const bool is_array_indices_only = (opts & ECMA_LIST_ARRAY_INDICES) != 0;
20602058
const bool is_with_prototype_chain = (opts & ECMA_LIST_PROTOTYPE) != 0;
@@ -2069,10 +2067,10 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
20692067

20702068
memset (names_hashes_bitmap, 0, names_hashes_bitmap_size * sizeof (names_hashes_bitmap[0]));
20712069

2072-
ecma_object_t *prototype_chain_iter_p = obj_p;
2073-
20742070
while (true)
20752071
{
2072+
const ecma_object_type_t type = ecma_get_object_type (obj_p);
2073+
const bool obj_is_builtin = ecma_get_object_is_builtin (obj_p);
20762074
ecma_length_t string_named_properties_count = 0;
20772075
ecma_length_t array_index_named_properties_count = 0;
20782076
#if ENABLED (JERRY_ES2015)
@@ -2224,14 +2222,14 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
22242222
}
22252223
}
22262224

2227-
jmem_cpointer_t prop_iter_cp = prototype_chain_iter_p->u1.property_list_cp;
2225+
jmem_cpointer_t prop_iter_cp = obj_p->u1.property_list_cp;
22282226

2229-
if (ecma_op_object_is_fast_array (prototype_chain_iter_p) && prop_iter_cp != JMEM_CP_NULL)
2227+
if (ecma_op_object_is_fast_array (obj_p) && prop_iter_cp != JMEM_CP_NULL)
22302228
{
2231-
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) prototype_chain_iter_p;
2229+
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p;
22322230

22332231
uint32_t length = ext_obj_p->u.array.length;
2234-
array_index_named_properties_count = length - ecma_fast_array_get_hole_count (prototype_chain_iter_p);
2232+
array_index_named_properties_count = length - ecma_fast_array_get_hole_count (obj_p);
22352233

22362234
ecma_value_t *values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, prop_iter_cp);
22372235

@@ -2563,13 +2561,12 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
25632561

25642562
JMEM_FINALIZE_LOCAL_ARRAY (names_p);
25652563

2566-
if (!is_with_prototype_chain || prototype_chain_iter_p->u2.prototype_cp == JMEM_CP_NULL)
2564+
if (!is_with_prototype_chain || obj_p->u2.prototype_cp == JMEM_CP_NULL)
25672565
{
25682566
break;
25692567
}
25702568

2571-
prototype_chain_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t,
2572-
prototype_chain_iter_p->u2.prototype_cp);
2569+
obj_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, obj_p->u2.prototype_cp);
25732570
}
25742571

25752572
ecma_collection_free (skipped_non_enumerable_p);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 expected = ['0', '1', '2', '3', '4', '5'];
16+
var actual = [];
17+
18+
var v1 = typeof 13.37;
19+
var v3 = Object(v1);
20+
var v5 = [13.37,13.37];
21+
var v6 = [v5];
22+
v3.__proto__ = v6;
23+
24+
for (var v7 in v3) {
25+
actual.push(v7);
26+
}
27+
28+
assert(actual.length === expected.length);
29+
30+
for (var i = 0; i < actual.length; i++) {
31+
assert(actual[i] === expected[i]);
32+
}

0 commit comments

Comments
 (0)