diff --git a/jerry-core/ecma/base/ecma-globals.h b/jerry-core/ecma/base/ecma-globals.h index 5e68154f9..dc9b105f2 100644 --- a/jerry-core/ecma/base/ecma-globals.h +++ b/jerry-core/ecma/base/ecma-globals.h @@ -291,6 +291,29 @@ typedef enum ECMA_PROPERTY_FLAG_LCACHED = 1u << (ECMA_PROPERTY_FLAG_SHIFT + 3), /**< property is lcached */ } ecma_property_flags_t; +/** + * Property flags configurable, enumerable, writable. + */ +#define ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE \ + (ECMA_PROPERTY_FLAG_CONFIGURABLE | ECMA_PROPERTY_FLAG_ENUMERABLE | ECMA_PROPERTY_FLAG_WRITABLE) + +/** + * Property flags configurable, enumerable. + */ +#define ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE \ + (ECMA_PROPERTY_FLAG_CONFIGURABLE | ECMA_PROPERTY_FLAG_ENUMERABLE) + +/** + * Property flags configurable, enumerable. + */ +#define ECMA_PROPERTY_CONFIGURABLE_WRITABLE \ + (ECMA_PROPERTY_FLAG_CONFIGURABLE | ECMA_PROPERTY_FLAG_WRITABLE) + +/** + * No attributes can be changed for this property. + */ +#define ECMA_PROPERTY_FIXED 0 + /** * Abstract property representation. * diff --git a/jerry-core/ecma/base/ecma-helpers.c b/jerry-core/ecma/base/ecma-helpers.c index 57faf6ab8..c513bc6f4 100644 --- a/jerry-core/ecma/base/ecma-helpers.c +++ b/jerry-core/ecma/base/ecma-helpers.c @@ -576,26 +576,13 @@ ecma_get_internal_property (ecma_object_t *object_p, /**< object descriptor */ ecma_property_t * ecma_create_named_data_property (ecma_object_t *object_p, /**< object */ ecma_string_t *name_p, /**< property name */ - bool is_writable, /**< 'Writable' attribute */ - bool is_enumerable, /**< 'Enumerable' attribute */ - bool is_configurable) /**< 'Configurable' attribute */ + uint8_t prop_attributes) /**< property attributes (See: ecma_property_flags_t) */ { JERRY_ASSERT (object_p != NULL && name_p != NULL); JERRY_ASSERT (ecma_find_named_property (object_p, name_p) == NULL); + JERRY_ASSERT ((prop_attributes & ~ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE) == 0); - uint8_t type_and_flags = ECMA_PROPERTY_TYPE_NAMEDDATA; - if (is_configurable) - { - type_and_flags = (uint8_t) (type_and_flags | ECMA_PROPERTY_FLAG_CONFIGURABLE); - } - if (is_enumerable) - { - type_and_flags = (uint8_t) (type_and_flags | ECMA_PROPERTY_FLAG_ENUMERABLE); - } - if (is_writable) - { - type_and_flags = (uint8_t) (type_and_flags | ECMA_PROPERTY_FLAG_WRITABLE); - } + uint8_t type_and_flags = ECMA_PROPERTY_TYPE_NAMEDDATA | prop_attributes; name_p = ecma_copy_or_ref_ecma_string (name_p); @@ -617,21 +604,13 @@ ecma_create_named_accessor_property (ecma_object_t *object_p, /**< object */ ecma_string_t *name_p, /**< property name */ ecma_object_t *get_p, /**< getter */ ecma_object_t *set_p, /**< setter */ - bool is_enumerable, /**< 'enumerable' attribute */ - bool is_configurable) /**< 'configurable' attribute */ + uint8_t prop_attributes) /**< property attributes */ { JERRY_ASSERT (object_p != NULL && name_p != NULL); JERRY_ASSERT (ecma_find_named_property (object_p, name_p) == NULL); + JERRY_ASSERT ((prop_attributes & ~ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE) == 0); - uint8_t type_and_flags = ECMA_PROPERTY_TYPE_NAMEDACCESSOR; - if (is_configurable) - { - type_and_flags = (uint8_t) (type_and_flags | ECMA_PROPERTY_FLAG_CONFIGURABLE); - } - if (is_enumerable) - { - type_and_flags = (uint8_t) (type_and_flags | ECMA_PROPERTY_FLAG_ENUMERABLE); - } + uint8_t type_and_flags = ECMA_PROPERTY_TYPE_NAMEDACCESSOR | prop_attributes; name_p = ecma_copy_or_ref_ecma_string (name_p); diff --git a/jerry-core/ecma/base/ecma-helpers.h b/jerry-core/ecma/base/ecma-helpers.h index 0833e5496..ea7c4337c 100644 --- a/jerry-core/ecma/base/ecma-helpers.h +++ b/jerry-core/ecma/base/ecma-helpers.h @@ -263,9 +263,9 @@ extern ecma_property_t *ecma_find_internal_property (ecma_object_t *, ecma_inter extern ecma_property_t *ecma_get_internal_property (ecma_object_t *, ecma_internal_property_id_t); extern ecma_property_t * -ecma_create_named_data_property (ecma_object_t *, ecma_string_t *, bool, bool, bool); +ecma_create_named_data_property (ecma_object_t *, ecma_string_t *, uint8_t); extern ecma_property_t * -ecma_create_named_accessor_property (ecma_object_t *, ecma_string_t *, ecma_object_t *, ecma_object_t *, bool, bool); +ecma_create_named_accessor_property (ecma_object_t *, ecma_string_t *, ecma_object_t *, ecma_object_t *, uint8_t); extern ecma_property_t * ecma_find_named_property (ecma_object_t *, ecma_string_t *); extern ecma_property_t * 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 1a8eb1936..e1d100afe 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 @@ -300,11 +300,24 @@ TRY_TO_INSTANTIATE_PROPERTY_ROUTINE_NAME (ecma_object_t *obj_p, /**< object */ } } + uint8_t prop_attributes = 0; + + if (configurable) + { + prop_attributes = (uint8_t) (prop_attributes | ECMA_PROPERTY_FLAG_CONFIGURABLE); + } + if (enumerable) + { + prop_attributes = (uint8_t) (prop_attributes | ECMA_PROPERTY_FLAG_ENUMERABLE); + } + if (writable) + { + prop_attributes = (uint8_t) (prop_attributes | ECMA_PROPERTY_FLAG_WRITABLE); + } + ecma_property_t *prop_p = ecma_create_named_data_property (obj_p, prop_name_p, - writable, - enumerable, - configurable); + prop_attributes); ecma_named_data_property_assign_value (obj_p, prop_p, value); diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-json.c b/jerry-core/ecma/builtin-objects/ecma-builtin-json.c index 8968746fb..a048f4ba1 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-json.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-json.c @@ -737,11 +737,11 @@ ecma_builtin_json_parse (ecma_value_t this_arg __attr_unused___, /**< 'this' arg { ecma_object_t *object_p = ecma_op_create_object_object_noarg (); ecma_string_t *name_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY); - ecma_property_t *property_p = ecma_create_named_data_property (object_p, - name_p, - true, - true, - true); + + ecma_property_t *property_p; + property_p = ecma_create_named_data_property (object_p, + name_p, + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); ecma_named_data_property_assign_value (object_p, property_p, final_result); ecma_free_value (final_result); diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c index 1fa85185f..48bed0b74 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c @@ -1572,7 +1572,7 @@ ecma_builtin_helper_split_match (ecma_value_t input_string, /**< first argument ecma_string_t *magic_index_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_INDEX); ecma_property_t *index_prop_p = ecma_create_named_data_property (match_array_p, magic_index_str_p, - true, false, false); + ECMA_PROPERTY_FLAG_WRITABLE); ecma_deref_ecma_string (magic_index_str_p); ecma_named_data_property_assign_value (match_array_p, diff --git a/jerry-core/ecma/builtin-objects/ecma-builtins.c b/jerry-core/ecma/builtin-objects/ecma-builtins.c index 227f49746..054977394 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtins.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtins.c @@ -316,7 +316,7 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object * ecma_property_t *len_prop_p = ecma_create_named_data_property (object_p, string_p, - false, false, false); + ECMA_PROPERTY_FIXED); ecma_set_named_data_property_value (len_prop_p, ecma_make_uint32_value (length_prop_value)); diff --git a/jerry-core/ecma/operations/ecma-array-object.c b/jerry-core/ecma/operations/ecma-array-object.c index 05de4f428..1f30d0bf9 100644 --- a/jerry-core/ecma/operations/ecma-array-object.c +++ b/jerry-core/ecma/operations/ecma-array-object.c @@ -103,7 +103,8 @@ ecma_op_create_array_object (const ecma_value_t *arguments_list_p, /**< list of ecma_property_t *length_prop_p = ecma_create_named_data_property (obj_p, length_magic_string_p, - true, false, false); + ECMA_PROPERTY_FLAG_WRITABLE); + ecma_set_named_data_property_value (length_prop_p, ecma_make_number_value ((ecma_number_t) length)); ecma_deref_ecma_string (length_magic_string_p); diff --git a/jerry-core/ecma/operations/ecma-exceptions.c b/jerry-core/ecma/operations/ecma-exceptions.c index 740d7a7aa..1ab31156b 100644 --- a/jerry-core/ecma/operations/ecma-exceptions.c +++ b/jerry-core/ecma/operations/ecma-exceptions.c @@ -120,7 +120,7 @@ ecma_new_standard_error_with_message (ecma_standard_error_t error_type, /**< nat ecma_string_t *message_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_MESSAGE); ecma_property_t *prop_p = ecma_create_named_data_property (new_error_obj_p, message_magic_string_p, - true, false, true); + ECMA_PROPERTY_CONFIGURABLE_WRITABLE); ecma_set_named_data_property_value (prop_p, ecma_make_string_value (ecma_copy_or_ref_ecma_string (message_string_p))); diff --git a/jerry-core/ecma/operations/ecma-function-object.c b/jerry-core/ecma/operations/ecma-function-object.c index 0d6618ce8..ea5e5a292 100644 --- a/jerry-core/ecma/operations/ecma-function-object.c +++ b/jerry-core/ecma/operations/ecma-function-object.c @@ -311,9 +311,7 @@ ecma_op_function_try_lazy_instantiate_property (ecma_object_t *obj_p, /**< the f // 15 ecma_property_t *length_prop_p = ecma_create_named_data_property (obj_p, property_name_p, - false, - false, - false); + ECMA_PROPERTY_FIXED); ecma_named_data_property_assign_value (obj_p, length_prop_p, ecma_make_uint32_value (len)); @@ -349,9 +347,7 @@ ecma_op_function_try_lazy_instantiate_property (ecma_object_t *obj_p, /**< the f // 18. ecma_property_t *prototype_prop_p = ecma_create_named_data_property (obj_p, property_name_p, - true, - false, - false); + ECMA_PROPERTY_FLAG_WRITABLE); ecma_named_data_property_assign_value (obj_p, prototype_prop_p, ecma_make_object_value (proto_p)); diff --git a/jerry-core/ecma/operations/ecma-lex-env.c b/jerry-core/ecma/operations/ecma-lex-env.c index 059df4218..7c585441d 100644 --- a/jerry-core/ecma/operations/ecma-lex-env.c +++ b/jerry-core/ecma/operations/ecma-lex-env.c @@ -135,9 +135,16 @@ ecma_op_create_mutable_binding (ecma_object_t *lex_env_p, /**< lexical environme if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE) { + uint8_t prop_attributes = ECMA_PROPERTY_FLAG_WRITABLE; + + if (is_deletable) + { + prop_attributes = (uint8_t) (prop_attributes | ECMA_PROPERTY_FLAG_CONFIGURABLE); + } + ecma_create_named_data_property (lex_env_p, name_p, - true, false, is_deletable); + prop_attributes); } else { @@ -399,7 +406,7 @@ ecma_op_create_immutable_binding (ecma_object_t *lex_env_p, /**< lexical environ */ ecma_property_t *prop_p = ecma_create_named_data_property (lex_env_p, name_p, - false, false, false); + ECMA_PROPERTY_FIXED); JERRY_ASSERT (ecma_is_value_undefined (ecma_get_named_data_property_value (prop_p))); diff --git a/jerry-core/ecma/operations/ecma-objects-general.c b/jerry-core/ecma/operations/ecma-objects-general.c index d1f7e8d24..68682a9fc 100644 --- a/jerry-core/ecma/operations/ecma-objects-general.c +++ b/jerry-core/ecma/operations/ecma-objects-general.c @@ -403,11 +403,10 @@ ecma_op_general_object_put (ecma_object_t *obj_p, /**< the object */ } } - ecma_property_t *new_prop_p = ecma_create_named_data_property (obj_p, - property_name_p, - true, /* Writable */ - true, /* Enumerable */ - true); /* Configurable */ + ecma_property_t *new_prop_p; + new_prop_p = ecma_create_named_data_property (obj_p, + property_name_p, + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); JERRY_ASSERT (ecma_is_value_undefined (ecma_get_named_data_property_value (new_prop_p))); ecma_set_named_data_property_value (new_prop_p, ecma_copy_value_if_not_object (value)); @@ -635,12 +634,24 @@ ecma_op_general_object_define_own_property (ecma_object_t *obj_p, /**< the objec JERRY_ASSERT (property_desc_type == ECMA_PROPERTY_TYPE_GENERIC || property_desc_type == ECMA_PROPERTY_TYPE_NAMEDDATA); + uint8_t prop_attributes = 0; + + if (property_desc_p->is_configurable) + { + prop_attributes = (uint8_t) (prop_attributes | ECMA_PROPERTY_FLAG_CONFIGURABLE); + } + if (property_desc_p->is_enumerable) + { + prop_attributes = (uint8_t) (prop_attributes | ECMA_PROPERTY_FLAG_ENUMERABLE); + } + if (property_desc_p->is_writable) + { + prop_attributes = (uint8_t) (prop_attributes | ECMA_PROPERTY_FLAG_WRITABLE); + } + ecma_property_t *new_prop_p = ecma_create_named_data_property (obj_p, property_name_p, - property_desc_p->is_writable, - property_desc_p->is_enumerable, - property_desc_p->is_configurable); - + prop_attributes); JERRY_ASSERT (property_desc_p->is_value_defined || ecma_is_value_undefined (property_desc_p->value)); @@ -651,12 +662,22 @@ ecma_op_general_object_define_own_property (ecma_object_t *obj_p, /**< the objec { // b. + uint8_t prop_attributes = 0; + + if (property_desc_p->is_configurable) + { + prop_attributes = (uint8_t) (prop_attributes | ECMA_PROPERTY_FLAG_CONFIGURABLE); + } + if (property_desc_p->is_enumerable) + { + prop_attributes = (uint8_t) (prop_attributes | ECMA_PROPERTY_FLAG_ENUMERABLE); + } + ecma_create_named_accessor_property (obj_p, property_name_p, property_desc_p->get_p, property_desc_p->set_p, - property_desc_p->is_enumerable, - property_desc_p->is_configurable); + prop_attributes); } return ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE); @@ -727,8 +748,12 @@ ecma_op_general_object_define_own_property (ecma_object_t *obj_p, /**< the objec /* The following implementation can be optimized by directly overwriting * the fields of current_p if this code path is performance critical. */ + uint8_t prop_attributes = ECMA_PROPERTY_FLAG_CONFIGURABLE; - bool was_enumerable = ecma_is_property_enumerable (current_p); + if (ecma_is_property_enumerable (current_p)) + { + prop_attributes = (uint8_t) (prop_attributes | ECMA_PROPERTY_FLAG_ENUMERABLE); + } ecma_delete_property (obj_p, current_p); @@ -740,8 +765,7 @@ ecma_op_general_object_define_own_property (ecma_object_t *obj_p, /**< the objec property_name_p, NULL, NULL, - was_enumerable, - true); + prop_attributes); } else { @@ -749,9 +773,7 @@ ecma_op_general_object_define_own_property (ecma_object_t *obj_p, /**< the objec current_p = ecma_create_named_data_property (obj_p, property_name_p, - false, - was_enumerable, - true); + prop_attributes); } } diff --git a/jerry-core/ecma/operations/ecma-regexp-object.c b/jerry-core/ecma/operations/ecma-regexp-object.c index c79e79173..b91a740bf 100644 --- a/jerry-core/ecma/operations/ecma-regexp-object.c +++ b/jerry-core/ecma/operations/ecma-regexp-object.c @@ -142,7 +142,7 @@ re_initialize_props (ecma_object_t *re_obj_p, /**< RegExp obejct */ { prop_p = ecma_create_named_data_property (re_obj_p, magic_string_p, - false, false, false); + ECMA_PROPERTY_FIXED); } ecma_deref_ecma_string (magic_string_p); @@ -161,7 +161,7 @@ re_initialize_props (ecma_object_t *re_obj_p, /**< RegExp obejct */ { prop_p = ecma_create_named_data_property (re_obj_p, magic_string_p, - false, false, false); + ECMA_PROPERTY_FIXED); } ecma_deref_ecma_string (magic_string_p); @@ -177,7 +177,7 @@ re_initialize_props (ecma_object_t *re_obj_p, /**< RegExp obejct */ { prop_p = ecma_create_named_data_property (re_obj_p, magic_string_p, - false, false, false); + ECMA_PROPERTY_FIXED); } ecma_deref_ecma_string (magic_string_p); @@ -193,7 +193,7 @@ re_initialize_props (ecma_object_t *re_obj_p, /**< RegExp obejct */ { prop_p = ecma_create_named_data_property (re_obj_p, magic_string_p, - false, false, false); + ECMA_PROPERTY_FIXED); } ecma_deref_ecma_string (magic_string_p); @@ -209,7 +209,7 @@ re_initialize_props (ecma_object_t *re_obj_p, /**< RegExp obejct */ { prop_p = ecma_create_named_data_property (re_obj_p, magic_string_p, - true, false, false); + ECMA_PROPERTY_FLAG_WRITABLE); } ecma_deref_ecma_string (magic_string_p); diff --git a/jerry-core/ecma/operations/ecma-string-object.c b/jerry-core/ecma/operations/ecma-string-object.c index f68e85e87..689ac6177 100644 --- a/jerry-core/ecma/operations/ecma-string-object.c +++ b/jerry-core/ecma/operations/ecma-string-object.c @@ -101,7 +101,7 @@ ecma_op_create_string_object (const ecma_value_t *arguments_list_p, /**< list of ecma_string_t *length_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH); ecma_property_t *length_prop_p = ecma_create_named_data_property (obj_p, length_magic_string_p, - false, false, false); + ECMA_PROPERTY_FIXED); ecma_set_named_data_property_value (length_prop_p, ecma_make_number_value (length_value)); ecma_deref_ecma_string (length_magic_string_p); @@ -191,7 +191,7 @@ ecma_op_string_object_get_own_property (ecma_object_t *obj_p, /**< a String obje new_prop_p = ecma_create_named_data_property (obj_p, new_prop_name_p, - false, true, false); + ECMA_PROPERTY_FLAG_ENUMERABLE); ecma_set_named_data_property_value (new_prop_p, ecma_make_string_value (new_prop_str_value_p)); diff --git a/jerry-core/jerry.c b/jerry-core/jerry.c index 365bfd800..e6fa07ce1 100644 --- a/jerry-core/jerry.c +++ b/jerry-core/jerry.c @@ -1060,11 +1060,16 @@ jerry_api_add_object_field (jerry_api_object_t *object_p, /**< object to add fie ecma_value_t value_to_put; jerry_api_convert_api_value_to_ecma_value (&value_to_put, field_value_p); + uint8_t prop_attributes = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE; + + if (is_writable) + { + prop_attributes = (uint8_t) (prop_attributes | ECMA_PROPERTY_FLAG_WRITABLE); + } + prop_p = ecma_create_named_data_property (object_p, field_name_str_p, - is_writable, - true, - true); + prop_attributes); ecma_named_data_property_assign_value (object_p, prop_p, value_to_put); ecma_free_value (value_to_put); diff --git a/jerry-core/vm/opcodes.c b/jerry-core/vm/opcodes.c index 3d79905cb..66001849e 100644 --- a/jerry-core/vm/opcodes.c +++ b/jerry-core/vm/opcodes.c @@ -181,8 +181,7 @@ opfunc_set_accessor (bool is_getter, /**< is getter accessor */ accessor_name_p, getter_func_p, setter_func_p, - true, - true); + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE); } else if (is_getter) { diff --git a/jerry-core/vm/vm.c b/jerry-core/vm/vm.c index 5cef22cd4..e8e81ac10 100644 --- a/jerry-core/vm/vm.c +++ b/jerry-core/vm/vm.c @@ -973,9 +973,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */ { property_p = ecma_create_named_data_property (object_p, prop_name_p, - true, - true, - true); + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); } ecma_named_data_property_assign_value (object_p, property_p, left_value); @@ -1038,11 +1036,10 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */ { ecma_string_t *index_str_p = ecma_new_ecma_string_from_uint32 (length_num); - ecma_property_t *prop_p = ecma_create_named_data_property (array_obj_p, - index_str_p, - true, /* Writable */ - true, /* Enumerable */ - true); /* Configurable */ + ecma_property_t *prop_p; + prop_p = ecma_create_named_data_property (array_obj_p, + index_str_p, + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); JERRY_ASSERT (ecma_is_value_undefined (ecma_get_named_data_property_value (prop_p)));