Rework ecma collection. (#2153)
Greatly simplify the iterator part and make it compatible with 32 bit cpointers. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
committed by
Dániel Bátyai
parent
f833da2c13
commit
b9560b7c70
@@ -1381,8 +1381,8 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
|
||||
JERRY_ASSERT (obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
|
||||
ecma_collection_header_t *ret_p = ecma_new_strings_collection (NULL, 0);
|
||||
ecma_collection_header_t *skipped_non_enumerable_p = ecma_new_strings_collection (NULL, 0);
|
||||
ecma_collection_header_t *ret_p = ecma_new_values_collection (NULL, 0, false);
|
||||
ecma_collection_header_t *skipped_non_enumerable_p = ecma_new_values_collection (NULL, 0, false);
|
||||
|
||||
const ecma_object_type_t type = ecma_get_object_type (obj_p);
|
||||
const bool obj_is_builtin = ecma_get_object_is_builtin (obj_p);
|
||||
@@ -1400,7 +1400,7 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
|
||||
ecma_length_t string_named_properties_count = 0;
|
||||
ecma_length_t array_index_named_properties_count = 0;
|
||||
|
||||
ecma_collection_header_t *prop_names_p = ecma_new_strings_collection (NULL, 0);
|
||||
ecma_collection_header_t *prop_names_p = ecma_new_values_collection (NULL, 0, false);
|
||||
|
||||
if (obj_is_builtin)
|
||||
{
|
||||
@@ -1482,15 +1482,15 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
|
||||
}
|
||||
}
|
||||
|
||||
ecma_collection_iterator_t iter;
|
||||
ecma_collection_iterator_init (&iter, prop_names_p);
|
||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (prop_names_p);
|
||||
|
||||
uint32_t own_names_hashes_bitmap[ECMA_OBJECT_HASH_BITMAP_SIZE / bitmap_row_size];
|
||||
memset (own_names_hashes_bitmap, 0, sizeof (own_names_hashes_bitmap));
|
||||
|
||||
while (ecma_collection_iterator_next (&iter))
|
||||
while (ecma_value_p != NULL)
|
||||
{
|
||||
ecma_string_t *name_p = ecma_get_string_from_value (*iter.current_value_p);
|
||||
ecma_string_t *name_p = ecma_get_string_from_value (*ecma_value_p);
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
|
||||
uint8_t hash = (uint8_t) name_p->hash;
|
||||
uint32_t bitmap_row = (uint32_t) (hash / bitmap_row_size);
|
||||
@@ -1543,13 +1543,14 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
|
||||
|
||||
if ((own_names_hashes_bitmap[bitmap_row] & (1u << bitmap_column)) != 0)
|
||||
{
|
||||
ecma_collection_iterator_init (&iter, prop_names_p);
|
||||
ecma_value_p = ecma_collection_iterator_init (prop_names_p);
|
||||
|
||||
while (ecma_collection_iterator_next (&iter))
|
||||
while (ecma_value_p != NULL)
|
||||
{
|
||||
ecma_string_t *name2_p = ecma_get_string_from_value (*iter.current_value_p);
|
||||
ecma_string_t *current_name_p = ecma_get_string_from_value (*ecma_value_p);
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
|
||||
if (ecma_compare_ecma_strings (name_p, name2_p))
|
||||
if (ecma_compare_ecma_strings (name_p, current_name_p))
|
||||
{
|
||||
is_add = false;
|
||||
break;
|
||||
@@ -1583,10 +1584,12 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
|
||||
prop_iter_p->next_property_cp);
|
||||
}
|
||||
|
||||
ecma_collection_iterator_init (&iter, prop_names_p);
|
||||
while (ecma_collection_iterator_next (&iter))
|
||||
ecma_value_p = ecma_collection_iterator_init (prop_names_p);
|
||||
|
||||
while (ecma_value_p != NULL)
|
||||
{
|
||||
ecma_string_t *name_p = ecma_get_string_from_value (*iter.current_value_p);
|
||||
ecma_string_t *name_p = ecma_get_string_from_value (*ecma_value_p);
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
|
||||
uint32_t index = ecma_string_get_array_index (name_p);
|
||||
|
||||
@@ -1610,10 +1613,12 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
|
||||
uint32_t name_pos = array_index_named_properties_count + string_named_properties_count;
|
||||
uint32_t array_index_name_pos = 0;
|
||||
|
||||
ecma_collection_iterator_init (&iter, prop_names_p);
|
||||
while (ecma_collection_iterator_next (&iter))
|
||||
ecma_value_p = ecma_collection_iterator_init (prop_names_p);
|
||||
|
||||
while (ecma_value_p != NULL)
|
||||
{
|
||||
ecma_string_t *name_p = ecma_get_string_from_value (*iter.current_value_p);
|
||||
ecma_string_t *name_p = ecma_get_string_from_value (*ecma_value_p);
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
|
||||
uint32_t index = ecma_string_get_array_index (name_p);
|
||||
|
||||
@@ -1698,13 +1703,14 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
|
||||
else
|
||||
{
|
||||
/* Name with same hash has already occured. */
|
||||
ecma_collection_iterator_init (&iter, ret_p);
|
||||
ecma_value_p = ecma_collection_iterator_init (ret_p);
|
||||
|
||||
while (ecma_collection_iterator_next (&iter))
|
||||
while (ecma_value_p != NULL)
|
||||
{
|
||||
ecma_string_t *iter_name_p = ecma_get_string_from_value (*iter.current_value_p);
|
||||
ecma_string_t *current_name_p = ecma_get_string_from_value (*ecma_value_p);
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
|
||||
if (ecma_compare_ecma_strings (name_p, iter_name_p))
|
||||
if (ecma_compare_ecma_strings (name_p, current_name_p))
|
||||
{
|
||||
is_append = false;
|
||||
break;
|
||||
@@ -1714,12 +1720,14 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
|
||||
|
||||
if (is_append)
|
||||
{
|
||||
ecma_collection_iterator_init (&iter, skipped_non_enumerable_p);
|
||||
while (ecma_collection_iterator_next (&iter))
|
||||
{
|
||||
ecma_string_t *iter_name_p = ecma_get_string_from_value (*iter.current_value_p);
|
||||
ecma_value_p = ecma_collection_iterator_init (skipped_non_enumerable_p);
|
||||
|
||||
if (ecma_compare_ecma_strings (name_p, iter_name_p))
|
||||
while (ecma_value_p != NULL)
|
||||
{
|
||||
ecma_string_t *current_name_p = ecma_get_string_from_value (*ecma_value_p);
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
|
||||
if (ecma_compare_ecma_strings (name_p, current_name_p))
|
||||
{
|
||||
is_append = false;
|
||||
break;
|
||||
|
||||
@@ -148,12 +148,12 @@ static void
|
||||
ecma_promise_trigger_reactions (ecma_collection_header_t *reactions, /**< lists of reactions */
|
||||
ecma_value_t value) /**< value for resolve or reject */
|
||||
{
|
||||
ecma_collection_iterator_t iter;
|
||||
ecma_collection_iterator_init (&iter, reactions);
|
||||
ecma_value_t *ecma_value_p = ecma_collection_iterator_init (reactions);
|
||||
|
||||
while (ecma_collection_iterator_next (&iter))
|
||||
while (ecma_value_p != NULL)
|
||||
{
|
||||
ecma_enqueue_promise_reaction_job (*iter.current_value_p, value);
|
||||
ecma_enqueue_promise_reaction_job (*ecma_value_p, value);
|
||||
ecma_value_p = ecma_collection_iterator_next (ecma_value_p);
|
||||
}
|
||||
|
||||
ecma_free_values_collection (reactions, false);
|
||||
@@ -175,11 +175,17 @@ ecma_reject_promise (ecma_value_t promise, /**< promise */
|
||||
ecma_promise_set_state (obj_p, ECMA_PROMISE_STATE_REJECTED);
|
||||
ecma_promise_set_result (obj_p, ecma_copy_value_if_not_object (reason));
|
||||
ecma_promise_object_t *promise_p = (ecma_promise_object_t *) obj_p;
|
||||
ecma_promise_trigger_reactions (promise_p->reject_reactions, reason);
|
||||
|
||||
/* GC can be triggered by ecma_new_values_collection so freeing the collection
|
||||
first and creating a new one might cause a heap after use event. */
|
||||
ecma_collection_header_t *reject_reactions = promise_p->reject_reactions;
|
||||
ecma_collection_header_t *fulfill_reactions = promise_p->fulfill_reactions;
|
||||
promise_p->reject_reactions = ecma_new_values_collection (NULL, 0, false);
|
||||
/* Free all fullfill_reactions. */
|
||||
ecma_free_values_collection (promise_p->fulfill_reactions, false);
|
||||
promise_p->fulfill_reactions = ecma_new_values_collection (NULL, 0, false);
|
||||
|
||||
/* Fulfill reactions will never be triggered. */
|
||||
ecma_free_values_collection (fulfill_reactions, false);
|
||||
ecma_promise_trigger_reactions (reject_reactions, reason);
|
||||
} /* ecma_reject_promise */
|
||||
|
||||
/**
|
||||
@@ -198,11 +204,17 @@ ecma_fulfill_promise (ecma_value_t promise, /**< promise */
|
||||
ecma_promise_set_state (obj_p, ECMA_PROMISE_STATE_FULFILLED);
|
||||
ecma_promise_set_result (obj_p, ecma_copy_value_if_not_object (value));
|
||||
ecma_promise_object_t *promise_p = (ecma_promise_object_t *) obj_p;
|
||||
ecma_promise_trigger_reactions (promise_p->fulfill_reactions, value);
|
||||
promise_p->fulfill_reactions = ecma_new_values_collection (NULL, 0, false);
|
||||
/* Free all reject_reactions. */
|
||||
ecma_free_values_collection (promise_p->reject_reactions, false);
|
||||
|
||||
/* GC can be triggered by ecma_new_values_collection so freeing the collection
|
||||
first and creating a new one might cause a heap after use event. */
|
||||
ecma_collection_header_t *reject_reactions = promise_p->reject_reactions;
|
||||
ecma_collection_header_t *fulfill_reactions = promise_p->fulfill_reactions;
|
||||
promise_p->reject_reactions = ecma_new_values_collection (NULL, 0, false);
|
||||
promise_p->fulfill_reactions = ecma_new_values_collection (NULL, 0, false);
|
||||
|
||||
/* Reject reactions will never be triggered. */
|
||||
ecma_free_values_collection (reject_reactions, false);
|
||||
ecma_promise_trigger_reactions (fulfill_reactions, value);
|
||||
} /* ecma_fulfill_promise */
|
||||
|
||||
/**
|
||||
|
||||
@@ -1241,8 +1241,8 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
|
||||
JERRY_ASSERT (ecma_object_class_is (regexp_object_p, LIT_MAGIC_STRING_REGEXP_UL));
|
||||
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) regexp_object_p;
|
||||
re_compiled_code_t *bc_p = ECMA_GET_INTERNAL_VALUE_POINTER (re_compiled_code_t,
|
||||
ext_object_p->u.class_prop.u.value);
|
||||
re_compiled_code_t *bc_p = ECMA_GET_INTERNAL_VALUE_ANY_POINTER (re_compiled_code_t,
|
||||
ext_object_p->u.class_prop.u.value);
|
||||
|
||||
if (bc_p == NULL)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user