Skip to content

Commit 51244b6

Browse files
Peter Markirerobika
authored andcommitted
Add option to list symbols in Object.getOwnPropertyNames() (#3507)
Also a little refactoring of Object.getOwnPropertyNames() JerryScript-DCO-1.0-Signed-off-by: Peter Marki marpeter@inf.u-szeged.hu
1 parent 8b41bf3 commit 51244b6

13 files changed

Lines changed: 184 additions & 129 deletions

jerry-core/ecma/base/ecma-globals.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,10 @@ typedef enum
335335
ECMA_LIST_ENUMERABLE = (1 << 1), /**< exclude non-enumerable properties */
336336
ECMA_LIST_PROTOTYPE = (1 << 2), /**< list properties from prototype chain */
337337
#if ENABLED (JERRY_ES2015)
338-
ECMA_LIST_SYMBOLS = (1 << 3), /**< list symbol properties only */
338+
ECMA_LIST_SYMBOLS = (1 << 3), /**< list symbol properties */
339+
ECMA_LIST_SYMBOLS_ONLY = (1 << 4), /**< list symbol properties only */
339340
#endif /* ENABLED (JERRY_ES2015) */
340-
ECMA_LIST_CONVERT_FAST_ARRAYS = (1 << 4), /**< after listing the properties convert
341+
ECMA_LIST_CONVERT_FAST_ARRAYS = (1 << 5), /**< after listing the properties convert
341342
* the fast access mode array back to normal array */
342343
} ecma_list_properties_options_t;
343344

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ ecma_builtin_object_object_get_own_property_names (ecma_object_t *obj_p) /**< ro
290290
static ecma_value_t
291291
ecma_builtin_object_object_get_own_property_symbols (ecma_object_t *obj_p) /**< routine's argument */
292292
{
293-
return ecma_builtin_helper_object_get_properties (obj_p, ECMA_LIST_SYMBOLS);
293+
return ecma_builtin_helper_object_get_properties (obj_p, ECMA_LIST_SYMBOLS_ONLY);
294294
} /* ecma_builtin_object_object_get_own_property_symbols */
295295

296296
#endif /* ENABLED (JERRY_ES2015) */
@@ -781,15 +781,15 @@ ecma_builtin_object_object_assign (ecma_object_t *target_p, /**< target object *
781781
ecma_object_t *from_obj_p = ecma_get_object_from_value (from_value);
782782

783783
/* 5.b.iii */
784-
/* TODO: extends this collection if symbols will be supported */
785784
ecma_collection_t *props_p = ecma_op_object_get_property_names (from_obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS
786-
| ECMA_LIST_ENUMERABLE);
785+
| ECMA_LIST_ENUMERABLE
786+
| ECMA_LIST_SYMBOLS);
787787

788788
ecma_value_t *buffer_p = props_p->buffer_p;
789789

790790
for (uint32_t j = 0; (j < props_p->item_count) && ecma_is_value_empty (ret_value); j++)
791791
{
792-
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[j]);
792+
ecma_string_t *property_name_p = ecma_get_prop_name_from_value (buffer_p[j]);
793793

794794
/* 5.c.i-ii */
795795
ecma_property_descriptor_t prop_desc;

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -897,18 +897,17 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
897897
*/
898898
void
899899
ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in object */
900-
bool separate_enumerable, /**< true - list enumerable properties into
901-
* main collection, and non-enumerable
902-
* to collection of 'skipped non-enumerable'
903-
* properties,
904-
* false - list all properties into main collection.
905-
*/
900+
uint32_t opts, /**< listing options using flags
901+
* from ecma_list_properties_options_t */
906902
ecma_collection_t *main_collection_p, /**< 'main' collection */
907903
ecma_collection_t *non_enum_collection_p) /**< skipped 'non-enumerable'
908904
* collection */
909905
{
910906
JERRY_ASSERT (ecma_get_object_is_builtin (object_p));
911907

908+
const bool separate_enumerable = (opts & ECMA_LIST_ENUMERABLE) != 0;
909+
const bool is_array_indices_only = (opts & ECMA_LIST_ARRAY_INDICES) != 0;
910+
912911
if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION
913912
&& ecma_builtin_function_is_routine (object_p))
914913
{
@@ -966,6 +965,12 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in
966965

967966
ecma_string_t *name_p = ecma_get_magic_string ((lit_magic_string_id_t) curr_property_p->magic_string_id);
968967

968+
if (is_array_indices_only && ecma_string_get_array_index (name_p) == ECMA_STRING_NOT_ARRAY_INDEX)
969+
{
970+
curr_property_p++;
971+
continue;
972+
}
973+
969974
uint32_t bit_for_index = (uint32_t) 1u << index;
970975

971976
if (!(*bitset_p & bit_for_index) || ecma_op_object_has_own_property (object_p, name_p))

jerry-core/ecma/builtin-objects/ecma-builtins.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ ecma_property_t *
9191
ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, ecma_string_t *string_p);
9292
void
9393
ecma_builtin_list_lazy_property_names (ecma_object_t *object_p,
94-
bool separate_enumerable,
94+
uint32_t opts,
9595
ecma_collection_t *main_collection_p,
9696
ecma_collection_t *non_enum_collection_p);
9797
bool

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ ecma_fast_array_get_property_names (ecma_object_t *object_p, /**< fast access mo
508508
ecma_collection_t *ret_p = ecma_new_collection ();
509509

510510
#if ENABLED (JERRY_ES2015)
511-
if (opts & ECMA_LIST_SYMBOLS)
511+
if (opts & ECMA_LIST_SYMBOLS_ONLY)
512512
{
513513
return ret_p;
514514
}
@@ -1185,23 +1185,21 @@ ecma_array_get_length (ecma_object_t *array_p) /**< array object */
11851185
*/
11861186
void
11871187
ecma_op_array_list_lazy_property_names (ecma_object_t *obj_p, /**< a String object */
1188-
bool separate_enumerable, /**< true - list enumerable properties
1189-
* into main collection,
1190-
* and non-enumerable to collection of
1191-
* 'skipped non-enumerable' properties,
1192-
* false - list all properties into main
1193-
* collection.
1194-
*/
1188+
uint32_t opts, /**< listing options using flags
1189+
* from ecma_list_properties_options_t */
11951190
ecma_collection_t *main_collection_p, /**< 'main' collection */
11961191
ecma_collection_t *non_enum_collection_p) /**< skipped
11971192
* 'non-enumerable'
11981193
* collection */
11991194
{
12001195
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_ARRAY);
12011196

1202-
ecma_collection_t *for_non_enumerable_p = separate_enumerable ? non_enum_collection_p : main_collection_p;
1197+
ecma_collection_t *for_non_enumerable_p = (opts & ECMA_LIST_ENUMERABLE) ? non_enum_collection_p : main_collection_p;
12031198

1204-
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
1199+
if ((opts & ECMA_LIST_ARRAY_INDICES) == 0)
1200+
{
1201+
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
1202+
}
12051203
} /* ecma_op_array_list_lazy_property_names */
12061204

12071205
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ ecma_op_array_object_define_own_property (ecma_object_t *object_p, ecma_string_t
117117
uint32_t ecma_array_get_length (ecma_object_t *array_p);
118118

119119
void
120-
ecma_op_array_list_lazy_property_names (ecma_object_t *obj_p, bool separate_enumerable,
120+
ecma_op_array_list_lazy_property_names (ecma_object_t *obj_p,
121+
uint32_t opts,
121122
ecma_collection_t *main_collection_p,
122123
ecma_collection_t *non_enum_collection_p);
123124

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

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,21 +1770,16 @@ ecma_op_bound_function_try_to_lazy_instantiate_property (ecma_object_t *object_p
17701770
*/
17711771
void
17721772
ecma_op_function_list_lazy_property_names (ecma_object_t *object_p, /**< functionobject */
1773-
bool separate_enumerable, /**< true - list enumerable properties into
1774-
* main collection and non-enumerable
1775-
* to collection of 'skipped
1776-
* non-enumerable' properties,
1777-
* false - list all properties into main
1778-
* collection.
1779-
*/
1773+
uint32_t opts, /**< listing options using flags
1774+
* from ecma_list_properties_options_t */
17801775
ecma_collection_t *main_collection_p, /**< 'main' collection */
17811776
ecma_collection_t *non_enum_collection_p) /**< skipped
17821777
* 'non-enumerable'
17831778
* collection */
17841779
{
17851780
JERRY_UNUSED (main_collection_p);
17861781

1787-
ecma_collection_t *for_non_enumerable_p = separate_enumerable ? non_enum_collection_p : main_collection_p;
1782+
ecma_collection_t *for_non_enumerable_p = (opts & ECMA_LIST_ENUMERABLE) ? non_enum_collection_p : main_collection_p;
17881783

17891784
/* 'length' property is non-enumerable (ECMA-262 v5, 13.2.5) */
17901785
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
@@ -1825,21 +1820,15 @@ ecma_op_function_list_lazy_property_names (ecma_object_t *object_p, /**< functio
18251820
* ecma_op_external_function_try_to_lazy_instantiate_property
18261821
*/
18271822
void
1828-
ecma_op_external_function_list_lazy_property_names (bool separate_enumerable, /**< true - list enumerable properties
1829-
* into main collection and
1830-
* non-enumerable to collection
1831-
* of 'skipped non-enumerable'
1832-
* properties,
1833-
* false - list all properties into
1834-
* main collection.
1835-
*/
1836-
ecma_collection_t *main_collection_p, /**< 'main' collection */
1837-
ecma_collection_t *non_enum_collection_p) /**< skipped
1838-
* collection */
1823+
ecma_op_external_function_list_lazy_property_names (uint32_t opts, /**< listing options using flags
1824+
* from ecma_list_properties_options_t */
1825+
ecma_collection_t *main_collection_p, /**< 'main' collection */
1826+
ecma_collection_t *non_enum_collection_p) /**< skipped
1827+
* collection */
18391828
{
18401829
JERRY_UNUSED (main_collection_p);
18411830

1842-
ecma_collection_t *for_non_enumerable_p = separate_enumerable ? non_enum_collection_p : main_collection_p;
1831+
ecma_collection_t *for_non_enumerable_p = (opts & ECMA_LIST_ENUMERABLE) ? non_enum_collection_p : main_collection_p;
18431832

18441833
/* 'prototype' property is non-enumerable (ECMA-262 v5, 13.2.18) */
18451834
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_PROTOTYPE));
@@ -1853,22 +1842,16 @@ ecma_op_external_function_list_lazy_property_names (bool separate_enumerable, /*
18531842
* ecma_op_bound_function_try_to_lazy_instantiate_property
18541843
*/
18551844
void
1856-
ecma_op_bound_function_list_lazy_property_names (bool separate_enumerable, /**< true - list enumerable properties
1857-
* into main collection and
1858-
* non-enumerable to collection
1859-
* of 'skipped non-enumerable'
1860-
* properties,
1861-
* false - list all properties into
1862-
* main collection.
1863-
*/
1845+
ecma_op_bound_function_list_lazy_property_names (uint32_t opts, /**< listing options using flags
1846+
* from ecma_list_properties_options_t */
18641847
ecma_collection_t *main_collection_p, /**< 'main' collection */
18651848
ecma_collection_t *non_enum_collection_p) /**< skipped
18661849
* 'non-enumerable'
18671850
* collection */
18681851
{
18691852
JERRY_UNUSED (main_collection_p);
18701853

1871-
ecma_collection_t *for_non_enumerable_p = separate_enumerable ? non_enum_collection_p : main_collection_p;
1854+
ecma_collection_t *for_non_enumerable_p = (opts & ECMA_LIST_ENUMERABLE) ? non_enum_collection_p : main_collection_p;
18721855

18731856
/* 'length' property is non-enumerable (ECMA-262 v5, 13.2.5) */
18741857
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,17 @@ ecma_op_bound_function_try_to_lazy_instantiate_property (ecma_object_t *object_p
110110

111111
void
112112
ecma_op_function_list_lazy_property_names (ecma_object_t *object_p,
113-
bool separate_enumerable,
113+
uint32_t opts,
114114
ecma_collection_t *main_collection_p,
115115
ecma_collection_t *non_enum_collection_p);
116116

117117
void
118-
ecma_op_external_function_list_lazy_property_names (bool separate_enumerable,
118+
ecma_op_external_function_list_lazy_property_names (uint32_t opts,
119119
ecma_collection_t *main_collection_p,
120120
ecma_collection_t *non_enum_collection_p);
121121

122122
void
123-
ecma_op_bound_function_list_lazy_property_names (bool separate_enumerable,
123+
ecma_op_bound_function_list_lazy_property_names (uint32_t opts,
124124
ecma_collection_t *main_collection_p,
125125
ecma_collection_t *non_enum_collection_p);
126126

0 commit comments

Comments
 (0)