Rework ecma collection (#3086)
After this patch the ecma value collection is a resizable buffer of ecma-values where the adjacent elements are allocated next to each other. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
committed by
Zoltan Herczeg
parent
f3d3c34c30
commit
fc30f003ba
@@ -952,17 +952,16 @@ 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_header_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_op_object_get_property_names (obj_p, ECMA_LIST_ARRAY_INDICES);
|
||||
|
||||
uint32_t defined_prop_count = 0;
|
||||
|
||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (array_index_props_p);
|
||||
ecma_value_t *buffer_p = array_index_props_p->buffer_p;
|
||||
|
||||
/* Count properties with name that is array index less than len */
|
||||
while (ecma_value_p != NULL)
|
||||
for (uint32_t i = 0; i < array_index_props_p->item_count; i++)
|
||||
{
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (*ecma_value_p);
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
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);
|
||||
@@ -977,13 +976,12 @@ ecma_builtin_array_prototype_object_sort (ecma_value_t this_arg, /**< this argum
|
||||
uint32_t copied_num = 0;
|
||||
JMEM_DEFINE_LOCAL_ARRAY (values_buffer, defined_prop_count, ecma_value_t);
|
||||
|
||||
ecma_value_p = ecma_collection_iterator_init (array_index_props_p);
|
||||
buffer_p = array_index_props_p->buffer_p;
|
||||
|
||||
/* Copy unsorted array into a native c array. */
|
||||
while (ecma_value_p != NULL)
|
||||
for (uint32_t i = 0; i < array_index_props_p->item_count; i++)
|
||||
{
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (*ecma_value_p);
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
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);
|
||||
@@ -1045,7 +1043,7 @@ clean_up:
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (ret_value))
|
||||
{
|
||||
ecma_free_values_collection (array_index_props_p, 0);
|
||||
ecma_collection_free (array_index_props_p);
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
@@ -1053,12 +1051,11 @@ clean_up:
|
||||
|
||||
/* Undefined properties should be in the back of the array. */
|
||||
|
||||
ecma_value_p = ecma_collection_iterator_init (array_index_props_p);
|
||||
buffer_p = array_index_props_p->buffer_p;
|
||||
|
||||
while (ecma_value_p != NULL)
|
||||
for (uint32_t i = 0; i < array_index_props_p->item_count; i++)
|
||||
{
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (*ecma_value_p);
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
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);
|
||||
@@ -1069,13 +1066,13 @@ clean_up:
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (del_value))
|
||||
{
|
||||
ecma_free_values_collection (array_index_props_p, 0);
|
||||
ecma_collection_free (array_index_props_p);
|
||||
return del_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ecma_free_values_collection (array_index_props_p, 0);
|
||||
ecma_collection_free (array_index_props_p);
|
||||
|
||||
return ecma_copy_value (this_arg);
|
||||
} /* ecma_builtin_array_prototype_object_sort */
|
||||
|
||||
@@ -63,21 +63,19 @@ ecma_json_has_object_in_stack (ecma_json_occurence_stack_item_t *stack_p, /**< s
|
||||
* @return true, if the string is already in the collection.
|
||||
*/
|
||||
bool
|
||||
ecma_has_string_value_in_collection (ecma_collection_header_t *collection_p, /**< collection */
|
||||
ecma_has_string_value_in_collection (ecma_collection_t *collection_p, /**< collection */
|
||||
ecma_string_t *string_p) /**< string */
|
||||
{
|
||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (collection_p);
|
||||
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||
|
||||
while (ecma_value_p != NULL)
|
||||
for (uint32_t i = 0; i < collection_p->item_count; i++)
|
||||
{
|
||||
ecma_string_t *current_p = ecma_get_string_from_value (*ecma_value_p);
|
||||
ecma_string_t *current_p = ecma_get_string_from_value (buffer_p[i]);
|
||||
|
||||
if (ecma_compare_ecma_strings (current_p, string_p))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -278,29 +278,22 @@ ecma_builtin_helper_object_get_properties (ecma_object_t *obj_p, /**< object */
|
||||
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (new_array));
|
||||
ecma_object_t *new_array_p = ecma_get_object_from_value (new_array);
|
||||
|
||||
uint32_t index = 0;
|
||||
|
||||
ecma_collection_header_t *props_p = ecma_op_object_get_property_names (obj_p, opts);
|
||||
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, opts);
|
||||
|
||||
if (props_p->item_count == 0)
|
||||
{
|
||||
ecma_free_values_collection (props_p, 0);
|
||||
ecma_collection_destroy (props_p);
|
||||
return new_array;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (((ecma_extended_object_t *) new_array_p)->u.array.is_fast_mode);
|
||||
|
||||
ecma_value_t *buffer_p = props_p->buffer_p;
|
||||
ecma_value_t *values_p = ecma_fast_array_extend (new_array_p, props_p->item_count);
|
||||
|
||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (props_p);
|
||||
memcpy (values_p, buffer_p, props_p->item_count * sizeof (ecma_value_t));
|
||||
|
||||
while (ecma_value_p != NULL)
|
||||
{
|
||||
values_p[index++] = ecma_copy_value_if_not_object (*ecma_value_p);
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
}
|
||||
|
||||
ecma_free_values_collection (props_p, 0);
|
||||
ecma_collection_free_objects (props_p);
|
||||
|
||||
return new_array;
|
||||
} /* ecma_builtin_helper_object_get_properties */
|
||||
|
||||
@@ -153,7 +153,7 @@ typedef struct struct_ecma_json_occurence_stack_item_t
|
||||
typedef struct
|
||||
{
|
||||
/** Collection for property keys. */
|
||||
ecma_collection_header_t *property_list_p;
|
||||
ecma_collection_t *property_list_p;
|
||||
|
||||
/** Collection for traversing objects. */
|
||||
ecma_json_occurence_stack_item_t *occurence_stack_last_p;
|
||||
@@ -175,15 +175,11 @@ 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_string_from_object (const ecma_value_t arg1);
|
||||
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_header_t *collection_p, ecma_string_t *string_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_formatted_json (lit_utf8_byte_t left_bracket, lit_utf8_byte_t right_bracket,
|
||||
ecma_string_t *stepback_p, ecma_collection_header_t *partial_p,
|
||||
ecma_json_stringify_context_t *context_p);
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_json_create_non_formatted_json (lit_utf8_byte_t left_bracket, lit_utf8_byte_t right_bracket,
|
||||
ecma_collection_header_t *partial_p);
|
||||
ecma_collection_t *partial_p);
|
||||
#endif /* ENABLED (JERRY_BUILTIN_JSON) */
|
||||
|
||||
/* ecma-builtin-helper-error.c */
|
||||
|
||||
@@ -636,15 +636,14 @@ ecma_builtin_json_internalize_property (ecma_object_t *reviver_p, /**< reviver f
|
||||
{
|
||||
ecma_object_t *object_p = ecma_get_object_from_value (value);
|
||||
|
||||
ecma_collection_header_t *props_p = ecma_op_object_get_property_names (object_p, ECMA_LIST_ENUMERABLE);
|
||||
ecma_collection_t *props_p = ecma_op_object_get_property_names (object_p, ECMA_LIST_ENUMERABLE);
|
||||
|
||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (props_p);
|
||||
ecma_value_t *buffer_p = props_p->buffer_p;
|
||||
|
||||
/* 3.d.iii */
|
||||
while (ecma_value_p != NULL)
|
||||
for (uint32_t i = 0; i < props_p->item_count; i++)
|
||||
{
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (*ecma_value_p);
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[i]);
|
||||
|
||||
/* 3.d.iii.1 */
|
||||
ecma_value_t result = ecma_builtin_json_internalize_property (reviver_p, object_p, property_name_p);
|
||||
@@ -652,7 +651,7 @@ ecma_builtin_json_internalize_property (ecma_object_t *reviver_p, /**< reviver f
|
||||
/* 3.d.iii.2 */
|
||||
if (ECMA_IS_VALUE_ERROR (result))
|
||||
{
|
||||
ecma_free_values_collection (props_p, 0);
|
||||
ecma_collection_free (props_p);
|
||||
ecma_deref_object (object_p);
|
||||
|
||||
return result;
|
||||
@@ -676,7 +675,7 @@ ecma_builtin_json_internalize_property (ecma_object_t *reviver_p, /**< reviver f
|
||||
}
|
||||
}
|
||||
|
||||
ecma_free_values_collection (props_p, 0);
|
||||
ecma_collection_free (props_p);
|
||||
}
|
||||
|
||||
ecma_value_t arguments_list[2];
|
||||
@@ -898,7 +897,7 @@ ecma_builtin_json_serialize_object (ecma_json_stringify_context_t *context_p, /*
|
||||
const bool has_gap = !ecma_compare_ecma_string_to_magic_id (context_p->gap_str_p, LIT_MAGIC_STRING__EMPTY);
|
||||
const lit_utf8_size_t separator_size = ecma_stringbuilder_get_size (&context_p->indent_builder);
|
||||
|
||||
ecma_collection_header_t *property_keys_p;
|
||||
ecma_collection_t *property_keys_p;
|
||||
/* 5. */
|
||||
if (context_p->property_list_p->item_count > 0)
|
||||
{
|
||||
@@ -911,14 +910,14 @@ ecma_builtin_json_serialize_object (ecma_json_stringify_context_t *context_p, /*
|
||||
}
|
||||
|
||||
/* 8. */
|
||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (property_keys_p);
|
||||
ecma_value_t *buffer_p = property_keys_p->buffer_p;
|
||||
|
||||
ecma_stringbuilder_append_byte (&context_p->result_builder, LIT_CHAR_LEFT_BRACE);
|
||||
const lit_utf8_size_t left_brace = ecma_stringbuilder_get_size (&context_p->result_builder);
|
||||
lit_utf8_size_t last_prop = left_brace;
|
||||
|
||||
ecma_value_t result = ECMA_VALUE_EMPTY;
|
||||
while (ecma_value_p != NULL)
|
||||
|
||||
for (uint32_t i = 0; i < property_keys_p->item_count; i++)
|
||||
{
|
||||
if (has_gap)
|
||||
{
|
||||
@@ -927,7 +926,7 @@ ecma_builtin_json_serialize_object (ecma_json_stringify_context_t *context_p, /*
|
||||
separator_size);
|
||||
}
|
||||
|
||||
ecma_string_t *key_p = ecma_get_string_from_value (*ecma_value_p);
|
||||
ecma_string_t *key_p = ecma_get_string_from_value (buffer_p[i]);
|
||||
ecma_builtin_json_quote (&context_p->result_builder, key_p);
|
||||
ecma_stringbuilder_append_byte (&context_p->result_builder, LIT_CHAR_COLON);
|
||||
|
||||
@@ -958,8 +957,6 @@ ecma_builtin_json_serialize_object (ecma_json_stringify_context_t *context_p, /*
|
||||
/* The property should not be appended, we must backtrack. */
|
||||
ecma_stringbuilder_revert (&context_p->result_builder, last_prop);
|
||||
}
|
||||
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
}
|
||||
|
||||
if (last_prop != left_brace)
|
||||
@@ -988,7 +985,7 @@ ecma_builtin_json_serialize_object (ecma_json_stringify_context_t *context_p, /*
|
||||
cleanup:
|
||||
if (context_p->property_list_p->item_count == 0)
|
||||
{
|
||||
ecma_free_values_collection (property_keys_p, 0);
|
||||
ecma_collection_free (property_keys_p);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -1334,7 +1331,7 @@ ecma_builtin_json_string_from_object (const ecma_value_t arg1) /**< object argum
|
||||
ecma_json_stringify_context_t context;
|
||||
context.occurence_stack_last_p = NULL;
|
||||
context.indent_builder = ecma_stringbuilder_create ();
|
||||
context.property_list_p = ecma_new_values_collection ();
|
||||
context.property_list_p = ecma_new_collection ();
|
||||
context.replacer_function_p = NULL;
|
||||
context.gap_str_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
|
||||
|
||||
@@ -1342,7 +1339,7 @@ ecma_builtin_json_string_from_object (const ecma_value_t arg1) /**< object argum
|
||||
|
||||
ecma_deref_ecma_string (context.gap_str_p);
|
||||
ecma_stringbuilder_destroy (&context.indent_builder);
|
||||
ecma_free_values_collection (context.property_list_p, 0);
|
||||
ecma_collection_free (context.property_list_p);
|
||||
return ret_value;
|
||||
} /*ecma_builtin_json_string_from_object*/
|
||||
|
||||
@@ -1365,7 +1362,7 @@ ecma_builtin_json_stringify (ecma_value_t this_arg, /**< 'this' argument */
|
||||
|
||||
ecma_json_stringify_context_t context;
|
||||
context.replacer_function_p = NULL;
|
||||
context.property_list_p = ecma_new_values_collection ();
|
||||
context.property_list_p = ecma_new_collection ();
|
||||
|
||||
/* 4. */
|
||||
if (ecma_is_value_object (arg2))
|
||||
@@ -1393,7 +1390,7 @@ ecma_builtin_json_stringify (ecma_value_t this_arg, /**< 'this' argument */
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (value))
|
||||
{
|
||||
ecma_free_values_collection (context.property_list_p, 0);
|
||||
ecma_collection_free (context.property_list_p);
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -1422,7 +1419,7 @@ ecma_builtin_json_stringify (ecma_value_t this_arg, /**< 'this' argument */
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (str_val))
|
||||
{
|
||||
ecma_free_values_collection (context.property_list_p, 0);
|
||||
ecma_collection_free (context.property_list_p);
|
||||
ecma_free_value (value);
|
||||
return str_val;
|
||||
}
|
||||
@@ -1440,7 +1437,7 @@ ecma_builtin_json_stringify (ecma_value_t this_arg, /**< 'this' argument */
|
||||
|
||||
if (!ecma_has_string_value_in_collection (context.property_list_p, string_p))
|
||||
{
|
||||
ecma_append_to_values_collection (context.property_list_p, item, ECMA_COLLECTION_NO_COPY);
|
||||
ecma_collection_push_back (context.property_list_p, item);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1468,7 +1465,7 @@ ecma_builtin_json_stringify (ecma_value_t this_arg, /**< 'this' argument */
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (value))
|
||||
{
|
||||
ecma_free_values_collection (context.property_list_p, 0);
|
||||
ecma_collection_free (context.property_list_p);
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -1481,7 +1478,7 @@ ecma_builtin_json_stringify (ecma_value_t this_arg, /**< 'this' argument */
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (value))
|
||||
{
|
||||
ecma_free_values_collection (context.property_list_p, 0);
|
||||
ecma_collection_free (context.property_list_p);
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -1554,7 +1551,7 @@ ecma_builtin_json_stringify (ecma_value_t this_arg, /**< 'this' argument */
|
||||
|
||||
ecma_deref_ecma_string (context.gap_str_p);
|
||||
ecma_stringbuilder_destroy (&context.indent_builder);
|
||||
ecma_free_values_collection (context.property_list_p, 0);
|
||||
ecma_collection_free (context.property_list_p);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_json_stringify */
|
||||
|
||||
@@ -321,14 +321,13 @@ ecma_builtin_object_object_get_own_property_symbols (ecma_object_t *obj_p) /**<
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_object_seal (ecma_object_t *obj_p) /**< routine's argument */
|
||||
{
|
||||
ecma_collection_header_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS);
|
||||
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS);
|
||||
|
||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (props_p);
|
||||
ecma_value_t *buffer_p = props_p->buffer_p;
|
||||
|
||||
while (ecma_value_p != NULL)
|
||||
for (uint32_t i = 0; i < props_p->item_count; i++)
|
||||
{
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (*ecma_value_p);
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[i]);
|
||||
|
||||
/* 2.a */
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
@@ -351,14 +350,14 @@ ecma_builtin_object_object_seal (ecma_object_t *obj_p) /**< routine's argument *
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (define_own_prop_ret))
|
||||
{
|
||||
ecma_free_values_collection (props_p, 0);
|
||||
ecma_collection_free (props_p);
|
||||
return define_own_prop_ret;
|
||||
}
|
||||
|
||||
ecma_free_value (define_own_prop_ret);
|
||||
}
|
||||
|
||||
ecma_free_values_collection (props_p, 0);
|
||||
ecma_collection_free (props_p);
|
||||
|
||||
/* 3. */
|
||||
ecma_set_object_extensible (obj_p, false);
|
||||
@@ -380,14 +379,13 @@ ecma_builtin_object_object_seal (ecma_object_t *obj_p) /**< routine's argument *
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_object_freeze (ecma_object_t *obj_p) /**< routine's argument */
|
||||
{
|
||||
ecma_collection_header_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS);
|
||||
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS);
|
||||
|
||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (props_p);
|
||||
ecma_value_t *buffer_p = props_p->buffer_p;
|
||||
|
||||
while (ecma_value_p != NULL)
|
||||
for (uint32_t i = 0; i < props_p->item_count; i++)
|
||||
{
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (*ecma_value_p);
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[i]);
|
||||
|
||||
/* 2.a */
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
@@ -417,14 +415,14 @@ ecma_builtin_object_object_freeze (ecma_object_t *obj_p) /**< routine's argument
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (define_own_prop_ret))
|
||||
{
|
||||
ecma_free_values_collection (props_p, 0);
|
||||
ecma_collection_free (props_p);
|
||||
return define_own_prop_ret;
|
||||
}
|
||||
|
||||
ecma_free_value (define_own_prop_ret);
|
||||
}
|
||||
|
||||
ecma_free_values_collection (props_p, 0);
|
||||
ecma_collection_free (props_p);
|
||||
|
||||
/* 3. */
|
||||
ecma_set_object_extensible (obj_p, false);
|
||||
@@ -478,14 +476,13 @@ ecma_builtin_object_frozen_or_sealed_helper (ecma_object_t *obj_p, /**< routine'
|
||||
ecma_value_t ret_value = ECMA_VALUE_TRUE;
|
||||
|
||||
/* 2. */
|
||||
ecma_collection_header_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_NO_OPTS);
|
||||
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_NO_OPTS);
|
||||
|
||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (props_p);
|
||||
ecma_value_t *buffer_p = props_p->buffer_p;
|
||||
|
||||
while (ecma_value_p != NULL)
|
||||
for (uint32_t i = 0; i < props_p->item_count; i++)
|
||||
{
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (*ecma_value_p);
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[i]);
|
||||
|
||||
/* 2.a */
|
||||
ecma_property_t property = ecma_op_object_get_own_property (obj_p,
|
||||
@@ -510,7 +507,7 @@ ecma_builtin_object_frozen_or_sealed_helper (ecma_object_t *obj_p, /**< routine'
|
||||
}
|
||||
}
|
||||
|
||||
ecma_free_values_collection (props_p, 0);
|
||||
ecma_collection_free (props_p);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_frozen_or_sealed_helper */
|
||||
@@ -597,21 +594,20 @@ ecma_builtin_object_object_define_properties (ecma_object_t *obj_p, /**< routine
|
||||
|
||||
ecma_object_t *props_p = ecma_get_object_from_value (props);
|
||||
/* 3. */
|
||||
ecma_collection_header_t *prop_names_p = ecma_op_object_get_property_names (props_p, ECMA_LIST_CONVERT_FAST_ARRAYS
|
||||
| ECMA_LIST_ENUMERABLE);
|
||||
uint32_t property_number = prop_names_p->item_count;
|
||||
ecma_collection_t *prop_names_p = ecma_op_object_get_property_names (props_p, ECMA_LIST_CONVERT_FAST_ARRAYS
|
||||
| ECMA_LIST_ENUMERABLE);
|
||||
ecma_value_t ret_value = ECMA_VALUE_ERROR;
|
||||
|
||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (prop_names_p);
|
||||
ecma_value_t *buffer_p = prop_names_p->buffer_p;
|
||||
|
||||
/* 4. */
|
||||
JMEM_DEFINE_LOCAL_ARRAY (property_descriptors, property_number, ecma_property_descriptor_t);
|
||||
JMEM_DEFINE_LOCAL_ARRAY (property_descriptors, prop_names_p->item_count, ecma_property_descriptor_t);
|
||||
uint32_t property_descriptor_number = 0;
|
||||
|
||||
while (ecma_value_p != NULL)
|
||||
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_string_from_value (*ecma_value_p));
|
||||
ecma_value_t desc_obj = ecma_op_object_get (props_p, ecma_get_string_from_value (buffer_p[i]));
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (desc_obj))
|
||||
{
|
||||
@@ -634,26 +630,22 @@ ecma_builtin_object_object_define_properties (ecma_object_t *obj_p, /**< routine
|
||||
property_descriptor_number++;
|
||||
|
||||
ecma_free_value (conv_result);
|
||||
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
}
|
||||
|
||||
/* 6. */
|
||||
ecma_value_p = ecma_collection_iterator_init (prop_names_p);
|
||||
buffer_p = prop_names_p->buffer_p;
|
||||
|
||||
for (uint32_t index = 0; index < property_number; index++)
|
||||
for (uint32_t i = 0; i < prop_names_p->item_count; i++)
|
||||
{
|
||||
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
|
||||
ecma_get_string_from_value (*ecma_value_p),
|
||||
&property_descriptors[index]);
|
||||
ecma_get_string_from_value (buffer_p[i]),
|
||||
&property_descriptors[i]);
|
||||
if (ECMA_IS_VALUE_ERROR (define_own_prop_ret))
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ecma_free_value (define_own_prop_ret);
|
||||
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
}
|
||||
|
||||
ecma_ref_object (obj_p);
|
||||
@@ -670,7 +662,7 @@ cleanup:
|
||||
|
||||
JMEM_FINALIZE_LOCAL_ARRAY (property_descriptors);
|
||||
|
||||
ecma_free_values_collection (prop_names_p, 0);
|
||||
ecma_collection_free (prop_names_p);
|
||||
|
||||
ecma_deref_object (props_p);
|
||||
|
||||
@@ -821,14 +813,14 @@ ecma_builtin_object_object_assign (const ecma_value_t arguments_list_p[], /**< a
|
||||
|
||||
/* 5.b.iii */
|
||||
/* TODO: extends this collection if symbols will be supported */
|
||||
ecma_collection_header_t *props_p = ecma_op_object_get_property_names (from_obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS
|
||||
| ECMA_LIST_ENUMERABLE);
|
||||
ecma_collection_t *props_p = ecma_op_object_get_property_names (from_obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS
|
||||
| ECMA_LIST_ENUMERABLE);
|
||||
|
||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (props_p);
|
||||
ecma_value_t *buffer_p = props_p->buffer_p;
|
||||
|
||||
while (ecma_value_p != NULL && ecma_is_value_empty (ret_value))
|
||||
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 (*ecma_value_p);
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[j]);
|
||||
|
||||
/* 5.c.i-ii */
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
@@ -866,12 +858,10 @@ ecma_builtin_object_object_assign (const ecma_value_t arguments_list_p[], /**< a
|
||||
ecma_free_value (prop_value);
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
}
|
||||
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
}
|
||||
|
||||
ecma_deref_object (from_obj_p);
|
||||
ecma_free_values_collection (props_p, 0);
|
||||
ecma_collection_free (props_p);
|
||||
}
|
||||
|
||||
/* 6. */
|
||||
|
||||
@@ -898,24 +898,22 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in
|
||||
* properties,
|
||||
* false - list all properties into main collection.
|
||||
*/
|
||||
ecma_collection_header_t *main_collection_p, /**< 'main' collection */
|
||||
ecma_collection_header_t *non_enum_collection_p) /**< skipped 'non-enumerable'
|
||||
* collection */
|
||||
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));
|
||||
|
||||
if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION
|
||||
&& ecma_builtin_function_is_routine (object_p))
|
||||
{
|
||||
ecma_collection_header_t *for_enumerable_p = main_collection_p;
|
||||
ecma_collection_t *for_enumerable_p = main_collection_p;
|
||||
JERRY_UNUSED (for_enumerable_p);
|
||||
|
||||
ecma_collection_header_t *for_non_enumerable_p = separate_enumerable ? non_enum_collection_p : main_collection_p;
|
||||
ecma_collection_t *for_non_enumerable_p = separate_enumerable ? non_enum_collection_p : main_collection_p;
|
||||
|
||||
/* 'length' property is non-enumerable (ECMA-262 v5, 15) */
|
||||
ecma_append_to_values_collection (for_non_enumerable_p,
|
||||
ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH),
|
||||
0);
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -941,7 +939,7 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in
|
||||
ecma_length_t index = 0;
|
||||
uint32_t *bitset_p = built_in_props_p->instantiated_bitset;
|
||||
|
||||
ecma_collection_header_t *for_non_enumerable_p = (separate_enumerable ? non_enum_collection_p
|
||||
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)
|
||||
@@ -969,11 +967,9 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in
|
||||
{
|
||||
ecma_value_t name = ecma_make_magic_string_value ((lit_magic_string_id_t) curr_property_p->magic_string_id);
|
||||
|
||||
ecma_append_to_values_collection (for_non_enumerable_p, name, 0);
|
||||
ecma_collection_push_back (for_non_enumerable_p, name);
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string (name_p);
|
||||
|
||||
curr_property_p++;
|
||||
index++;
|
||||
}
|
||||
|
||||
@@ -92,8 +92,8 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, ecma_string_t
|
||||
void
|
||||
ecma_builtin_list_lazy_property_names (ecma_object_t *object_p,
|
||||
bool separate_enumerable,
|
||||
ecma_collection_header_t *main_collection_p,
|
||||
ecma_collection_header_t *non_enum_collection_p);
|
||||
ecma_collection_t *main_collection_p,
|
||||
ecma_collection_t *non_enum_collection_p);
|
||||
bool
|
||||
ecma_builtin_is (ecma_object_t *obj_p, ecma_builtin_id_t builtin_id);
|
||||
ecma_object_t *
|
||||
|
||||
Reference in New Issue
Block a user