From 37ebd20a728585bcbd301165c5fc2d37b81cf68b Mon Sep 17 00:00:00 2001 From: Zoltan Herczeg Date: Fri, 17 Jun 2016 04:32:53 -0700 Subject: [PATCH] Remove LIST_LAZY_PROPERTY_NAMES_ROUTINE_NAME macro function. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com --- ...a-builtin-internal-routines-template.inc.h | 125 ----------------- .../builtin-objects/ecma-builtins-internal.h | 7 +- .../ecma/builtin-objects/ecma-builtins.c | 130 ++++++++++-------- 3 files changed, 74 insertions(+), 188 deletions(-) diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-internal-routines-template.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-internal-routines-template.inc.h index 2ff6ba3375..e6899ebc37 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-internal-routines-template.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-internal-routines-template.inc.h @@ -30,8 +30,6 @@ #define PROPERTY_DESCRIPTOR_LIST_NAME \ PASTE (PASTE (ecma_builtin_, BUILTIN_UNDERSCORED_ID), _property_descriptor_list) -#define LIST_LAZY_PROPERTY_NAMES_ROUTINE_NAME \ - PASTE (PASTE (ecma_builtin_, BUILTIN_UNDERSCORED_ID), _list_lazy_property_names) #define DISPATCH_ROUTINE_ROUTINE_NAME \ PASTE (PASTE (ecma_builtin_, BUILTIN_UNDERSCORED_ID), _dispatch_routine) @@ -52,19 +50,6 @@ #undef ROUTINE_ARG_LIST_0 #undef ROUTINE_ARG -#define ECMA_BUILTIN_PROPERTY_NAMES \ - PASTE (PASTE (ecma_builtin_property_names, _), BUILTIN_UNDERSCORED_ID) - -static const lit_magic_string_id_t ECMA_BUILTIN_PROPERTY_NAMES[] = -{ -#define SIMPLE_VALUE(name, simple_value, prop_attributes) name, -#define NUMBER_VALUE(name, number_value, prop_attributes) name, -#define STRING_VALUE(name, magic_string_id, prop_attributes) name, -#define OBJECT_VALUE(name, obj_builtin_id, prop_attributes) name, -#define ROUTINE(name, c_function_name, args_number, length_prop_value) name, -#include BUILTIN_INC_HEADER_NAME -}; - #define ECMA_BUILTIN_PROPERTY_NAME_INDEX(name) \ PASTE (PASTE (PASTE (PASTE (ecma_builtin_property_names, _), BUILTIN_UNDERSCORED_ID), _), name) @@ -132,114 +117,6 @@ const ecma_builtin_property_descriptor_t PROPERTY_DESCRIPTOR_LIST_NAME[] = } }; -/** - * List names of the built-in object's lazy instantiated properties - * - * See also: - * TRY_TO_INSTANTIATE_PROPERTY_ROUTINE_NAME - * - * @return string values collection - */ -void -LIST_LAZY_PROPERTY_NAMES_ROUTINE_NAME (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. */ - ecma_collection_header_t *main_collection_p, /**< 'main' collection */ - ecma_collection_header_t *non_enum_collection_p) /**< skipped 'non-enumerable' - collection */ -{ - ecma_collection_header_t *for_enumerable_p = main_collection_p; - (void) for_enumerable_p; - - ecma_collection_header_t *for_non_enumerable_p = separate_enumerable ? non_enum_collection_p : main_collection_p; - -#define OBJECT_ID(builtin_id) const ecma_builtin_id_t builtin_object_id = builtin_id; -#include BUILTIN_INC_HEADER_NAME - - JERRY_ASSERT (ecma_builtin_is (object_p, builtin_object_id)); - - const ecma_length_t properties_number = (ecma_length_t) (sizeof (ECMA_BUILTIN_PROPERTY_NAMES) / - sizeof (ECMA_BUILTIN_PROPERTY_NAMES[0])); - - for (ecma_length_t index = 0; - index < properties_number; - index++) - { - lit_magic_string_id_t name = ECMA_BUILTIN_PROPERTY_NAMES[index]; - - uint32_t bit; - ecma_internal_property_id_t mask_prop_id; - - if (index >= 32) - { - mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63; - bit = (uint32_t) 1u << (index - 32); - } - else - { - mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31; - bit = (uint32_t) 1u << index; - } - - ecma_property_t *mask_prop_p = ecma_find_internal_property (object_p, mask_prop_id); - bool is_instantiated = false; - if (mask_prop_p == NULL) - { - is_instantiated = true; - } - else - { - uint32_t bit_mask = ecma_get_internal_property_value (mask_prop_p); - - if (bit_mask & bit) - { - is_instantiated = true; - } - else - { - is_instantiated = false; - } - } - - bool is_existing; - - ecma_string_t *name_p = ecma_get_magic_string (name); - - if (!is_instantiated) - { - /* will be instantiated upon first request */ - is_existing = true; - } - else - { - if (ecma_op_object_get_own_property (object_p, name_p) == NULL) - { - is_existing = false; - } - else - { - is_existing = true; - } - } - - if (is_existing) - { - ecma_append_to_values_collection (for_non_enumerable_p, - ecma_make_string_value (name_p), - true); - } - - ecma_deref_ecma_string (name_p); - } -} /* LIST_LAZY_PROPERTY_NAMES_ROUTINE_NAME */ - - /** * Dispatcher of the built-in's routines * @@ -294,9 +171,7 @@ DISPATCH_ROUTINE_ROUTINE_NAME (uint16_t builtin_routine_id, /**< built-in wide r #undef PASTE_ #undef PASTE #undef PROPERTY_DESCRIPTOR_LIST_NAME -#undef LIST_LAZY_PROPERTY_NAMES_ROUTINE_NAME #undef DISPATCH_ROUTINE_ROUTINE_NAME #undef BUILTIN_UNDERSCORED_ID #undef BUILTIN_INC_HEADER_NAME -#undef ECMA_BUILTIN_PROPERTY_NAMES #undef ECMA_BUILTIN_PROPERTY_NAME_INDEX diff --git a/jerry-core/ecma/builtin-objects/ecma-builtins-internal.h b/jerry-core/ecma/builtin-objects/ecma-builtins-internal.h index 301dc8d241..964f03a256 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtins-internal.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtins-internal.h @@ -123,12 +123,7 @@ extern ecma_value_t \ ecma_builtin_ ## lowercase_name ## _dispatch_routine (uint16_t builtin_routine_id, \ ecma_value_t this_arg_value, \ const ecma_value_t [], \ - ecma_length_t); \ -extern void \ -ecma_builtin_ ## lowercase_name ## _list_lazy_property_names (ecma_object_t *, \ - bool, \ - ecma_collection_header_t *, \ - ecma_collection_header_t *); + ecma_length_t); #include "ecma-builtins.inc.h" #endif /* !ECMA_BUILTINS_INTERNAL_H */ diff --git a/jerry-core/ecma/builtin-objects/ecma-builtins.c b/jerry-core/ecma/builtin-objects/ecma-builtins.c index 545642b365..69135b6f2e 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtins.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtins.c @@ -270,6 +270,20 @@ ecma_finalize_builtins (void) } } /* ecma_finalize_builtins */ +typedef const ecma_builtin_property_descriptor_t *ecma_builtin_property_list_reference_t; + +static const ecma_builtin_property_list_reference_t ecma_builtin_property_list_references[] = +{ +#define BUILTIN(builtin_id, \ + object_type, \ + object_prototype_builtin_id, \ + is_extensible, \ + is_static, \ + lowercase_name) \ + ecma_builtin_ ## lowercase_name ## _property_descriptor_list, +#include "ecma-builtins.inc.h" +}; + /** * If the property's name is one of built-in properties of the object * that is not instantiated yet, instantiate the property and @@ -338,31 +352,11 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object * ECMA_INTERNAL_PROPERTY_BUILT_IN_ID); ecma_builtin_id_t builtin_id = (ecma_builtin_id_t) ecma_get_internal_property_value (built_in_id_prop_p); - const ecma_builtin_property_descriptor_t *property_list_p = NULL; + JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT); JERRY_ASSERT (ecma_builtin_is (object_p, builtin_id)); - switch (builtin_id) - { -#define BUILTIN(builtin_id, \ - object_type, \ - object_prototype_builtin_id, \ - is_extensible, \ - is_static, \ - lowercase_name) \ - case builtin_id: \ - { \ - property_list_p = ecma_builtin_ ## lowercase_name ## _property_descriptor_list; \ - break; \ - } -#include "ecma-builtins.inc.h" - - default: - { - JERRY_UNREACHABLE (); - break; - } - } + const ecma_builtin_property_descriptor_t *property_list_p = ecma_builtin_property_list_references[builtin_id]; const ecma_builtin_property_descriptor_t *curr_property_p = property_list_p; @@ -379,42 +373,42 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object * JERRY_ASSERT (index < 64); - uint32_t bit; + uint32_t bit_for_index; ecma_internal_property_id_t mask_prop_id; if (likely (index < 32)) { mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31; - bit = (uint32_t) 1u << index; + bit_for_index = (uint32_t) 1u << index; } else { mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63; - bit = (uint32_t) 1u << (index - 32); + bit_for_index = (uint32_t) 1u << (index - 32); } ecma_property_t *mask_prop_p = ecma_find_internal_property (object_p, mask_prop_id); - uint32_t bit_mask; + uint32_t instantiated_bitset; if (mask_prop_p == NULL) { mask_prop_p = ecma_create_internal_property (object_p, mask_prop_id); - bit_mask = 0; + instantiated_bitset = 0; } else { - bit_mask = ecma_get_internal_property_value (mask_prop_p); + instantiated_bitset = ecma_get_internal_property_value (mask_prop_p); - if (bit_mask & bit) + if (instantiated_bitset & bit_for_index) { /* This property was instantiated before. */ return NULL; } } - bit_mask |= bit; + instantiated_bitset |= bit_for_index; - ecma_set_internal_property_value (mask_prop_p, bit_mask); + ecma_set_internal_property_value (mask_prop_p, instantiated_bitset); ecma_value_t value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); @@ -559,42 +553,64 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in ECMA_INTERNAL_PROPERTY_BUILT_IN_ID); ecma_builtin_id_t builtin_id = (ecma_builtin_id_t) ecma_get_internal_property_value (built_in_id_prop_p); + JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT); JERRY_ASSERT (ecma_builtin_is (object_p, builtin_id)); - switch (builtin_id) + const ecma_builtin_property_descriptor_t *curr_property_p = ecma_builtin_property_list_references[builtin_id]; + + ecma_length_t index = 0; + ecma_internal_property_id_t mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31; + ecma_property_t *mask_prop_p = ecma_find_internal_property (object_p, mask_prop_id); + + ecma_collection_header_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) { -#define BUILTIN(builtin_id, \ - object_type, \ - object_prototype_builtin_id, \ - is_extensible, \ - is_static, \ - lowercase_name) \ - case builtin_id: \ - { \ - ecma_builtin_ ## lowercase_name ## _list_lazy_property_names (object_p, \ - separate_enumerable, \ - main_collection_p, \ - non_enum_collection_p); \ - return; \ - } -#include "ecma-builtins.inc.h" + JERRY_ASSERT (index < 64); - case ECMA_BUILTIN_ID__COUNT: + if (index == 32) { - JERRY_UNREACHABLE (); + ecma_internal_property_id_t mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63; + mask_prop_p = ecma_find_internal_property (object_p, mask_prop_id); } - default: + uint32_t bit_for_index; + if (index >= 32) { -#ifdef CONFIG_ECMA_COMPACT_PROFILE - JERRY_UNREACHABLE (); -#else /* !CONFIG_ECMA_COMPACT_PROFILE */ - JERRY_UNIMPLEMENTED ("The built-in is not implemented."); -#endif /* CONFIG_ECMA_COMPACT_PROFILE */ + bit_for_index = (uint32_t) 1u << (index - 32); } - } + else + { + bit_for_index = (uint32_t) 1u << index; + } + + bool was_instantiated = true; - JERRY_UNREACHABLE (); + if (mask_prop_p != NULL) + { + uint32_t instantiated_bitset = ecma_get_internal_property_value (mask_prop_p); + + if (!(instantiated_bitset & bit_for_index)) + { + was_instantiated = false; + } + } + + ecma_string_t *name_p = ecma_get_magic_string (curr_property_p->magic_string_id); + + if (!was_instantiated || ecma_op_object_get_own_property (object_p, name_p) != NULL) + { + ecma_append_to_values_collection (for_non_enumerable_p, + ecma_make_string_value (name_p), + true); + } + + ecma_deref_ecma_string (name_p); + + curr_property_p++; + index++; + } } } /* ecma_builtin_list_lazy_property_names */