Skip to content

Commit b2a2022

Browse files
authored
Fix property order in lazy property listing for builtin/external functions (#3780)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent f06c533 commit b2a2022

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,8 @@ ecma_op_function_list_lazy_property_names (ecma_object_t *object_p, /**< functio
16491649
* ecma_op_external_function_try_to_lazy_instantiate_property
16501650
*/
16511651
void
1652-
ecma_op_external_function_list_lazy_property_names (uint32_t opts, /**< listing options using flags
1652+
ecma_op_external_function_list_lazy_property_names (ecma_object_t *object_p, /**< function object */
1653+
uint32_t opts, /**< listing options using flags
16531654
* from ecma_list_properties_options_t */
16541655
ecma_collection_t *main_collection_p, /**< 'main' collection */
16551656
ecma_collection_t *non_enum_collection_p) /**< skipped
@@ -1659,8 +1660,15 @@ ecma_op_external_function_list_lazy_property_names (uint32_t opts, /**< listing
16591660

16601661
ecma_collection_t *for_non_enumerable_p = (opts & ECMA_LIST_ENUMERABLE) ? non_enum_collection_p : main_collection_p;
16611662

1662-
/* 'prototype' property is non-enumerable (ECMA-262 v5, 13.2.18) */
1663-
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_PROTOTYPE));
1663+
#if !ENABLED (JERRY_ES2015)
1664+
JERRY_UNUSED (object_p);
1665+
#else /* ENABLED (JERRY_ES2015) */
1666+
if (!ecma_op_ordinary_object_has_own_property (object_p, ecma_get_magic_string (LIT_MAGIC_STRING_PROTOTYPE)))
1667+
#endif /* !ENABLED (JERRY_ES2015) */
1668+
{
1669+
/* 'prototype' property is non-enumerable (ECMA-262 v5, 13.2.18) */
1670+
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_PROTOTYPE));
1671+
}
16641672
} /* ecma_op_external_function_list_lazy_property_names */
16651673

16661674
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ ecma_op_function_list_lazy_property_names (ecma_object_t *object_p,
9494
ecma_collection_t *non_enum_collection_p);
9595

9696
void
97-
ecma_op_external_function_list_lazy_property_names (uint32_t opts,
97+
ecma_op_external_function_list_lazy_property_names (ecma_object_t *object_p,
98+
uint32_t opts,
9899
ecma_collection_t *main_collection_p,
99100
ecma_collection_t *non_enum_collection_p);
100101

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,8 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
21082108
{
21092109
if (!is_array_indices_only)
21102110
{
2111-
ecma_op_external_function_list_lazy_property_names (opts,
2111+
ecma_op_external_function_list_lazy_property_names (obj_p,
2112+
opts,
21122113
prop_names_p,
21132114
skipped_non_enumerable_p);
21142115
}
@@ -2160,6 +2161,7 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
21602161
#endif /* ENABLED (JERRY_ES2015) */
21612162

21622163
ecma_value_t *buffer_p = prop_names_p->buffer_p;
2164+
uint32_t lazy_prop_name_count = prop_names_p->item_count;
21632165

21642166
const size_t own_names_hashes_bitmap_size = ECMA_OBJECT_HASH_BITMAP_SIZE / bitmap_row_size;
21652167
JERRY_VLA (uint32_t, own_names_hashes_bitmap, own_names_hashes_bitmap_size);
@@ -2392,6 +2394,7 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
23922394

23932395
uint32_t array_index_name_pos = 0;
23942396
uint32_t string_name_pos = string_named_properties_count;
2397+
uint32_t lazy_string_name_pos = 0;
23952398
#if ENABLED (JERRY_ES2015)
23962399
uint32_t symbol_name_pos = symbol_named_properties_count;
23972400
#endif /* ENABLED (JERRY_ES2015) */
@@ -2453,12 +2456,19 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
24532456
JERRY_ASSERT (string_name_pos > 0);
24542457
JERRY_ASSERT (string_name_pos <= string_named_properties_count);
24552458

2456-
string_names_p[--string_name_pos] = name_p;
2459+
if (i < lazy_prop_name_count)
2460+
{
2461+
string_names_p[lazy_string_name_pos++] = name_p;
2462+
}
2463+
else
2464+
{
2465+
string_names_p[--string_name_pos] = name_p;
2466+
}
24572467
}
24582468
}
24592469

24602470
JERRY_ASSERT (array_index_name_pos == array_index_named_properties_count);
2461-
JERRY_ASSERT (string_name_pos == 0);
2471+
JERRY_ASSERT (string_name_pos - lazy_string_name_pos == 0);
24622472
#if ENABLED (JERRY_ES2015)
24632473
JERRY_ASSERT (symbol_name_pos == 0);
24642474
#endif /* ENABLED (JERRY_ES2015) */

jerry-core/vm/opcodes.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,14 @@ opfunc_create_implicit_class_constructor (uint8_t opcode) /**< current cbc opcod
867867
ext_func_obj_p->u.external_handler_cb = ecma_op_implicit_constructor_handler_cb;
868868
}
869869

870+
ecma_property_value_t *prop_value_p;
871+
prop_value_p = ecma_create_named_data_property (func_obj_p,
872+
ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH),
873+
ECMA_PROPERTY_FLAG_CONFIGURABLE,
874+
NULL);
875+
876+
prop_value_p->value = ecma_make_uint32_value (0);
877+
870878
return ecma_make_object_value (func_obj_p);
871879
} /* opfunc_create_implicit_class_constructor */
872880

@@ -1064,8 +1072,8 @@ opfunc_set_class_attributes (ecma_object_t *obj_p, /**< object */
10641072

10651073
if (ECMA_PROPERTY_GET_TYPE (property) == ECMA_PROPERTY_TYPE_NAMEDDATA)
10661074
{
1067-
JERRY_ASSERT (ecma_is_value_object (property_pair_p->values[index].value));
1068-
if (ecma_is_property_enumerable (property))
1075+
if (ecma_is_value_object (property_pair_p->values[index].value)
1076+
&& ecma_is_property_enumerable (property))
10691077
{
10701078
property_pair_p->header.types[index] = (uint8_t) (property & ~ECMA_PROPERTY_FLAG_ENUMERABLE);
10711079
opfunc_set_home_object (ecma_get_object_from_value (property_pair_p->values[index].value), parent_env_p);

tests/jerry/es2015/regression-test-issue-3606.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
// limitations under the License.
1414

1515

16-
var expected = '{"values":true,"keys":true,"findIndex":true,"find":true,"fill":true,"entries":true,"copyWithin":true}';
16+
var expected = '{"copyWithin":true,"entries":true,"fill":true,"find":true,"findIndex":true,"keys":true,"values":true}';
1717
assert(JSON.stringify(Array.prototype[Symbol.unscopables]) === expected);

0 commit comments

Comments
 (0)