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
@@ -1079,38 +1079,38 @@ ecma_builtin_array_prototype_object_sort (ecma_value_t this_arg, /**< this argum
return ecma_raise_type_error (ECMA_ERR_MSG ("Compare function is not callable."));
}
ecma_collection_t *array_index_props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_ARRAY_INDICES);
ecma_collection_t *array_index_props_p = ecma_new_collection ();
#if ENABLED (JERRY_BUILTIN_PROXY)
if (array_index_props_p == NULL)
for (uint32_t i = 0; i < len; i++)
{
return ECMA_VALUE_ERROR;
}
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
ecma_string_t *prop_name_p = ecma_new_ecma_string_from_uint32 (i);
uint32_t defined_prop_count = 0;
ecma_property_descriptor_t prop_desc;
ecma_value_t get_desc = ecma_op_object_get_own_property_descriptor (obj_p, prop_name_p, &prop_desc);
ecma_value_t *buffer_p = array_index_props_p->buffer_p;
/* Count properties with name that is array index less than len */
for (uint32_t i = 0; i < array_index_props_p->item_count; i++)
{
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[i]);
uint32_t index = ecma_string_get_array_index (property_name_p);
JERRY_ASSERT (index != ECMA_STRING_NOT_ARRAY_INDEX);
if (index < len)
if (ECMA_IS_VALUE_ERROR (get_desc))
{
defined_prop_count++;
ecma_collection_free (array_index_props_p);
ecma_deref_ecma_string (prop_name_p);
return get_desc;
}
if (ecma_is_value_true (get_desc))
{
ecma_ref_ecma_string (prop_name_p);
ecma_collection_push_back (array_index_props_p, ecma_make_string_value (prop_name_p));
ecma_free_property_descriptor (&prop_desc);
continue;
}
}
uint32_t defined_prop_count = array_index_props_p->item_count;
ecma_value_t ret_value = ECMA_VALUE_ERROR;
uint32_t copied_num = 0;
JMEM_DEFINE_LOCAL_ARRAY (values_buffer, defined_prop_count, ecma_value_t);
buffer_p = array_index_props_p->buffer_p;
ecma_value_t *buffer_p = array_index_props_p->buffer_p;
/* Copy unsorted array into a native c array. */
for (uint32_t i = 0; i < array_index_props_p->item_count; i++)
@@ -1184,8 +1184,7 @@ clean_up:
JERRY_ASSERT (ecma_is_value_empty (ret_value));
/* Undefined properties should be in the back of the array. */
buffer_p = array_index_props_p->buffer_p;
ecma_value_t *buffer_p = array_index_props_p->buffer_p;
for (uint32_t i = 0; i < array_index_props_p->item_count; i++)
{
@@ -54,33 +54,6 @@ ecma_json_has_object_in_stack (ecma_json_occurence_stack_item_t *stack_p, /**< s
return false;
} /* ecma_json_has_object_in_stack */
/**
* Check the string value existance in the collection.
*
* Used by:
* - ecma_builtin_json_stringify step 4.b.ii.5
*
* @return true, if the string is already in the collection.
*/
bool
ecma_has_string_value_in_collection (ecma_collection_t *collection_p, /**< collection */
ecma_string_t *string_p) /**< string */
{
ecma_value_t *buffer_p = collection_p->buffer_p;
for (uint32_t i = 0; i < collection_p->item_count; i++)
{
ecma_string_t *current_p = ecma_get_string_from_value (buffer_p[i]);
if (ecma_compare_ecma_strings (current_p, string_p))
{
return true;
}
}
return false;
} /* ecma_has_string_value_in_collection */
#endif /* ENABLED (JERRY_BUILTIN_JSON) */
/**
@@ -226,42 +226,6 @@ ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, /**< th
return ret_string_p;
} /* ecma_builtin_helper_get_to_locale_string_at_index */
/**
* The Object's 'getOwnPropertyNames' routine.
*
* See also:
* ECMA-262 v5, 15.2.3.4 steps 2-5
*
* @return ecma value - Array of property names.
* Returned value must be freed with ecma_free_value.
*/
ecma_value_t
ecma_builtin_helper_object_get_properties (ecma_object_t *obj_p, /**< object */
uint32_t opts) /**< any combination of ecma_list_properties_options_t */
{
JERRY_ASSERT (obj_p != NULL);
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, opts);
#if ENABLED (JERRY_BUILTIN_PROXY)
if (props_p == NULL)
{
return ECMA_VALUE_ERROR;
}
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
if (props_p->item_count == 0)
{
ecma_collection_destroy (props_p);
return ecma_op_create_array_object (NULL, 0, false);
}
ecma_value_t new_array = ecma_op_create_array_object (props_p->buffer_p, props_p->item_count, false);
ecma_collection_free (props_p);
return new_array;
} /* ecma_builtin_helper_object_get_properties */
/**
* Helper function to normalizing an array index
*
@@ -46,8 +46,6 @@ ecma_builtin_helper_object_to_string (const ecma_value_t this_arg);
ecma_string_t *
ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, uint32_t index);
ecma_value_t
ecma_builtin_helper_object_get_properties (ecma_object_t *obj_p, uint32_t opts);
ecma_value_t
ecma_builtin_helper_array_concat_value (ecma_object_t *obj_p, uint32_t *length_p, ecma_value_t value);
uint32_t
ecma_builtin_helper_array_index_normalize (ecma_value_t arg, uint32_t length, uint32_t *number_p);
@@ -216,7 +214,6 @@ ecma_value_t ecma_builtin_json_parse_buffer (const lit_utf8_byte_t * str_start_p
lit_utf8_size_t string_size);
ecma_value_t ecma_builtin_json_stringify_no_opts (const ecma_value_t value);
bool ecma_json_has_object_in_stack (ecma_json_occurence_stack_item_t *stack_p, ecma_object_t *object_p);
bool ecma_has_string_value_in_collection (ecma_collection_t *collection_p, ecma_string_t *string_p);
ecma_value_t
ecma_builtin_helper_json_create_non_formatted_json (lit_utf8_byte_t left_bracket, lit_utf8_byte_t right_bracket,
@@ -694,7 +694,8 @@ ecma_builtin_json_internalize_property (ecma_object_t *reviver_p, /**< reviver f
/* 3.d */
else
{
ecma_collection_t *props_p = ecma_op_object_get_property_names (object_p, ECMA_LIST_ENUMERABLE);
ecma_collection_t *props_p = ecma_op_object_get_enumerable_property_names (object_p,
ECMA_ENUMERABLE_PROPERTY_KEYS);
JERRY_ASSERT (props_p != NULL);
@@ -983,7 +984,7 @@ ecma_builtin_json_serialize_object (ecma_json_stringify_context_t *context_p, /*
/* 6. */
else
{
property_keys_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_ENUMERABLE);
property_keys_p = ecma_op_object_get_enumerable_property_names (obj_p, ECMA_ENUMERABLE_PROPERTY_KEYS);
#if ENABLED (JERRY_BUILTIN_PROXY)
if (property_keys_p == NULL)
@@ -1573,7 +1574,7 @@ ecma_builtin_json_stringify (ecma_value_t this_arg, /**< 'this' argument */
JERRY_ASSERT (ecma_is_value_string (item));
ecma_string_t *string_p = ecma_get_string_from_value (item);
if (!ecma_has_string_value_in_collection (context.property_list_p, string_p))
if (!ecma_collection_has_string_value (context.property_list_p, string_p))
{
ecma_collection_push_back (context.property_list_p, item);
}
@@ -55,13 +55,15 @@ enum
ECMA_OBJECT_ROUTINE_ASSIGN,
ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_DESCRIPTOR,
ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_DESCRIPTORS,
ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_NAMES,
ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS,
ECMA_OBJECT_ROUTINE_GET_PROTOTYPE_OF,
ECMA_OBJECT_ROUTINE_KEYS,
ECMA_OBJECT_ROUTINE_VALUES,
ECMA_OBJECT_ROUTINE_ENTRIES,
/* These should be in this order. */
ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_NAMES,
ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS,
/* These should be in this order. */
ECMA_OBJECT_ROUTINE_FREEZE,
ECMA_OBJECT_ROUTINE_PREVENT_EXTENSIONS,
@@ -289,40 +291,6 @@ ecma_builtin_object_object_set_proto (ecma_value_t arg1, /**< routine's first ar
} /* ecma_builtin_object_object_set_proto */
#endif /* ENABLED (JERRY_ESNEXT) */
/**
* The Object object's 'getOwnPropertyNames' routine
*
* See also:
* ECMA-262 v5, 15.2.3.4
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_object_object_get_own_property_names (ecma_object_t *obj_p) /**< routine's argument */
{
return ecma_builtin_helper_object_get_properties (obj_p, ECMA_LIST_NO_OPTS);
} /* ecma_builtin_object_object_get_own_property_names */
#if ENABLED (JERRY_ESNEXT)
/**
* The Object object's 'getOwnPropertySymbols' routine
*
* See also:
* ECMA-262 v6, 19.1.2.7
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
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_ONLY);
} /* ecma_builtin_object_object_get_own_property_symbols */
#endif /* ENABLED (JERRY_ESNEXT) */
/**
* SetIntegrityLevel operation
*
@@ -349,20 +317,13 @@ ecma_builtin_object_set_integrity_level (ecma_object_t *obj_p, /**< object */
}
}
else
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
{
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
ecma_op_ordinary_object_prevent_extensions (obj_p);
#if ENABLED (JERRY_BUILTIN_PROXY)
}
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
/* 6. */
uint32_t opts = ECMA_LIST_CONVERT_FAST_ARRAYS;
#if ENABLED (JERRY_ESNEXT)
opts |= ECMA_LIST_SYMBOLS;
#endif /* ENABLED (JERRY_ESNEXT) */
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, opts);
ecma_collection_t *props_p = ecma_op_object_own_property_keys (obj_p);
#if ENABLED (JERRY_BUILTIN_PROXY)
if (props_p == NULL)
@@ -606,12 +567,10 @@ ecma_builtin_object_test_integrity_level (ecma_object_t *obj_p, /**< routine's a
is_extensible = ecma_is_value_true (status);
}
else
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
{
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
is_extensible = ecma_op_ordinary_object_is_extensible (obj_p);
#if ENABLED (JERRY_BUILTIN_PROXY)
}
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
if (is_extensible)
{
@@ -622,7 +581,7 @@ ecma_builtin_object_test_integrity_level (ecma_object_t *obj_p, /**< routine's a
ecma_value_t ret_value = ECMA_VALUE_TRUE;
/* 2. */
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_NO_OPTS);
ecma_collection_t *props_p = ecma_op_object_own_property_keys (obj_p);
#if ENABLED (JERRY_BUILTIN_PROXY)
if (props_p == NULL)
@@ -780,7 +739,7 @@ static ecma_value_t
ecma_builtin_object_object_get_own_property_descriptors (ecma_object_t *obj_p) /**< routine's first argument */
{
/* 2 */
ecma_collection_t *prop_names_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_SYMBOLS);
ecma_collection_t *prop_names_p = ecma_op_object_own_property_keys (obj_p);
#if ENABLED (JERRY_BUILTIN_PROXY)
if (prop_names_p == NULL)
@@ -841,6 +800,7 @@ ecma_builtin_object_object_get_own_property_descriptors (ecma_object_t *obj_p) /
*
* See also:
* ECMA-262 v5, 15.2.3.7
* ECMA-262 v11, 19.1.2.3.1
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
@@ -858,14 +818,9 @@ ecma_builtin_object_object_define_properties (ecma_object_t *obj_p, /**< routine
}
ecma_object_t *props_p = ecma_get_object_from_value (props);
/* 3. */
uint32_t options = ECMA_LIST_CONVERT_FAST_ARRAYS | ECMA_LIST_ENUMERABLE;
#if ENABLED (JERRY_ESNEXT)
options |= ECMA_LIST_SYMBOLS;
#endif /* ENABLED (JERRY_ESNEXT) */
ecma_collection_t *prop_names_p = ecma_op_object_get_property_names (props_p, options);
ecma_collection_t *prop_names_p = ecma_op_object_own_property_keys (props_p);
ecma_value_t ret_value = ECMA_VALUE_ERROR;
#if ENABLED (JERRY_BUILTIN_PROXY)
@@ -881,40 +836,67 @@ ecma_builtin_object_object_define_properties (ecma_object_t *obj_p, /**< routine
/* 4. */
JMEM_DEFINE_LOCAL_ARRAY (property_descriptors, prop_names_p->item_count, ecma_property_descriptor_t);
uint32_t property_descriptor_number = 0;
ecma_collection_t *enum_prop_names = ecma_new_collection ();
/* 5. */
for (uint32_t i = 0; i < prop_names_p->item_count; i++)
{
/* 5.a */
ecma_value_t desc_obj = ecma_op_object_get (props_p, ecma_get_prop_name_from_value (buffer_p[i]));
ecma_string_t *prop_name_p = ecma_get_prop_name_from_value (buffer_p[i]);
if (ECMA_IS_VALUE_ERROR (desc_obj))
ecma_property_descriptor_t prop_desc;
ecma_value_t get_desc = ecma_op_object_get_own_property_descriptor (props_p,
prop_name_p,
&prop_desc);
#if ENABLED (JERRY_ESNEXT)
if (ECMA_IS_VALUE_ERROR (get_desc))
{
goto cleanup;
}
#endif /* ENABLED (JERRY_ESNEXT) */
/* 5.b */
ecma_value_t conv_result = ecma_op_to_property_descriptor (desc_obj,
&property_descriptors[property_descriptor_number]);
property_descriptors[property_descriptor_number].flags |= ECMA_PROP_IS_THROW;
ecma_free_value (desc_obj);
if (ECMA_IS_VALUE_ERROR (conv_result))
if (ecma_is_value_true (get_desc))
{
goto cleanup;
if (prop_desc.flags & ECMA_PROP_IS_ENUMERABLE)
{
ecma_value_t desc_obj = ecma_op_object_get (props_p, prop_name_p);
if (ECMA_IS_VALUE_ERROR (desc_obj))
{
ecma_free_property_descriptor (&prop_desc);
goto cleanup;
}
ecma_value_t conv_result = ecma_op_to_property_descriptor (desc_obj,
&property_descriptors[property_descriptor_number]);
property_descriptors[property_descriptor_number].flags |= ECMA_PROP_IS_THROW;
ecma_free_value (desc_obj);
if (ECMA_IS_VALUE_ERROR (conv_result))
{
ecma_free_property_descriptor (&prop_desc);
goto cleanup;
}
property_descriptor_number++;
ecma_free_value (conv_result);
ecma_ref_ecma_string (prop_name_p);
ecma_collection_push_back (enum_prop_names, buffer_p[i]);
}
ecma_free_property_descriptor (&prop_desc);
}
property_descriptor_number++;
ecma_free_value (conv_result);
}
/* 6. */
for (uint32_t i = 0; i < prop_names_p->item_count; i++)
for (uint32_t i = 0; i < enum_prop_names->item_count; i++)
{
ecma_string_t *prop_name_p = ecma_get_prop_name_from_value (enum_prop_names->buffer_p[i]);
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
ecma_get_prop_name_from_value (buffer_p[i]),
prop_name_p,
&property_descriptors[i]);
if (ECMA_IS_VALUE_ERROR (define_own_prop_ret))
{
@@ -936,6 +918,8 @@ cleanup:
ecma_free_property_descriptor (&property_descriptors[index]);
}
ecma_collection_free (enum_prop_names);
JMEM_FINALIZE_LOCAL_ARRAY (property_descriptors);
ecma_collection_free (prop_names_p);
@@ -1071,8 +1055,8 @@ 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 */
ecma_collection_t *props_p = ecma_op_object_get_property_names (from_obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS
| ECMA_LIST_SYMBOLS);
ecma_collection_t *props_p = ecma_op_object_own_property_keys (from_obj_p);
#if ENABLED (JERRY_BUILTIN_PROXY)
if (props_p == NULL)
{
@@ -1166,6 +1150,71 @@ ecma_builtin_object_object_is (ecma_value_t arg1, /**< routine's first argument
#endif /* ENABLED (JERRY_ESNEXT) */
/**
* GetOwnPropertyKeys abstract method
*
* See also:
* ECMA-262 v11, 19.1.2.11.1
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_op_object_get_own_property_keys (ecma_value_t this_arg, /**< this argument */
uint16_t type) /**< routine type */
{
#if ENABLED (JERRY_ESNEXT)
/* 1. */
ecma_value_t object = ecma_op_to_object (this_arg);
if (ECMA_IS_VALUE_ERROR (object))
{
return object;
}
ecma_object_t *obj_p = ecma_get_object_from_value (object);
/* 2. */
ecma_collection_t *props_p = ecma_op_object_own_property_keys (obj_p);
if (props_p == NULL)
{
ecma_deref_object (obj_p);
return ECMA_VALUE_ERROR;
}
/* 3. */
ecma_collection_t *name_list = ecma_new_collection ();
/* 4. */
for (uint32_t i = 0; i < props_p->item_count; i++)
{
ecma_value_t prop_name = props_p->buffer_p[i];
ecma_string_t *name_p = ecma_get_prop_name_from_value (prop_name);
if ((ecma_prop_name_is_symbol (name_p) && type == ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS)
|| (ecma_is_value_string (prop_name) && type == ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_NAMES))
{
ecma_ref_ecma_string (name_p);
ecma_collection_push_back (name_list, prop_name);
}
}
ecma_value_t result_array = ecma_op_create_array_object (name_list->buffer_p, name_list->item_count, false);
ecma_deref_object (obj_p);
ecma_collection_free (name_list);
#else /* !ENABLED (JERRY_ESNEXT) */
JERRY_UNUSED (type);
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
ecma_collection_t *props_p = ecma_op_object_own_property_keys (obj_p);
ecma_value_t result_array = ecma_op_create_array_object (props_p->buffer_p, props_p->item_count, false);
#endif /* ENABLED (JERRY_ESNEXT) */
ecma_collection_free (props_p);
return result_array;
} /* ecma_op_object_get_own_property_keys */
/**
* Dispatcher of the built-in's routines
*
@@ -1269,22 +1318,12 @@ ecma_builtin_object_dispatch_routine (uint16_t builtin_routine_id, /**< built-in
result = ecma_builtin_object_object_get_prototype_of (obj_p);
break;
}
case ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_NAMES:
{
result = ecma_builtin_object_object_get_own_property_names (obj_p);
break;
}
#if ENABLED (JERRY_ESNEXT)
case ECMA_OBJECT_ROUTINE_ASSIGN:
{
result = ecma_builtin_object_object_assign (obj_p, arguments_list_p + 1, arguments_number - 1);
break;
}
case ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS:
{
result = ecma_builtin_object_object_get_own_property_symbols (obj_p);
break;
}
case ECMA_OBJECT_ROUTINE_ENTRIES:
case ECMA_OBJECT_ROUTINE_VALUES:
#endif /* ENABLED (JERRY_ESNEXT) */
@@ -1329,6 +1368,10 @@ ecma_builtin_object_dispatch_routine (uint16_t builtin_routine_id, /**< built-in
#endif /* ENABLED (JERRY_ESNEXT) */
return result;
}
else if (builtin_routine_id <= ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS)
{
return ecma_op_object_get_own_property_keys (arg1, builtin_routine_id);
}
else if (builtin_routine_id <= ECMA_OBJECT_ROUTINE_SEAL)
{
#if ENABLED (JERRY_ESNEXT)
@@ -165,8 +165,21 @@ ecma_builtin_reflect_dispatch_routine (uint16_t builtin_routine_id, /**< built-i
ecma_object_t *target_p = ecma_get_object_from_value (arguments_list[0]);
/* 2. 3. */
return ecma_builtin_helper_object_get_properties (target_p, ECMA_LIST_SYMBOLS);
/* 2. */
ecma_collection_t *prop_names = ecma_op_object_own_property_keys (target_p);
#if ENABLED (JERRY_BUILTIN_PROXY)
if (prop_names == NULL)
{
return ECMA_VALUE_ERROR;
}
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
/* 3. */
ecma_value_t new_array = ecma_op_create_array_object (prop_names->buffer_p, prop_names->item_count, false);
ecma_collection_free (prop_names);
return new_array;
}
if (builtin_routine_id == ECMA_REFLECT_OBJECT_CONSTRUCT)
+23 -58
View File
@@ -1041,43 +1041,32 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
*/
void
ecma_builtin_routine_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in 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 */
ecma_collection_t *prop_names_p, /**< prop name collection */
ecma_property_counter_t *prop_counter_p) /**< prop counter */
{
JERRY_ASSERT (ecma_get_object_is_builtin (object_p));
JERRY_ASSERT (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION);
JERRY_ASSERT (ecma_builtin_function_is_routine (object_p));
const bool separate_enumerable = (opts & ECMA_LIST_ENUMERABLE) != 0;
const bool is_array_indices_only = (opts & ECMA_LIST_ARRAY_INDICES) != 0;
ecma_collection_t *for_enumerable_p = main_collection_p;
JERRY_UNUSED (for_enumerable_p);
ecma_collection_t *for_non_enumerable_p = separate_enumerable ? non_enum_collection_p : main_collection_p;
if (!is_array_indices_only)
{
#if ENABLED (JERRY_ESNEXT)
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
if (!(ext_func_p->u.built_in.u.builtin_routine.bitset & ECMA_BUILTIN_ROUTINE_LENGTH_INITIALIZED))
{
/* Unintialized 'length' property is non-enumerable (ECMA-262 v6, 19.2.4.1) */
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
}
if (!(ext_func_p->u.built_in.u.builtin_routine.bitset & ECMA_BUILTIN_ROUTINE_NAME_INITIALIZED))
{
/* Unintialized 'name' property is non-enumerable (ECMA-262 v6, 19.2.4.2) */
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_NAME));
}
#else /* !ENABLED (JERRY_ESNEXT) */
/* 'length' property is non-enumerable (ECMA-262 v5, 15) */
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
#endif /* ENABLED (JERRY_ESNEXT) */
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
if (!(ext_func_p->u.built_in.u.builtin_routine.bitset & ECMA_BUILTIN_ROUTINE_LENGTH_INITIALIZED))
{
/* Unintialized 'length' property is non-enumerable (ECMA-262 v6, 19.2.4.1) */
ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
prop_counter_p->string_named_props++;
}
if (!(ext_func_p->u.built_in.u.builtin_routine.bitset & ECMA_BUILTIN_ROUTINE_NAME_INITIALIZED))
{
/* Unintialized 'name' property is non-enumerable (ECMA-262 v6, 19.2.4.2) */
ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_NAME));
prop_counter_p->string_named_props++;
}
#else /* !ENABLED (JERRY_ESNEXT) */
/* 'length' property is non-enumerable (ECMA-262 v5, 15) */
ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
prop_counter_p->string_named_props++;
#endif /* ENABLED (JERRY_ESNEXT) */
} /* ecma_builtin_routine_list_lazy_property_names */
/**
@@ -1088,19 +1077,13 @@ ecma_builtin_routine_list_lazy_property_names (ecma_object_t *object_p, /**< a b
*/
void
ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in 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 */
ecma_collection_t *prop_names_p, /**< prop name collection */
ecma_property_counter_t *prop_counter_p) /**< prop counter */
{
JERRY_ASSERT (ecma_get_object_is_builtin (object_p));
JERRY_ASSERT (ecma_get_object_type (object_p) != ECMA_OBJECT_TYPE_FUNCTION
|| !ecma_builtin_function_is_routine (object_p));
const bool separate_enumerable = (opts & ECMA_LIST_ENUMERABLE) != 0;
const bool is_array_indices_only = (opts & ECMA_LIST_ARRAY_INDICES) != 0;
ecma_built_in_props_t *built_in_props_p;
ecma_object_type_t object_type = ecma_get_object_type (object_p);
@@ -1123,9 +1106,6 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in
uint32_t index = 0;
uint32_t *bitset_p = built_in_props_p->u.instantiated_bitset;
ecma_collection_t *for_non_enumerable_p = (separate_enumerable ? non_enum_collection_p
: main_collection_p);
while (curr_property_p->magic_string_id != LIT_MAGIC_STRING__COUNT)
{
if (index == 32)
@@ -1145,28 +1125,13 @@ 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_ordinary_object_has_own_property (object_p, name_p))
{
ecma_value_t name = ecma_make_magic_string_value ((lit_magic_string_id_t) curr_property_p->magic_string_id);
#if ENABLED (JERRY_ESNEXT)
if (curr_property_p->attributes & ECMA_PROPERTY_FLAG_ENUMERABLE)
{
ecma_collection_push_back (main_collection_p, name);
}
else
#endif /* ENABLED (JERRY_ESNEXT) */
{
ecma_collection_push_back (for_non_enumerable_p, name);
}
ecma_collection_push_back (prop_names_p, name);
prop_counter_p->string_named_props++;
}
curr_property_p++;
@@ -93,14 +93,12 @@ ecma_property_t *
ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, ecma_string_t *string_p);
void
ecma_builtin_routine_list_lazy_property_names (ecma_object_t *object_p,
uint32_t opts,
ecma_collection_t *main_collection_p,
ecma_collection_t *non_enum_collection_p);
ecma_collection_t *prop_names_p,
ecma_property_counter_t *prop_counter_p);
void
ecma_builtin_list_lazy_property_names (ecma_object_t *object_p,
uint32_t opts,
ecma_collection_t *main_collection_p,
ecma_collection_t *non_enum_collection_p);
ecma_collection_t *prop_names_p,
ecma_property_counter_t *prop_counter_p);
bool
ecma_builtin_is (ecma_object_t *obj_p, ecma_builtin_id_t builtin_id);
ecma_object_t *