Rework Object's [[OwnPropertyKeys]] (#4001)

I've removed the ecma_op_object_get_property_names method, and implemented the following ones:
- ecma_op_object_own_property_keys: this is now the internal [[OwnPropertyKeys]] method
- ecma_op_object_enumerate: this is used for the for-in iterator
- ecma_object_sort_property_names: this is used for sorting the property names of an object
- ecma_object_list_lazy_property_names: this is for getting the lazy instantiated properties
- ecma_object_prop_name_is_duplicated: this is for checking if a given property is duplicated in an object

Also the for-in operation with Proxy object works with this patch, #3992 should be closed

JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
This commit is contained in:
Szilagyi Adam
2020-07-27 11:37:04 +02:00
committed by GitHub
parent 3f0f9589c4
commit ff47c84bc4
34 changed files with 853 additions and 1101 deletions
+15 -65
View File
@@ -511,61 +511,35 @@ ecma_fast_array_set_length (ecma_object_t *object_p, /**< fast access mode array
* @return collection of strings - property names
*/
ecma_collection_t *
ecma_fast_array_get_property_names (ecma_object_t *object_p, /**< fast access mode array object */
uint32_t opts) /**< any combination of ecma_list_properties_options_t values */
ecma_fast_array_object_own_property_keys (ecma_object_t *object_p) /**< fast access mode array object */
{
JERRY_ASSERT (ecma_op_object_is_fast_array (object_p));
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p;
ecma_collection_t *ret_p = ecma_new_collection ();
#if ENABLED (JERRY_ESNEXT)
if (opts & ECMA_LIST_SYMBOLS_ONLY)
{
return ret_p;
}
#endif /* ENABLED (JERRY_ESNEXT) */
uint32_t length = ext_obj_p->u.array.length;
bool append_length = (!(opts & ECMA_LIST_ENUMERABLE) && !(opts & ECMA_LIST_ARRAY_INDICES));
if (length == 0)
if (length != 0)
{
if (append_length)
ecma_value_t *values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, object_p->u1.property_list_cp);
for (uint32_t i = 0; i < length; i++)
{
ecma_collection_push_back (ret_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
if (ecma_is_value_array_hole (values_p[i]))
{
continue;
}
ecma_string_t *index_str_p = ecma_new_ecma_string_from_uint32 (i);
ecma_collection_push_back (ret_p, ecma_make_string_value (index_str_p));
}
return ret_p;
}
ecma_value_t *values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, object_p->u1.property_list_cp);
for (uint32_t i = 0; i < length; i++)
{
if (ecma_is_value_array_hole (values_p[i]))
{
continue;
}
ecma_string_t *index_str_p = ecma_new_ecma_string_from_uint32 (i);
ecma_collection_push_back (ret_p, ecma_make_string_value (index_str_p));
}
if (append_length)
{
ecma_collection_push_back (ret_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
}
if (opts & ECMA_LIST_CONVERT_FAST_ARRAYS)
{
ecma_fast_array_convert_to_normal (object_p);
}
ecma_collection_push_back (ret_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
return ret_p;
} /* ecma_fast_array_get_property_names */
} /* ecma_fast_array_object_own_property_keys */
/**
* Array object creation operation.
@@ -1240,30 +1214,6 @@ ecma_array_object_to_string (ecma_value_t this_arg) /**< this argument */
return ret_value;
} /* ecma_array_object_to_string */
/**
* List names of a String object's lazy instantiated properties
*
* @return string values collection
*/
void
ecma_op_array_list_lazy_property_names (ecma_object_t *obj_p, /**< a String object */
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_type (obj_p) == ECMA_OBJECT_TYPE_ARRAY);
ecma_collection_t *for_non_enumerable_p = (opts & ECMA_LIST_ENUMERABLE) ? non_enum_collection_p : main_collection_p;
if ((opts & ECMA_LIST_ARRAY_INDICES) == 0)
{
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
}
} /* ecma_op_array_list_lazy_property_names */
/**
* @}
* @}