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
This commit is contained in:
Peter Marki
2020-01-16 15:59:27 +01:00
committed by Robert Fancsik
parent 8b41bf306a
commit 51244b6d08
13 changed files with 184 additions and 129 deletions
@@ -290,7 +290,7 @@ ecma_builtin_object_object_get_own_property_names (ecma_object_t *obj_p) /**< ro
static ecma_value_t
ecma_builtin_object_object_get_own_property_symbols (ecma_object_t *obj_p) /**< routine's argument */
{
return ecma_builtin_helper_object_get_properties (obj_p, ECMA_LIST_SYMBOLS);
return ecma_builtin_helper_object_get_properties (obj_p, ECMA_LIST_SYMBOLS_ONLY);
} /* ecma_builtin_object_object_get_own_property_symbols */
#endif /* ENABLED (JERRY_ES2015) */
@@ -781,15 +781,15 @@ ecma_builtin_object_object_assign (ecma_object_t *target_p, /**< target object *
ecma_object_t *from_obj_p = ecma_get_object_from_value (from_value);
/* 5.b.iii */
/* TODO: extends this collection if symbols will be supported */
ecma_collection_t *props_p = ecma_op_object_get_property_names (from_obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS
| ECMA_LIST_ENUMERABLE);
| ECMA_LIST_ENUMERABLE
| ECMA_LIST_SYMBOLS);
ecma_value_t *buffer_p = props_p->buffer_p;
for (uint32_t j = 0; (j < props_p->item_count) && ecma_is_value_empty (ret_value); j++)
{
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[j]);
ecma_string_t *property_name_p = ecma_get_prop_name_from_value (buffer_p[j]);
/* 5.c.i-ii */
ecma_property_descriptor_t prop_desc;
@@ -897,18 +897,17 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
*/
void
ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in object */
bool separate_enumerable, /**< true - list enumerable properties into
* main collection, and non-enumerable
* to collection of 'skipped non-enumerable'
* properties,
* false - list all properties into main collection.
*/
uint32_t opts, /**< listing options using flags
* from ecma_list_properties_options_t */
ecma_collection_t *main_collection_p, /**< 'main' collection */
ecma_collection_t *non_enum_collection_p) /**< skipped 'non-enumerable'
* collection */
{
JERRY_ASSERT (ecma_get_object_is_builtin (object_p));
const bool separate_enumerable = (opts & ECMA_LIST_ENUMERABLE) != 0;
const bool is_array_indices_only = (opts & ECMA_LIST_ARRAY_INDICES) != 0;
if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION
&& ecma_builtin_function_is_routine (object_p))
{
@@ -966,6 +965,12 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in
ecma_string_t *name_p = ecma_get_magic_string ((lit_magic_string_id_t) curr_property_p->magic_string_id);
if (is_array_indices_only && ecma_string_get_array_index (name_p) == ECMA_STRING_NOT_ARRAY_INDEX)
{
curr_property_p++;
continue;
}
uint32_t bit_for_index = (uint32_t) 1u << index;
if (!(*bitset_p & bit_for_index) || ecma_op_object_has_own_property (object_p, name_p))
@@ -91,7 +91,7 @@ ecma_property_t *
ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, ecma_string_t *string_p);
void
ecma_builtin_list_lazy_property_names (ecma_object_t *object_p,
bool separate_enumerable,
uint32_t opts,
ecma_collection_t *main_collection_p,
ecma_collection_t *non_enum_collection_p);
bool