diff --git a/src/libecmaobjects/ecma-alloc.c b/src/libecmaobjects/ecma-alloc.c index 17a8330fb..d5ac5d4ee 100644 --- a/src/libecmaobjects/ecma-alloc.c +++ b/src/libecmaobjects/ecma-alloc.c @@ -55,30 +55,30 @@ JERRY_STATIC_ASSERT(sizeof (ecma_completion_value_t) == sizeof (uint32_t)); * FIXME: Run GC only if allocation failed. */ #define ALLOC(ecma_type) ecma_ ## ecma_type ## _t * \ -ecma_alloc_ ## ecma_type (void) \ + ecma_alloc_ ## ecma_type (void) \ { \ ecma_ ## ecma_type ## _t *p ## ecma_type = (ecma_ ## ecma_type ## _t *) \ - mem_pools_alloc (); \ + mem_pools_alloc (); \ \ if (likely (p ## ecma_type != NULL)) \ + { \ + return p ## ecma_type; \ + } \ + \ + for (ecma_gc_gen_t gen_id = ECMA_GC_GEN_0; \ + gen_id < ECMA_GC_GEN_COUNT; \ + gen_id++) \ + { \ + ecma_gc_run (gen_id); \ + \ + p ## ecma_type = (ecma_ ## ecma_type ## _t *) \ + mem_pools_alloc (); \ + \ + if (likely (p ## ecma_type != NULL)) \ { \ return p ## ecma_type; \ } \ - \ - for (ecma_gc_gen_t gen_id = ECMA_GC_GEN_0; \ - gen_id < ECMA_GC_GEN_COUNT; \ - gen_id++) \ - { \ - ecma_gc_run (gen_id); \ - \ - p ## ecma_type = (ecma_ ## ecma_type ## _t *) \ - mem_pools_alloc (); \ - \ - if (likely (p ## ecma_type != NULL)) \ - { \ - return p ## ecma_type; \ - } \ - } \ + } \ JERRY_UNREACHABLE(); \ } @@ -86,17 +86,17 @@ ecma_alloc_ ## ecma_type (void) \ * Deallocation routine template */ #define DEALLOC(ecma_type) void \ -ecma_dealloc_ ## ecma_type (ecma_ ## ecma_type ## _t *p ## ecma_type) \ + ecma_dealloc_ ## ecma_type (ecma_ ## ecma_type ## _t *p ## ecma_type) \ { \ - mem_pools_free ((uint8_t*) p ## ecma_type); \ + mem_pools_free ((uint8_t*) p ## ecma_type); \ } /** * Declaration of alloc/free routine for specified ecma-type. */ #define DECLARE_ROUTINES_FOR(ecma_type) \ - ALLOC(ecma_type) \ - DEALLOC(ecma_type) + ALLOC(ecma_type) \ + DEALLOC(ecma_type) DECLARE_ROUTINES_FOR (object) DECLARE_ROUTINES_FOR (property) diff --git a/src/libecmaobjects/ecma-gc.c b/src/libecmaobjects/ecma-gc.c index 701b1c654..018e42843 100644 --- a/src/libecmaobjects/ecma-gc.c +++ b/src/libecmaobjects/ecma-gc.c @@ -72,9 +72,9 @@ ecma_ref_object (ecma_object_t *object_p) /**< object */ JERRY_ASSERT(object_p->gc_info.refs > 0); if (unlikely (object_p->gc_info.refs == 0)) - { - JERRY_UNREACHABLE(); - } + { + JERRY_UNREACHABLE(); + } } /* ecma_ref_object */ /** @@ -99,9 +99,9 @@ ecma_gc_update_may_ref_younger_object_flag_by_value (ecma_object_t *obj_p, /**< ecma_value_t value) /**< value */ { if (value.value_type != ECMA_TYPE_OBJECT) - { - return; - } + { + return; + } ecma_object_t *ref_obj_p = ECMA_GET_POINTER(value.value); JERRY_ASSERT(ref_obj_p != NULL); @@ -115,14 +115,14 @@ ecma_gc_update_may_ref_younger_object_flag_by_object (ecma_object_t *obj_p, /**< or NULL */ { if (ref_obj_p == NULL) - { - return; - } + { + return; + } if (ref_obj_p->gc_info.generation < obj_p->gc_info.generation) - { - obj_p->gc_info.may_ref_younger_objects = true; - } + { + obj_p->gc_info.may_ref_younger_objects = true; + } } /* ecma_gc_update_may_ref_younger_object_flag_by_object */ /** @@ -151,145 +151,145 @@ ecma_gc_mark (ecma_object_t *object_p, /**< start object */ bool does_reference_object_to_traverse = false; if (object_p->is_lexical_environment) + { + ecma_object_t *lex_env_p = ECMA_GET_POINTER(object_p->u.lexical_environment.outer_reference_p); + if (lex_env_p != NULL + && lex_env_p->gc_info.generation <= maximum_gen_to_traverse) { - ecma_object_t *lex_env_p = ECMA_GET_POINTER(object_p->u.lexical_environment.outer_reference_p); - if (lex_env_p != NULL - && lex_env_p->gc_info.generation <= maximum_gen_to_traverse) - { - if (!lex_env_p->gc_info.visited) - { - ecma_gc_mark (lex_env_p, ECMA_GC_GEN_COUNT); - } + if (!lex_env_p->gc_info.visited) + { + ecma_gc_mark (lex_env_p, ECMA_GC_GEN_COUNT); + } - does_reference_object_to_traverse = true; - } + does_reference_object_to_traverse = true; } + } else + { + ecma_object_t *proto_p = ECMA_GET_POINTER(object_p->u.object.prototype_object_p); + if (proto_p != NULL + && proto_p->gc_info.generation <= maximum_gen_to_traverse) { - ecma_object_t *proto_p = ECMA_GET_POINTER(object_p->u.object.prototype_object_p); - if (proto_p != NULL - && proto_p->gc_info.generation <= maximum_gen_to_traverse) - { - if (!proto_p->gc_info.visited) - { - ecma_gc_mark (proto_p, ECMA_GC_GEN_COUNT); - } + if (!proto_p->gc_info.visited) + { + ecma_gc_mark (proto_p, ECMA_GC_GEN_COUNT); + } - does_reference_object_to_traverse = true; - } + does_reference_object_to_traverse = true; } + } for (ecma_property_t *property_p = ECMA_GET_POINTER(object_p->properties_p), *next_property_p; - property_p != NULL; - property_p = next_property_p) + property_p != NULL; + property_p = next_property_p) + { + next_property_p = ECMA_GET_POINTER(property_p->next_property_p); + + switch ((ecma_property_type_t) property_p->type) { - next_property_p = ECMA_GET_POINTER(property_p->next_property_p); + case ECMA_PROPERTY_NAMEDDATA: + { + ecma_value_t value = property_p->u.named_data_property.value; - switch ((ecma_property_type_t) property_p->type) + if (value.value_type == ECMA_TYPE_OBJECT) { - case ECMA_PROPERTY_NAMEDDATA: + ecma_object_t *value_obj_p = ECMA_GET_POINTER(value.value); + + if (value_obj_p->gc_info.generation <= maximum_gen_to_traverse) + { + if (!value_obj_p->gc_info.visited) { - ecma_value_t value = property_p->u.named_data_property.value; - - if (value.value_type == ECMA_TYPE_OBJECT) - { - ecma_object_t *value_obj_p = ECMA_GET_POINTER(value.value); - - if (value_obj_p->gc_info.generation <= maximum_gen_to_traverse) - { - if (!value_obj_p->gc_info.visited) - { - ecma_gc_mark (value_obj_p, ECMA_GC_GEN_COUNT); - } - - does_reference_object_to_traverse = true; - } - } - - break; + ecma_gc_mark (value_obj_p, ECMA_GC_GEN_COUNT); } - case ECMA_PROPERTY_NAMEDACCESSOR: - { - ecma_object_t *getter_obj_p = ECMA_GET_POINTER(property_p->u.named_accessor_property.get_p); - ecma_object_t *setter_obj_p = ECMA_GET_POINTER(property_p->u.named_accessor_property.set_p); - - if (getter_obj_p != NULL) - { - if (getter_obj_p->gc_info.generation <= maximum_gen_to_traverse) - { - if (!getter_obj_p->gc_info.visited) - { - ecma_gc_mark (getter_obj_p, ECMA_GC_GEN_COUNT); - } - - does_reference_object_to_traverse = true; - } - } - - if (setter_obj_p != NULL) - { - if (setter_obj_p->gc_info.generation <= maximum_gen_to_traverse) - { - if (!setter_obj_p->gc_info.visited) - { - ecma_gc_mark (setter_obj_p, ECMA_GC_GEN_COUNT); - } - - does_reference_object_to_traverse = true; - } - } - - break; - } - - case ECMA_PROPERTY_INTERNAL: - { - ecma_internal_property_id_t property_id = property_p->u.internal_property.type; - uint32_t property_value = property_p->u.internal_property.value; - - switch (property_id) - { - case ECMA_INTERNAL_PROPERTY_NUMBER_INDEXED_ARRAY_VALUES: /* an array */ - case ECMA_INTERNAL_PROPERTY_STRING_INDEXED_ARRAY_VALUES: /* an array */ - case ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS: /* an array */ - case ECMA_INTERNAL_PROPERTY_PROTOTYPE: /* the property's value is located in ecma_object_t */ - case ECMA_INTERNAL_PROPERTY_EXTENSIBLE: /* the property's value is located in ecma_object_t */ - case ECMA_INTERNAL_PROPERTY_PROVIDE_THIS: /* a boolean */ - case ECMA_INTERNAL_PROPERTY_CLASS: /* an enum */ - case ECMA_INTERNAL_PROPERTY_CODE: /* an integer */ - { - break; - } - - case ECMA_INTERNAL_PROPERTY_SCOPE: /* a lexical environment */ - case ECMA_INTERNAL_PROPERTY_BINDING_OBJECT: /* an object */ - { - ecma_object_t *obj_p = ECMA_GET_POINTER(property_value); - - if (obj_p->gc_info.generation <= maximum_gen_to_traverse) - { - if (!obj_p->gc_info.visited) - { - ecma_gc_mark (obj_p, ECMA_GC_GEN_COUNT); - } - - does_reference_object_to_traverse = true; - } - - break; - } - } - - break; - } + does_reference_object_to_traverse = true; + } } + + break; + } + + case ECMA_PROPERTY_NAMEDACCESSOR: + { + ecma_object_t *getter_obj_p = ECMA_GET_POINTER(property_p->u.named_accessor_property.get_p); + ecma_object_t *setter_obj_p = ECMA_GET_POINTER(property_p->u.named_accessor_property.set_p); + + if (getter_obj_p != NULL) + { + if (getter_obj_p->gc_info.generation <= maximum_gen_to_traverse) + { + if (!getter_obj_p->gc_info.visited) + { + ecma_gc_mark (getter_obj_p, ECMA_GC_GEN_COUNT); + } + + does_reference_object_to_traverse = true; + } + } + + if (setter_obj_p != NULL) + { + if (setter_obj_p->gc_info.generation <= maximum_gen_to_traverse) + { + if (!setter_obj_p->gc_info.visited) + { + ecma_gc_mark (setter_obj_p, ECMA_GC_GEN_COUNT); + } + + does_reference_object_to_traverse = true; + } + } + + break; + } + + case ECMA_PROPERTY_INTERNAL: + { + ecma_internal_property_id_t property_id = property_p->u.internal_property.type; + uint32_t property_value = property_p->u.internal_property.value; + + switch (property_id) + { + case ECMA_INTERNAL_PROPERTY_NUMBER_INDEXED_ARRAY_VALUES: /* an array */ + case ECMA_INTERNAL_PROPERTY_STRING_INDEXED_ARRAY_VALUES: /* an array */ + case ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS: /* an array */ + case ECMA_INTERNAL_PROPERTY_PROTOTYPE: /* the property's value is located in ecma_object_t */ + case ECMA_INTERNAL_PROPERTY_EXTENSIBLE: /* the property's value is located in ecma_object_t */ + case ECMA_INTERNAL_PROPERTY_PROVIDE_THIS: /* a boolean */ + case ECMA_INTERNAL_PROPERTY_CLASS: /* an enum */ + case ECMA_INTERNAL_PROPERTY_CODE: /* an integer */ + { + break; + } + + case ECMA_INTERNAL_PROPERTY_SCOPE: /* a lexical environment */ + case ECMA_INTERNAL_PROPERTY_BINDING_OBJECT: /* an object */ + { + ecma_object_t *obj_p = ECMA_GET_POINTER(property_value); + + if (obj_p->gc_info.generation <= maximum_gen_to_traverse) + { + if (!obj_p->gc_info.visited) + { + ecma_gc_mark (obj_p, ECMA_GC_GEN_COUNT); + } + + does_reference_object_to_traverse = true; + } + + break; + } + } + + break; + } } + } if (!does_reference_object_to_traverse) - { - object_p->gc_info.may_ref_younger_objects = false; - } + { + object_p->gc_info.may_ref_younger_objects = false; + } } /* ecma_gc_mark */ /** @@ -299,18 +299,18 @@ void ecma_gc_sweep (ecma_object_t *object_p) /**< object to free */ { JERRY_ASSERT(object_p != NULL - && !object_p->gc_info.visited - && object_p->gc_info.refs == 0); + && !object_p->gc_info.visited + && object_p->gc_info.refs == 0); for (ecma_property_t *property = ECMA_GET_POINTER(object_p->properties_p), - *next_property_p; - property != NULL; - property = next_property_p) - { - next_property_p = ECMA_GET_POINTER(property->next_property_p); + *next_property_p; + property != NULL; + property = next_property_p) + { + next_property_p = ECMA_GET_POINTER(property->next_property_p); - ecma_free_property (property); - } + ecma_free_property (property); + } ecma_dealloc_object (object_p); } /* ecma_gc_sweep */ @@ -325,46 +325,46 @@ ecma_gc_run (ecma_gc_gen_t max_gen_to_collect) /**< maximum generation to run co /* clearing visited flags for all objects of generations to be processed */ for (ecma_gc_gen_t gen_id = 0; gen_id <= max_gen_to_collect; gen_id++) + { + for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ]; + obj_iter_p != NULL; + obj_iter_p = ECMA_GET_POINTER(obj_iter_p->gc_info.next)) { - for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ]; - obj_iter_p != NULL; - obj_iter_p = ECMA_GET_POINTER(obj_iter_p->gc_info.next)) - { - obj_iter_p->gc_info.visited = false; - } + obj_iter_p->gc_info.visited = false; } + } /* if some object is referenced from stack or globals (i.e. it is root), * start recursive marking traverse from the object */ for (ecma_gc_gen_t gen_id = 0; gen_id <= max_gen_to_collect; gen_id++) + { + for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ]; + obj_iter_p != NULL; + obj_iter_p = ECMA_GET_POINTER(obj_iter_p->gc_info.next)) { - for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ]; - obj_iter_p != NULL; - obj_iter_p = ECMA_GET_POINTER(obj_iter_p->gc_info.next)) - { - if (obj_iter_p->gc_info.refs > 0 - && !obj_iter_p->gc_info.visited) - { - ecma_gc_mark (obj_iter_p, ECMA_GC_GEN_COUNT); - } - } + if (obj_iter_p->gc_info.refs > 0 + && !obj_iter_p->gc_info.visited) + { + ecma_gc_mark (obj_iter_p, ECMA_GC_GEN_COUNT); + } } + } /* if some object from generations that are not processed during current session may reference * younger generations, start recursive marking traverse from the object, but one the first level * consider only references to object of at most max_gen_to_collect generation */ for (ecma_gc_gen_t gen_id = max_gen_to_collect + 1; gen_id < ECMA_GC_GEN_COUNT; gen_id++) + { + for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ]; + obj_iter_p != NULL; + obj_iter_p = ECMA_GET_POINTER(obj_iter_p->gc_info.next)) { - for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ]; - obj_iter_p != NULL; - obj_iter_p = ECMA_GET_POINTER(obj_iter_p->gc_info.next)) - { - if (obj_iter_p->gc_info.may_ref_younger_objects > 0) - { - ecma_gc_mark (obj_iter_p, max_gen_to_collect); - } - } + if (obj_iter_p->gc_info.may_ref_younger_objects > 0) + { + ecma_gc_mark (obj_iter_p, max_gen_to_collect); + } } + } ecma_object_t *gen_last_obj_p[ max_gen_to_collect + 1 ]; #ifndef JERRY_NDEBUG @@ -372,79 +372,79 @@ ecma_gc_run (ecma_gc_gen_t max_gen_to_collect) /**< maximum generation to run co #endif /* !JERRY_NDEBUG */ for (ecma_gc_gen_t gen_id = 0; gen_id <= max_gen_to_collect; gen_id++) + { + ecma_object_t *obj_prev_p = NULL; + + for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ], + *obj_next_p; + obj_iter_p != NULL; + obj_iter_p = obj_next_p) { - ecma_object_t *obj_prev_p = NULL; + obj_next_p = ECMA_GET_POINTER(obj_iter_p->gc_info.next); - for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ], - *obj_next_p; - obj_iter_p != NULL; - obj_iter_p = obj_next_p) + if (!obj_iter_p->gc_info.visited) + { + ecma_gc_sweep (obj_iter_p); + + if (likely (obj_prev_p != NULL)) { - obj_next_p = ECMA_GET_POINTER(obj_iter_p->gc_info.next); - - if (!obj_iter_p->gc_info.visited) - { - ecma_gc_sweep (obj_iter_p); - - if (likely (obj_prev_p != NULL)) - { - ECMA_SET_POINTER(obj_prev_p->gc_info.next, obj_next_p); - } - else - { - ecma_gc_objects_lists[ gen_id ] = obj_next_p; - } - } - else - { - obj_prev_p = obj_iter_p; - - if (obj_iter_p->gc_info.generation != ECMA_GC_GEN_COUNT - 1) - { - /* the object will be promoted to next generation */ - obj_iter_p->gc_info.generation++; - } - } + ECMA_SET_POINTER(obj_prev_p->gc_info.next, obj_next_p); } + else + { + ecma_gc_objects_lists[ gen_id ] = obj_next_p; + } + } + else + { + obj_prev_p = obj_iter_p; - gen_last_obj_p[ gen_id ] = obj_prev_p; + if (obj_iter_p->gc_info.generation != ECMA_GC_GEN_COUNT - 1) + { + /* the object will be promoted to next generation */ + obj_iter_p->gc_info.generation++; + } + } } + gen_last_obj_p[ gen_id ] = obj_prev_p; + } + ecma_gc_gen_t gen_to_promote = max_gen_to_collect; if (unlikely (gen_to_promote == ECMA_GC_GEN_COUNT - 1)) - { - /* not promoting last generation */ - gen_to_promote--; - } + { + /* not promoting last generation */ + gen_to_promote--; + } /* promoting to next generation */ if (gen_last_obj_p[ gen_to_promote ] != NULL) - { - ECMA_SET_POINTER(gen_last_obj_p[ gen_to_promote ]->gc_info.next, ecma_gc_objects_lists[ gen_to_promote + 1 ]); - ecma_gc_objects_lists[ gen_to_promote + 1 ] = ecma_gc_objects_lists[ gen_to_promote ]; - ecma_gc_objects_lists[ gen_to_promote ] = NULL; - } + { + ECMA_SET_POINTER(gen_last_obj_p[ gen_to_promote ]->gc_info.next, ecma_gc_objects_lists[ gen_to_promote + 1 ]); + ecma_gc_objects_lists[ gen_to_promote + 1 ] = ecma_gc_objects_lists[ gen_to_promote ]; + ecma_gc_objects_lists[ gen_to_promote ] = NULL; + } for (int32_t gen_id = (int32_t)gen_to_promote - 1; - gen_id >= 0; - gen_id--) - { - ecma_gc_objects_lists[ gen_id + 1 ] = ecma_gc_objects_lists[ gen_id ]; - ecma_gc_objects_lists[ gen_id ] = NULL; - } + gen_id >= 0; + gen_id--) + { + ecma_gc_objects_lists[ gen_id + 1 ] = ecma_gc_objects_lists[ gen_id ]; + ecma_gc_objects_lists[ gen_id ] = NULL; + } #ifndef JERRY_NDEBUG for (ecma_gc_gen_t gen_id = ECMA_GC_GEN_0; - gen_id < ECMA_GC_GEN_COUNT; - gen_id++) + gen_id < ECMA_GC_GEN_COUNT; + gen_id++) + { + for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ]; + obj_iter_p != NULL; + obj_iter_p = ECMA_GET_POINTER(obj_iter_p->gc_info.next)) { - for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ]; - obj_iter_p != NULL; - obj_iter_p = ECMA_GET_POINTER(obj_iter_p->gc_info.next)) - { - JERRY_ASSERT(obj_iter_p->gc_info.generation == gen_id); - } + JERRY_ASSERT(obj_iter_p->gc_info.generation == gen_id); } + } #endif /* !JERRY_NDEBUG */ } /* ecma_gc_run */ diff --git a/src/libecmaobjects/ecma-globals.h b/src/libecmaobjects/ecma-globals.h index ece374723..b87d47fcb 100644 --- a/src/libecmaobjects/ecma-globals.h +++ b/src/libecmaobjects/ecma-globals.h @@ -51,42 +51,45 @@ /** * Type of ecma-value */ -typedef enum { - ECMA_TYPE_SIMPLE, /**< simple value */ - ECMA_TYPE_NUMBER, /**< 64-bit integer */ - ECMA_TYPE_STRING, /**< pointer to description of a string */ - ECMA_TYPE_OBJECT, /**< pointer to description of an object */ - ECMA_TYPE__COUNT /**< count of types */ +typedef enum +{ + ECMA_TYPE_SIMPLE, /**< simple value */ + ECMA_TYPE_NUMBER, /**< 64-bit integer */ + ECMA_TYPE_STRING, /**< pointer to description of a string */ + ECMA_TYPE_OBJECT, /**< pointer to description of an object */ + ECMA_TYPE__COUNT /**< count of types */ } ecma_type_t; /** * Simple ecma-values */ -typedef enum { - /** - * Empty value is implementation defined value, used for: - * - representing empty value in completion values (see also: ECMA-262 v5, 8.9 Completion specification type); - * - values of uninitialized immutable bindings; - * - values of empty register variables. - */ - ECMA_SIMPLE_VALUE_EMPTY, - ECMA_SIMPLE_VALUE_UNDEFINED, /**< undefined value */ - ECMA_SIMPLE_VALUE_NULL, /**< null value */ - ECMA_SIMPLE_VALUE_FALSE, /**< boolean false */ - ECMA_SIMPLE_VALUE_TRUE, /**< boolean true */ - ECMA_SIMPLE_VALUE_ARRAY_REDIRECT, /**< implementation defined value for an array's elements that exists, - but is stored directly in the array's property list - (used for array elements with non-default attribute values) */ - ECMA_SIMPLE_VALUE__COUNT /** count of simple ecma-values */ +typedef enum +{ + /** + * Empty value is implementation defined value, used for: + * - representing empty value in completion values (see also: ECMA-262 v5, 8.9 Completion specification type); + * - values of uninitialized immutable bindings; + * - values of empty register variables. + */ + ECMA_SIMPLE_VALUE_EMPTY, + ECMA_SIMPLE_VALUE_UNDEFINED, /**< undefined value */ + ECMA_SIMPLE_VALUE_NULL, /**< null value */ + ECMA_SIMPLE_VALUE_FALSE, /**< boolean false */ + ECMA_SIMPLE_VALUE_TRUE, /**< boolean true */ + ECMA_SIMPLE_VALUE_ARRAY_REDIRECT, /**< implementation defined value for an array's elements that exists, + but is stored directly in the array's property list + (used for array elements with non-default attribute values) */ + ECMA_SIMPLE_VALUE__COUNT /** count of simple ecma-values */ } ecma_simple_value_t; /** * Type of ecma-property */ -typedef enum { - ECMA_PROPERTY_NAMEDDATA, /**< named data property */ - ECMA_PROPERTY_NAMEDACCESSOR, /**< named accessor property */ - ECMA_PROPERTY_INTERNAL /**< internal property */ +typedef enum +{ + ECMA_PROPERTY_NAMEDDATA, /**< named data property */ + ECMA_PROPERTY_NAMEDACCESSOR, /**< named accessor property */ + ECMA_PROPERTY_INTERNAL /**< internal property */ } ecma_property_type_t; /** @@ -94,27 +97,29 @@ typedef enum { * * See also: ECMA-262 v5, 8.9. */ -typedef enum { - ECMA_COMPLETION_TYPE_NORMAL, /**< default block completion */ - ECMA_COMPLETION_TYPE_RETURN, /**< block completed with return */ - ECMA_COMPLETION_TYPE_BREAK, /**< block completed with break */ - ECMA_COMPLETION_TYPE_CONTINUE, /**< block completed with continue */ - ECMA_COMPLETION_TYPE_THROW, /**< block completed with throw */ - ECMA_COMPLETION_TYPE_EXIT /**< implementation-defined completion type - for finishing script execution */ +typedef enum +{ + ECMA_COMPLETION_TYPE_NORMAL, /**< default block completion */ + ECMA_COMPLETION_TYPE_RETURN, /**< block completed with return */ + ECMA_COMPLETION_TYPE_BREAK, /**< block completed with break */ + ECMA_COMPLETION_TYPE_CONTINUE, /**< block completed with continue */ + ECMA_COMPLETION_TYPE_THROW, /**< block completed with throw */ + ECMA_COMPLETION_TYPE_EXIT /**< implementation-defined completion type + for finishing script execution */ } ecma_completion_type_t; /** * Description of an ecma-value */ -typedef struct { - /** Value type (ecma_type_t) */ - unsigned int value_type : 2; +typedef struct +{ + /** Value type (ecma_type_t) */ + unsigned int value_type : 2; - /** - * Simple value (ecma_simple_value_t) or compressed pointer to value (depending on value_type) - */ - unsigned int value : ECMA_POINTER_FIELD_WIDTH; + /** + * Simple value (ecma_simple_value_t) or compressed pointer to value (depending on value_type) + */ + unsigned int value : ECMA_POINTER_FIELD_WIDTH; } __packed ecma_value_t; /** @@ -122,15 +127,16 @@ typedef struct { * * See also: ECMA-262 v5, 8.9. */ -typedef struct { - /** Type (ecma_completion_type_t) */ - unsigned int type : 3; +typedef struct +{ + /** Type (ecma_completion_type_t) */ + unsigned int type : 3; - /** Value */ - ecma_value_t value; + /** Value */ + ecma_value_t value; - /** Target */ - unsigned int target : 8; + /** Target */ + unsigned int target : 8; } __packed ecma_completion_value_t; /** @@ -142,25 +148,26 @@ typedef struct { /** * Internal properties' identifiers. */ -typedef enum { - ECMA_INTERNAL_PROPERTY_CLASS, /**< [[Class]] */ - ECMA_INTERNAL_PROPERTY_PROTOTYPE, /**< [[Prototype]] */ - ECMA_INTERNAL_PROPERTY_EXTENSIBLE, /**< [[Extensible]] */ - ECMA_INTERNAL_PROPERTY_SCOPE, /**< [[Scope]] */ - ECMA_INTERNAL_PROPERTY_CODE, /**< [[Code]] */ - ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS, /**< [[FormalParameters]] */ +typedef enum +{ + ECMA_INTERNAL_PROPERTY_CLASS, /**< [[Class]] */ + ECMA_INTERNAL_PROPERTY_PROTOTYPE, /**< [[Prototype]] */ + ECMA_INTERNAL_PROPERTY_EXTENSIBLE, /**< [[Extensible]] */ + ECMA_INTERNAL_PROPERTY_SCOPE, /**< [[Scope]] */ + ECMA_INTERNAL_PROPERTY_CODE, /**< [[Code]] */ + ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS, /**< [[FormalParameters]] */ - /** provideThis property of lexical environment */ - ECMA_INTERNAL_PROPERTY_PROVIDE_THIS, + /** provideThis property of lexical environment */ + ECMA_INTERNAL_PROPERTY_PROVIDE_THIS, - /** binding object of lexical environment */ - ECMA_INTERNAL_PROPERTY_BINDING_OBJECT, + /** binding object of lexical environment */ + ECMA_INTERNAL_PROPERTY_BINDING_OBJECT, - /** Part of an array, that is indexed by numbers */ - ECMA_INTERNAL_PROPERTY_NUMBER_INDEXED_ARRAY_VALUES, + /** Part of an array, that is indexed by numbers */ + ECMA_INTERNAL_PROPERTY_NUMBER_INDEXED_ARRAY_VALUES, - /** Part of an array, that is indexed by strings */ - ECMA_INTERNAL_PROPERTY_STRING_INDEXED_ARRAY_VALUES + /** Part of an array, that is indexed by strings */ + ECMA_INTERNAL_PROPERTY_STRING_INDEXED_ARRAY_VALUES } ecma_internal_property_id_t; /** @@ -193,186 +200,198 @@ typedef enum /** * Description of ecma-property */ -typedef struct ecma_property_t { - /** Property's type (ecma_property_type_t) */ - unsigned int type : 2; +typedef struct ecma_property_t +{ + /** Property's type (ecma_property_type_t) */ + unsigned int type : 2; - /** Compressed pointer to next property */ - unsigned int next_property_p : ECMA_POINTER_FIELD_WIDTH; + /** Compressed pointer to next property */ + unsigned int next_property_p : ECMA_POINTER_FIELD_WIDTH; - /** Property's details (depending on Type) */ - union { + /** Property's details (depending on Type) */ + union + { + /** Description of named data property */ + struct __packed ecma_named_data_property_t + { + /** Compressed pointer to property's name (pointer to String) */ + unsigned int name_p : ECMA_POINTER_FIELD_WIDTH; - /** Description of named data property */ - struct __packed ecma_named_data_property_t { - /** Compressed pointer to property's name (pointer to String) */ - unsigned int name_p : ECMA_POINTER_FIELD_WIDTH; + /** Attribute 'Writable' (ecma_property_writable_value_t) */ + unsigned int writable : 1; - /** Attribute 'Writable' (ecma_property_writable_value_t) */ - unsigned int writable : 1; + /** Attribute 'Enumerable' (ecma_property_enumerable_value_t) */ + unsigned int enumerable : 1; - /** Attribute 'Enumerable' (ecma_property_enumerable_value_t) */ - unsigned int enumerable : 1; + /** Attribute 'Configurable' (ecma_property_configurable_value_t) */ + unsigned int configurable : 1; - /** Attribute 'Configurable' (ecma_property_configurable_value_t) */ - unsigned int configurable : 1; + /** Value */ + ecma_value_t value; + } named_data_property; - /** Value */ - ecma_value_t value; - } named_data_property; + /** Description of named accessor property */ + struct __packed ecma_named_accessor_property_t + { + /** Compressed pointer to property's name (pointer to String) */ + unsigned int name_p : ECMA_POINTER_FIELD_WIDTH; - /** Description of named accessor property */ - struct __packed ecma_named_accessor_property_t { - /** Compressed pointer to property's name (pointer to String) */ - unsigned int name_p : ECMA_POINTER_FIELD_WIDTH; + /** Attribute 'Enumerable' (ecma_property_enumerable_value_t) */ + unsigned int enumerable : 1; - /** Attribute 'Enumerable' (ecma_property_enumerable_value_t) */ - unsigned int enumerable : 1; + /** Attribute 'Configurable' (ecma_property_configurable_value_t) */ + unsigned int configurable : 1; - /** Attribute 'Configurable' (ecma_property_configurable_value_t) */ - unsigned int configurable : 1; + /** Compressed pointer to property's getter */ + unsigned int get_p : ECMA_POINTER_FIELD_WIDTH; - /** Compressed pointer to property's getter */ - unsigned int get_p : ECMA_POINTER_FIELD_WIDTH; + /** Compressed pointer to property's setter */ + unsigned int set_p : ECMA_POINTER_FIELD_WIDTH; + } named_accessor_property; - /** Compressed pointer to property's setter */ - unsigned int set_p : ECMA_POINTER_FIELD_WIDTH; - } named_accessor_property; + /** Description of internal property */ + struct __packed ecma_internal_property_t + { + /** Internal property's type */ + unsigned int type : 4; - /** Description of internal property */ - struct __packed ecma_internal_property_t { - /** Internal property's type */ - unsigned int type : 4; - - /** Value (may be a compressed pointer) */ - uint32_t value; - } internal_property; - } u; + /** Value (may be a compressed pointer) */ + uint32_t value; + } internal_property; + } u; } ecma_property_t; /** * Description of GC's information layout */ -typedef struct { - /** - * Reference counter of the object. - * - * Number of references to the object from stack variables. - */ - unsigned int refs : CONFIG_ECMA_REFERENCE_COUNTER_WIDTH; +typedef struct +{ + /** + * Reference counter of the object. + * + * Number of references to the object from stack variables. + */ + unsigned int refs : CONFIG_ECMA_REFERENCE_COUNTER_WIDTH; - /** - * Identifier of GC generation. - */ - unsigned int generation : 2; + /** + * Identifier of GC generation. + */ + unsigned int generation : 2; - /** - * Compressed pointer to next object in the global list of objects with same generation. - */ - unsigned int next : ECMA_POINTER_FIELD_WIDTH; + /** + * Compressed pointer to next object in the global list of objects with same generation. + */ + unsigned int next : ECMA_POINTER_FIELD_WIDTH; - /** - * Marker that is set if the object was visited during graph traverse. - */ - unsigned int visited : 1; + /** + * Marker that is set if the object was visited during graph traverse. + */ + unsigned int visited : 1; - /** - * Flag indicating that the object may reference objects of younger generations in its properties. - */ - unsigned int may_ref_younger_objects : 1; + /** + * Flag indicating that the object may reference objects of younger generations in its properties. + */ + unsigned int may_ref_younger_objects : 1; } __packed ecma_gc_info_t; /** * Types of lexical environments */ -typedef enum { - ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE, /**< declarative lexical environment */ - ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND /**< object-bound lexical environment */ +typedef enum +{ + ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE, /**< declarative lexical environment */ + ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND /**< object-bound lexical environment */ } ecma_lexical_environment_type_t; /** * Internal object types */ -typedef enum { - ECMA_OBJECT_TYPE_GENERAL, /**< all objects that are not String (15.5), Function (15.3), - Arguments (10.6), Array (15.4) specification-defined objects - and not host objects */ - ECMA_OBJECT_TYPE_STRING, /**< String objects (15.5) */ - ECMA_OBJECT_TYPE_FUNCTION, /**< Function objects (15.3), created through 13.2 routine */ - ECMA_OBJECT_TYPE_BOUND_FUNCTION, /**< Function objects (15.3), created through 15.3.4.5 routine */ - ECMA_OBJECT_TYPE_ARGUMENTS, /**< Arguments object (10.6) */ - ECMA_OBJECT_TYPE_ARRAY, /**< Array object (15.4) */ - ECMA_OBJECT_TYPE_HOST /**< Host object */ +typedef enum +{ + ECMA_OBJECT_TYPE_GENERAL, /**< all objects that are not String (15.5), Function (15.3), + Arguments (10.6), Array (15.4) specification-defined objects + and not host objects */ + ECMA_OBJECT_TYPE_STRING, /**< String objects (15.5) */ + ECMA_OBJECT_TYPE_FUNCTION, /**< Function objects (15.3), created through 13.2 routine */ + ECMA_OBJECT_TYPE_BOUND_FUNCTION, /**< Function objects (15.3), created through 15.3.4.5 routine */ + ECMA_OBJECT_TYPE_ARGUMENTS, /**< Arguments object (10.6) */ + ECMA_OBJECT_TYPE_ARRAY, /**< Array object (15.4) */ + ECMA_OBJECT_TYPE_HOST /**< Host object */ } ecma_object_type_t; /** * ECMA-defined object classes */ -typedef enum { - ECMA_OBJECT_CLASS_OBJECT, /**< "Object" */ - ECMA_OBJECT_CLASS_FUNCTION, /**< "Function" */ - ECMA_OBJECT_CLASS_ARGUMENTS, /**< "Arguments" */ - ECMA_OBJECT_CLASS_ARRAY, /**< "Array" */ - ECMA_OBJECT_CLASS_BOOLEAN, /**< "Boolean" */ - ECMA_OBJECT_CLASS_DATE, /**< "Date" */ - ECMA_OBJECT_CLASS_ERROR, /**< "Error" */ - ECMA_OBJECT_CLASS_JSON, /**< "JSON" */ - ECMA_OBJECT_CLASS_MATH, /**< "Math" */ - ECMA_OBJECT_CLASS_NUMBER, /**< "Number" */ - ECMA_OBJECT_CLASS_REGEXP, /**< "RegExp" */ - ECMA_OBJECT_CLASS_STRING /**< "String" */ +typedef enum +{ + ECMA_OBJECT_CLASS_OBJECT, /**< "Object" */ + ECMA_OBJECT_CLASS_FUNCTION, /**< "Function" */ + ECMA_OBJECT_CLASS_ARGUMENTS, /**< "Arguments" */ + ECMA_OBJECT_CLASS_ARRAY, /**< "Array" */ + ECMA_OBJECT_CLASS_BOOLEAN, /**< "Boolean" */ + ECMA_OBJECT_CLASS_DATE, /**< "Date" */ + ECMA_OBJECT_CLASS_ERROR, /**< "Error" */ + ECMA_OBJECT_CLASS_JSON, /**< "JSON" */ + ECMA_OBJECT_CLASS_MATH, /**< "Math" */ + ECMA_OBJECT_CLASS_NUMBER, /**< "Number" */ + ECMA_OBJECT_CLASS_REGEXP, /**< "RegExp" */ + ECMA_OBJECT_CLASS_STRING /**< "String" */ } ecma_object_class_t; /** * Description of ECMA-object or lexical environment * (depending on is_lexical_environment). */ -typedef struct ecma_object_t { - /** Compressed pointer to property list */ - unsigned int properties_p : ECMA_POINTER_FIELD_WIDTH; +typedef struct ecma_object_t +{ + /** Compressed pointer to property list */ + unsigned int properties_p : ECMA_POINTER_FIELD_WIDTH; - /** Flag indicating whether it is a general object (false) - or a lexical environment (true) */ - unsigned int is_lexical_environment : 1; + /** Flag indicating whether it is a general object (false) + or a lexical environment (true) */ + unsigned int is_lexical_environment : 1; + + /** + * Attributes of either general object or lexical environment + * (depending on is_lexical_environment) + */ + union + { + /** + * A general object's attributes (if !is_lexical_environment) + */ + struct + { + /** Attribute 'Extensible' */ + unsigned int extensible : 1; + + /** Implementation internal object type (ecma_object_type_t) */ + unsigned int type : 3; + + /** Compressed pointer to prototype object (ecma_object_t) */ + unsigned int prototype_object_p : ECMA_POINTER_FIELD_WIDTH; + } __packed object; /** - * Attributes of either general object or lexical environment - * (depending on is_lexical_environment) + * A lexical environment's attribute (if is_lexical_environment) */ - union { - /** - * A general object's attributes (if !is_lexical_environment) - */ - struct { - /** Attribute 'Extensible' */ - unsigned int extensible : 1; + struct + { + /** + * Type of lexical environment (ecma_lexical_environment_type_t). + */ + unsigned int type : 1; - /** Implementation internal object type (ecma_object_type_t) */ - unsigned int type : 3; + /** Compressed pointer to outer lexical environment */ + unsigned int outer_reference_p : ECMA_POINTER_FIELD_WIDTH; + } __packed lexical_environment; - /** Compressed pointer to prototype object (ecma_object_t) */ - unsigned int prototype_object_p : ECMA_POINTER_FIELD_WIDTH; - } __packed object; + } __packed u; - /** - * A lexical environment's attribute (if is_lexical_environment) - */ - struct { - /** - * Type of lexical environment (ecma_lexical_environment_type_t). - */ - unsigned int type : 1; + /** GC's information */ + ecma_gc_info_t gc_info; - /** Compressed pointer to outer lexical environment */ - unsigned int outer_reference_p : ECMA_POINTER_FIELD_WIDTH; - } __packed lexical_environment; - - } __packed u; - - /** GC's information */ - ecma_gc_info_t gc_info; - - FIXME(Remove aligned attribute after packing the struct) + FIXME(Remove aligned attribute after packing the struct) } __packed __attribute__ ((aligned (16))) ecma_object_t; /** @@ -451,34 +470,37 @@ typedef uint16_t ecma_length_t; /** * Description of an Array's header */ -typedef struct { - /** Compressed pointer to next chunk */ - uint16_t next_chunk_p; +typedef struct +{ + /** Compressed pointer to next chunk */ + uint16_t next_chunk_p; - /** Number of elements in the Array */ - ecma_length_t unit_number; + /** Number of elements in the Array */ + ecma_length_t unit_number; } ecma_array_header_t; /** * Description of first chunk in a chain of chunks that contains an Array. */ -typedef struct { - /** Array's header */ - ecma_array_header_t header; +typedef struct +{ + /** Array's header */ + ecma_array_header_t header; - /** Elements */ - uint8_t data[ sizeof (uint64_t) - sizeof (ecma_array_header_t) ]; + /** Elements */ + uint8_t data[ sizeof (uint64_t) - sizeof (ecma_array_header_t) ]; } ecma_array_first_chunk_t; /** * Description of non-first chunk in a chain of chunks that contains an Array */ -typedef struct { - /** Compressed pointer to next chunk */ - uint16_t next_chunk_p; +typedef struct +{ + /** Compressed pointer to next chunk */ + uint16_t next_chunk_p; - /** Characters */ - uint8_t data[ sizeof (uint64_t) - sizeof (uint16_t) ]; + /** Characters */ + uint8_t data[ sizeof (uint64_t) - sizeof (uint16_t) ]; } ecma_array_non_first_chunk_t; /** diff --git a/src/libecmaobjects/ecma-helpers-value.c b/src/libecmaobjects/ecma-helpers-value.c index f85dde9ca..298bea578 100644 --- a/src/libecmaobjects/ecma-helpers-value.c +++ b/src/libecmaobjects/ecma-helpers-value.c @@ -72,7 +72,7 @@ bool ecma_is_value_boolean (ecma_value_t value) /**< ecma-value */ { return ((value.value_type == ECMA_TYPE_SIMPLE && value.value == ECMA_SIMPLE_VALUE_FALSE) - || (value.value_type == ECMA_TYPE_SIMPLE && value.value == ECMA_SIMPLE_VALUE_TRUE)); + || (value.value_type == ECMA_TYPE_SIMPLE && value.value == ECMA_SIMPLE_VALUE_TRUE)); } /* ecma_is_value_boolean */ /** @@ -98,7 +98,11 @@ ecma_is_value_true (ecma_value_t value) /**< ecma-value */ ecma_value_t ecma_make_simple_value (ecma_simple_value_t value) /**< simple value */ { - return (ecma_value_t) { .value_type = ECMA_TYPE_SIMPLE, .value = value }; + return (ecma_value_t) + { + .value_type = ECMA_TYPE_SIMPLE, + .value = value + }; } /* ecma_make_simple_value */ /** @@ -180,54 +184,60 @@ ecma_copy_value (const ecma_value_t value, /**< ecma-value */ switch ((ecma_type_t)value.value_type) { case ECMA_TYPE_SIMPLE: - { - value_copy = value; + { + value_copy = value; - break; - } + break; + } case ECMA_TYPE_NUMBER: + { + ecma_number_t *num_p = ECMA_GET_POINTER(value.value); + JERRY_ASSERT(num_p != NULL); + + ecma_number_t *number_copy_p = ecma_alloc_number (); + *number_copy_p = *num_p; + + value_copy = (ecma_value_t) { - ecma_number_t *num_p = ECMA_GET_POINTER(value.value); - JERRY_ASSERT(num_p != NULL); + .value_type = ECMA_TYPE_NUMBER + }; + ECMA_SET_NON_NULL_POINTER(value_copy.value, number_copy_p); - ecma_number_t *number_copy_p = ecma_alloc_number (); - *number_copy_p = *num_p; - - value_copy = (ecma_value_t) { .value_type = ECMA_TYPE_NUMBER }; - ECMA_SET_NON_NULL_POINTER(value_copy.value, number_copy_p); - - break; - } + break; + } case ECMA_TYPE_STRING: + { + ecma_array_first_chunk_t *string_p = ECMA_GET_POINTER(value.value); + JERRY_ASSERT(string_p != NULL); + + ecma_array_first_chunk_t *string_copy_p = ecma_duplicate_ecma_string (string_p); + + value_copy = (ecma_value_t) { - ecma_array_first_chunk_t *string_p = ECMA_GET_POINTER(value.value); - JERRY_ASSERT(string_p != NULL); + .value_type = ECMA_TYPE_STRING + }; + ECMA_SET_POINTER(value_copy.value, string_copy_p); - ecma_array_first_chunk_t *string_copy_p = ecma_duplicate_ecma_string (string_p); - - value_copy = (ecma_value_t) { .value_type = ECMA_TYPE_STRING }; - ECMA_SET_POINTER(value_copy.value, string_copy_p); - - break; - } + break; + } case ECMA_TYPE_OBJECT: + { + ecma_object_t *obj_p = ECMA_GET_POINTER(value.value); + JERRY_ASSERT(obj_p != NULL); + + if (do_ref_if_object) { - ecma_object_t *obj_p = ECMA_GET_POINTER(value.value); - JERRY_ASSERT(obj_p != NULL); - - if (do_ref_if_object) - { - ecma_ref_object (obj_p); - } - - value_copy = value; - - break; + ecma_ref_object (obj_p); } + + value_copy = value; + + break; + } case ECMA_TYPE__COUNT: - { - JERRY_UNREACHABLE(); - } + { + JERRY_UNREACHABLE(); + } } return value_copy; @@ -244,38 +254,38 @@ ecma_free_value (ecma_value_t value, /**< value description */ switch ((ecma_type_t) value.value_type) { case ECMA_TYPE_SIMPLE: - { - /* doesn't hold additional memory */ - break; - } + { + /* doesn't hold additional memory */ + break; + } case ECMA_TYPE_NUMBER: - { - ecma_number_t *number_p = ECMA_GET_POINTER(value.value); - ecma_dealloc_number (number_p); - break; - } + { + ecma_number_t *number_p = ECMA_GET_POINTER(value.value); + ecma_dealloc_number (number_p); + break; + } case ECMA_TYPE_STRING: - { - ecma_array_first_chunk_t *string_p = ECMA_GET_POINTER(value.value); - ecma_free_array (string_p); - break; - } + { + ecma_array_first_chunk_t *string_p = ECMA_GET_POINTER(value.value); + ecma_free_array (string_p); + break; + } case ECMA_TYPE_OBJECT: + { + if (do_deref_if_object) { - if (do_deref_if_object) - { - ecma_deref_object (ECMA_GET_POINTER(value.value)); - } - break; + ecma_deref_object (ECMA_GET_POINTER(value.value)); } + break; + } case ECMA_TYPE__COUNT: - { - JERRY_UNREACHABLE(); - } + { + JERRY_UNREACHABLE(); + } } } /* ecma_free_value */ @@ -286,10 +296,15 @@ ecma_free_value (ecma_value_t value, /**< value description */ */ ecma_completion_value_t ecma_make_completion_value (ecma_completion_type_t type, /**< type */ - ecma_value_t value, /**< value */ - uint8_t target) /**< target */ + ecma_value_t value, /**< value */ + uint8_t target) /**< target */ { - return (ecma_completion_value_t) { .type = type, .value = value, .target = target }; + return (ecma_completion_value_t) + { + .type = type, + .value = value, + .target = target + }; } /* ecma_make_completion_value */ /** @@ -301,9 +316,9 @@ ecma_completion_value_t ecma_make_simple_completion_value (ecma_simple_value_t simple_value) /**< simple ecma-value */ { JERRY_ASSERT(simple_value == ECMA_SIMPLE_VALUE_UNDEFINED - || simple_value == ECMA_SIMPLE_VALUE_NULL - || simple_value == ECMA_SIMPLE_VALUE_FALSE - || simple_value == ECMA_SIMPLE_VALUE_TRUE); + || simple_value == ECMA_SIMPLE_VALUE_NULL + || simple_value == ECMA_SIMPLE_VALUE_FALSE + || simple_value == ECMA_SIMPLE_VALUE_TRUE); return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, ecma_make_simple_value (simple_value), @@ -323,8 +338,8 @@ ecma_make_throw_value (ecma_object_t *exception_p) /**< an object */ ecma_value_t exception = ecma_make_object_value (exception_p); return ecma_make_completion_value (ECMA_COMPLETION_TYPE_THROW, - exception, - ECMA_TARGET_ID_RESERVED); + exception, + ECMA_TARGET_ID_RESERVED); } /* ecma_make_throw_value */ /** @@ -360,18 +375,18 @@ void ecma_free_completion_value (ecma_completion_value_t completion_value) /**< completion value */ { switch (completion_value.type) - { + { case ECMA_COMPLETION_TYPE_NORMAL: case ECMA_COMPLETION_TYPE_THROW: case ECMA_COMPLETION_TYPE_RETURN: - ecma_free_value (completion_value.value, true); - break; + ecma_free_value (completion_value.value, true); + break; case ECMA_COMPLETION_TYPE_CONTINUE: case ECMA_COMPLETION_TYPE_BREAK: case ECMA_COMPLETION_TYPE_EXIT: - JERRY_ASSERT(completion_value.value.value_type == ECMA_TYPE_SIMPLE); - break; - } + JERRY_ASSERT(completion_value.value.value_type == ECMA_TYPE_SIMPLE); + break; + } } /* ecma_free_completion_value */ /** @@ -411,8 +426,8 @@ ecma_is_completion_value_normal_simple_value (ecma_completion_value_t value, /** for equality with */ { return (value.type == ECMA_COMPLETION_TYPE_NORMAL - && value.value.value_type == ECMA_TYPE_SIMPLE - && value.value.value == simple_value); + && value.value.value_type == ECMA_TYPE_SIMPLE + && value.value.value == simple_value); } /* ecma_is_completion_value_normal_simple_value */ /** @@ -452,7 +467,7 @@ bool ecma_is_empty_completion_value (ecma_completion_value_t value) /**< completion value */ { return (ecma_is_completion_value_normal (value) - && ecma_is_value_empty (value.value)); + && ecma_is_value_empty (value.value)); } /* ecma_is_empty_completion_value */ /** diff --git a/src/libecmaobjects/ecma-helpers.c b/src/libecmaobjects/ecma-helpers.c index 7aac921ca..c8575926f 100644 --- a/src/libecmaobjects/ecma-helpers.c +++ b/src/libecmaobjects/ecma-helpers.c @@ -40,17 +40,17 @@ ecma_create_object (ecma_object_t *prototype_object_p, /**< pointer to prototybe bool is_extensible, /**< value of extensible attribute */ ecma_object_type_t type) /**< object type */ { - ecma_object_t *object_p = ecma_alloc_object (); - ecma_init_gc_info (object_p); + ecma_object_t *object_p = ecma_alloc_object (); + ecma_init_gc_info (object_p); - object_p->properties_p = ECMA_NULL_POINTER; - object_p->is_lexical_environment = false; + object_p->properties_p = ECMA_NULL_POINTER; + object_p->is_lexical_environment = false; - object_p->u.object.extensible = is_extensible; - ECMA_SET_POINTER(object_p->u.object.prototype_object_p, prototype_object_p); - object_p->u.object.type = type; + object_p->u.object.extensible = is_extensible; + ECMA_SET_POINTER(object_p->u.object.prototype_object_p, prototype_object_p); + object_p->u.object.type = type; - return object_p; + return object_p; } /* ecma_create_object */ /** @@ -91,8 +91,8 @@ ecma_create_decl_lex_env (ecma_object_t *outer_lexical_environment_p) /**< outer */ ecma_object_t* ecma_create_object_lex_env (ecma_object_t *outer_lexical_environment_p, /**< outer lexical environment */ - ecma_object_t *binding_obj_p, /**< binding object */ - bool provide_this) /**< provideThis flag */ + ecma_object_t *binding_obj_p, /**< binding object */ + bool provide_this) /**< provideThis flag */ { JERRY_ASSERT(binding_obj_p != NULL); @@ -127,20 +127,20 @@ ecma_create_object_lex_env (ecma_object_t *outer_lexical_environment_p, /**< out */ ecma_property_t* ecma_create_internal_property (ecma_object_t *object_p, /**< the object */ - ecma_internal_property_id_t property_id) /**< internal property identifier */ + ecma_internal_property_id_t property_id) /**< internal property identifier */ { - ecma_property_t *new_property_p = ecma_alloc_property (); + ecma_property_t *new_property_p = ecma_alloc_property (); - new_property_p->type = ECMA_PROPERTY_INTERNAL; + new_property_p->type = ECMA_PROPERTY_INTERNAL; - ecma_property_t *list_head_p = ECMA_GET_POINTER(object_p->properties_p); - ECMA_SET_POINTER(new_property_p->next_property_p, list_head_p); - ECMA_SET_NON_NULL_POINTER(object_p->properties_p, new_property_p); + ecma_property_t *list_head_p = ECMA_GET_POINTER(object_p->properties_p); + ECMA_SET_POINTER(new_property_p->next_property_p, list_head_p); + ECMA_SET_NON_NULL_POINTER(object_p->properties_p, new_property_p); - new_property_p->u.internal_property.type = property_id; - new_property_p->u.internal_property.value = ECMA_NULL_POINTER; + new_property_p->u.internal_property.type = property_id; + new_property_p->u.internal_property.value = ECMA_NULL_POINTER; - return new_property_p; + return new_property_p; } /* ecma_create_internal_property */ /** @@ -151,27 +151,27 @@ ecma_create_internal_property (ecma_object_t *object_p, /**< the object */ */ ecma_property_t* ecma_find_internal_property (ecma_object_t *object_p, /**< object descriptor */ - ecma_internal_property_id_t property_id) /**< internal property identifier */ + ecma_internal_property_id_t property_id) /**< internal property identifier */ { - JERRY_ASSERT(object_p != NULL); + JERRY_ASSERT(object_p != NULL); - JERRY_ASSERT(property_id != ECMA_INTERNAL_PROPERTY_PROTOTYPE - && property_id != ECMA_INTERNAL_PROPERTY_EXTENSIBLE); + JERRY_ASSERT(property_id != ECMA_INTERNAL_PROPERTY_PROTOTYPE + && property_id != ECMA_INTERNAL_PROPERTY_EXTENSIBLE); - for (ecma_property_t *property_p = ECMA_GET_POINTER(object_p->properties_p); - property_p != NULL; - property_p = ECMA_GET_POINTER(property_p->next_property_p)) + for (ecma_property_t *property_p = ECMA_GET_POINTER(object_p->properties_p); + property_p != NULL; + property_p = ECMA_GET_POINTER(property_p->next_property_p)) + { + if (property_p->type == ECMA_PROPERTY_INTERNAL) { - if (property_p->type == ECMA_PROPERTY_INTERNAL) - { - if (property_p->u.internal_property.type == property_id) - { - return property_p; - } - } + if (property_p->u.internal_property.type == property_id) + { + return property_p; + } } + } - return NULL; + return NULL; } /* ecma_find_internal_property */ /** @@ -184,13 +184,13 @@ ecma_find_internal_property (ecma_object_t *object_p, /**< object descriptor */ */ ecma_property_t* ecma_get_internal_property (ecma_object_t *object_p, /**< object descriptor */ - ecma_internal_property_id_t property_id) /**< internal property identifier */ + ecma_internal_property_id_t property_id) /**< internal property identifier */ { - ecma_property_t *property_p = ecma_find_internal_property (object_p, property_id); + ecma_property_t *property_p = ecma_find_internal_property (object_p, property_id); - JERRY_ASSERT(property_p != NULL); + JERRY_ASSERT(property_p != NULL); - return property_p; + return property_p; } /* ecma_get_internal_property */ /** @@ -201,10 +201,10 @@ ecma_get_internal_property (ecma_object_t *object_p, /**< object descriptor */ */ ecma_property_t* ecma_create_named_data_property (ecma_object_t *obj_p, /**< object */ - const ecma_char_t *name_p, /**< property name */ - ecma_property_writable_value_t writable, /**< 'writable' attribute */ - ecma_property_enumerable_value_t enumerable, /**< 'enumerable' attribute */ - ecma_property_configurable_value_t configurable) /**< 'configurable' attribute */ + const ecma_char_t *name_p, /**< property name */ + ecma_property_writable_value_t writable, /**< 'writable' attribute */ + ecma_property_enumerable_value_t enumerable, /**< 'enumerable' attribute */ + ecma_property_configurable_value_t configurable) /**< 'configurable' attribute */ { JERRY_ASSERT(obj_p != NULL && name_p != NULL); @@ -235,11 +235,11 @@ ecma_create_named_data_property (ecma_object_t *obj_p, /**< object */ */ ecma_property_t* ecma_create_named_accessor_property (ecma_object_t *obj_p, /**< object */ - const ecma_char_t *name_p, /**< property name */ - ecma_object_t *get_p, /**< getter */ - ecma_object_t *set_p, /**< setter */ - ecma_property_enumerable_value_t enumerable, /**< 'enumerable' attribute */ - ecma_property_configurable_value_t configurable) /**< 'configurable' attribute */ + const ecma_char_t *name_p, /**< property name */ + ecma_object_t *get_p, /**< getter */ + ecma_object_t *set_p, /**< setter */ + ecma_property_enumerable_value_t enumerable, /**< 'enumerable' attribute */ + ecma_property_configurable_value_t configurable) /**< 'configurable' attribute */ { JERRY_ASSERT(obj_p != NULL && name_p != NULL); @@ -273,37 +273,37 @@ ecma_create_named_accessor_property (ecma_object_t *obj_p, /**< object */ */ ecma_property_t* ecma_find_named_property (ecma_object_t *obj_p, /**< object to find property in */ - const ecma_char_t *name_p) /**< property's name */ + const ecma_char_t *name_p) /**< property's name */ { - JERRY_ASSERT(obj_p != NULL); - JERRY_ASSERT(name_p != NULL); + JERRY_ASSERT(obj_p != NULL); + JERRY_ASSERT(name_p != NULL); - for (ecma_property_t *property_p = ECMA_GET_POINTER(obj_p->properties_p); - property_p != NULL; - property_p = ECMA_GET_POINTER(property_p->next_property_p)) + for (ecma_property_t *property_p = ECMA_GET_POINTER(obj_p->properties_p); + property_p != NULL; + property_p = ECMA_GET_POINTER(property_p->next_property_p)) + { + ecma_array_first_chunk_t *property_name_p; + + if (property_p->type == ECMA_PROPERTY_NAMEDDATA) { - ecma_array_first_chunk_t *property_name_p; - - if (property_p->type == ECMA_PROPERTY_NAMEDDATA) - { - property_name_p = ECMA_GET_POINTER(property_p->u.named_data_property.name_p); - } else if (property_p->type == ECMA_PROPERTY_NAMEDACCESSOR) - { - property_name_p = ECMA_GET_POINTER(property_p->u.named_accessor_property.name_p); - } else - { - continue; - } - - JERRY_ASSERT(property_name_p != NULL); - - if (ecma_compare_zt_string_to_ecma_string (name_p, property_name_p)) - { - return property_p; - } + property_name_p = ECMA_GET_POINTER(property_p->u.named_data_property.name_p); + } else if (property_p->type == ECMA_PROPERTY_NAMEDACCESSOR) + { + property_name_p = ECMA_GET_POINTER(property_p->u.named_accessor_property.name_p); + } else + { + continue; } - return NULL; + JERRY_ASSERT(property_name_p != NULL); + + if (ecma_compare_zt_string_to_ecma_string (name_p, property_name_p)) + { + return property_p; + } + } + + return NULL; } /* ecma_find_named_property */ /** @@ -317,16 +317,16 @@ ecma_find_named_property (ecma_object_t *obj_p, /**< object to find property in */ ecma_property_t* ecma_get_named_property (ecma_object_t *obj_p, /**< object to find property in */ - const ecma_char_t *name_p) /**< property's name */ + const ecma_char_t *name_p) /**< property's name */ { - JERRY_ASSERT(obj_p != NULL); - JERRY_ASSERT(name_p != NULL); + JERRY_ASSERT(obj_p != NULL); + JERRY_ASSERT(name_p != NULL); - ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p); + ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p); - JERRY_ASSERT(property_p != NULL); + JERRY_ASSERT(property_p != NULL); - return property_p; + return property_p; } /* ecma_get_named_property */ /** @@ -340,16 +340,16 @@ ecma_get_named_property (ecma_object_t *obj_p, /**< object to find property in * */ ecma_property_t* ecma_get_named_data_property (ecma_object_t *obj_p, /**< object to find property in */ - const ecma_char_t *name_p) /**< property's name */ + const ecma_char_t *name_p) /**< property's name */ { - JERRY_ASSERT(obj_p != NULL); - JERRY_ASSERT(name_p != NULL); + JERRY_ASSERT(obj_p != NULL); + JERRY_ASSERT(name_p != NULL); - ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p); + ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p); - JERRY_ASSERT(property_p != NULL && property_p->type == ECMA_PROPERTY_NAMEDDATA); + JERRY_ASSERT(property_p != NULL && property_p->type == ECMA_PROPERTY_NAMEDDATA); - return property_p; + return property_p; } /* ecma_get_named_data_property */ /** @@ -395,10 +395,10 @@ ecma_free_internal_property (ecma_property_t *property_p) /**< the property */ case ECMA_INTERNAL_PROPERTY_NUMBER_INDEXED_ARRAY_VALUES: /* an array */ case ECMA_INTERNAL_PROPERTY_STRING_INDEXED_ARRAY_VALUES: /* an array */ case ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS: /* an array */ - { - ecma_free_array (ECMA_GET_POINTER(property_value)); - break; - } + { + ecma_free_array (ECMA_GET_POINTER(property_value)); + break; + } case ECMA_INTERNAL_PROPERTY_SCOPE: /* a lexical environment */ case ECMA_INTERNAL_PROPERTY_BINDING_OBJECT: /* an object */ @@ -407,9 +407,9 @@ ecma_free_internal_property (ecma_property_t *property_p) /**< the property */ case ECMA_INTERNAL_PROPERTY_PROVIDE_THIS: /* a boolean */ case ECMA_INTERNAL_PROPERTY_CLASS: /* an enum */ case ECMA_INTERNAL_PROPERTY_CODE: /* an integer */ - { - break; - } + { + break; + } } ecma_dealloc_property (property_p); @@ -424,25 +424,25 @@ ecma_free_property (ecma_property_t *prop_p) /**< property */ switch ((ecma_property_type_t) prop_p->type) { case ECMA_PROPERTY_NAMEDDATA: - { - ecma_free_named_data_property (prop_p); + { + ecma_free_named_data_property (prop_p); - break; - } + break; + } case ECMA_PROPERTY_NAMEDACCESSOR: - { - ecma_free_named_accessor_property (prop_p); + { + ecma_free_named_accessor_property (prop_p); - break; - } + break; + } case ECMA_PROPERTY_INTERNAL: - { - ecma_free_internal_property (prop_p); + { + ecma_free_internal_property (prop_p); - break; - } + break; + } } } /* ecma_free_property */ @@ -453,11 +453,11 @@ ecma_free_property (ecma_property_t *prop_p) /**< property */ */ void ecma_delete_property (ecma_object_t *obj_p, /**< object */ - ecma_property_t *prop_p) /**< property */ + ecma_property_t *prop_p) /**< property */ { for (ecma_property_t *cur_prop_p = ECMA_GET_POINTER(obj_p->properties_p), *prev_prop_p = NULL, *next_prop_p; - cur_prop_p != NULL; - prev_prop_p = cur_prop_p, cur_prop_p = next_prop_p) + cur_prop_p != NULL; + prev_prop_p = cur_prop_p, cur_prop_p = next_prop_p) { next_prop_p = ECMA_GET_POINTER(cur_prop_p->next_property_p); @@ -488,51 +488,51 @@ ecma_delete_property (ecma_object_t *obj_p, /**< object */ ecma_array_first_chunk_t* ecma_new_ecma_string (const ecma_char_t *string_p) /**< zero-terminated string of ecma-characters */ { - ecma_length_t length = 0; + ecma_length_t length = 0; - /* - * TODO: Do not precalculate length. - */ - if (string_p != NULL) + /* + * TODO: Do not precalculate length. + */ + if (string_p != NULL) + { + const ecma_char_t *iter_p = string_p; + while (*iter_p++) { - const ecma_char_t *iter_p = string_p; - while (*iter_p++) - { - length++; - } + length++; } + } - ecma_array_first_chunk_t *string_first_chunk_p = ecma_alloc_array_first_chunk (); + ecma_array_first_chunk_t *string_first_chunk_p = ecma_alloc_array_first_chunk (); - string_first_chunk_p->header.unit_number = length; - uint8_t *copy_pointer = (uint8_t*) string_p; - size_t chars_left = length; - size_t chars_to_copy = JERRY_MIN(length, sizeof (string_first_chunk_p->data) / sizeof (ecma_char_t)); - __memcpy (string_first_chunk_p->data, copy_pointer, chars_to_copy * sizeof (ecma_char_t)); + string_first_chunk_p->header.unit_number = length; + uint8_t *copy_pointer = (uint8_t*) string_p; + size_t chars_left = length; + size_t chars_to_copy = JERRY_MIN(length, sizeof (string_first_chunk_p->data) / sizeof (ecma_char_t)); + __memcpy (string_first_chunk_p->data, copy_pointer, chars_to_copy * sizeof (ecma_char_t)); + chars_left -= chars_to_copy; + copy_pointer += chars_to_copy * sizeof (ecma_char_t); + + ecma_array_non_first_chunk_t *string_non_first_chunk_p; + + JERRY_STATIC_ASSERT(ECMA_POINTER_FIELD_WIDTH <= sizeof (uint16_t) * JERRY_BITSINBYTE); + uint16_t *next_chunk_compressed_pointer_p = &string_first_chunk_p->header.next_chunk_p; + + while (chars_left > 0) + { + string_non_first_chunk_p = ecma_alloc_array_non_first_chunk (); + + size_t chars_to_copy = JERRY_MIN(chars_left, sizeof (string_non_first_chunk_p->data) / sizeof (ecma_char_t)); + __memcpy (string_non_first_chunk_p->data, copy_pointer, chars_to_copy * sizeof (ecma_char_t)); chars_left -= chars_to_copy; copy_pointer += chars_to_copy * sizeof (ecma_char_t); - ecma_array_non_first_chunk_t *string_non_first_chunk_p; + ECMA_SET_NON_NULL_POINTER(*next_chunk_compressed_pointer_p, string_non_first_chunk_p); + next_chunk_compressed_pointer_p = &string_non_first_chunk_p->next_chunk_p; + } - JERRY_STATIC_ASSERT(ECMA_POINTER_FIELD_WIDTH <= sizeof (uint16_t) * JERRY_BITSINBYTE); - uint16_t *next_chunk_compressed_pointer_p = &string_first_chunk_p->header.next_chunk_p; + *next_chunk_compressed_pointer_p = ECMA_NULL_POINTER; - while (chars_left > 0) - { - string_non_first_chunk_p = ecma_alloc_array_non_first_chunk (); - - size_t chars_to_copy = JERRY_MIN(chars_left, sizeof (string_non_first_chunk_p->data) / sizeof (ecma_char_t)); - __memcpy (string_non_first_chunk_p->data, copy_pointer, chars_to_copy * sizeof (ecma_char_t)); - chars_left -= chars_to_copy; - copy_pointer += chars_to_copy * sizeof (ecma_char_t); - - ECMA_SET_NON_NULL_POINTER(*next_chunk_compressed_pointer_p, string_non_first_chunk_p); - next_chunk_compressed_pointer_p = &string_non_first_chunk_p->next_chunk_p; - } - - *next_chunk_compressed_pointer_p = ECMA_NULL_POINTER; - - return string_first_chunk_p; + return string_first_chunk_p; } /* ecma_new_ecma_string */ /** @@ -546,43 +546,43 @@ ecma_new_ecma_string (const ecma_char_t *string_p) /**< zero-terminated string o */ ssize_t ecma_copy_ecma_string_chars_to_buffer (ecma_array_first_chunk_t *first_chunk_p, /**< first chunk of ecma-string */ - uint8_t *buffer_p, /**< destination buffer */ - size_t buffer_size) /**< size of buffer */ + uint8_t *buffer_p, /**< destination buffer */ + size_t buffer_size) /**< size of buffer */ { - ecma_length_t string_length = first_chunk_p->header.unit_number; - size_t required_buffer_size = sizeof (ecma_length_t) + sizeof (ecma_char_t) * string_length; + ecma_length_t string_length = first_chunk_p->header.unit_number; + size_t required_buffer_size = sizeof (ecma_length_t) + sizeof (ecma_char_t) * string_length; - if (required_buffer_size > buffer_size) - { - return - (ssize_t) required_buffer_size; - } + if (required_buffer_size > buffer_size) + { + return - (ssize_t) required_buffer_size; + } - *(ecma_length_t*) buffer_p = string_length; + *(ecma_length_t*) buffer_p = string_length; - size_t chars_left = string_length; - uint8_t *dest_pointer = buffer_p + sizeof (ecma_length_t); - size_t copy_chunk_chars = JERRY_MIN(sizeof (first_chunk_p->data) / sizeof (ecma_char_t), + size_t chars_left = string_length; + uint8_t *dest_pointer = buffer_p + sizeof (ecma_length_t); + size_t copy_chunk_chars = JERRY_MIN(sizeof (first_chunk_p->data) / sizeof (ecma_char_t), chars_left); - __memcpy (dest_pointer, first_chunk_p->data, copy_chunk_chars * sizeof (ecma_char_t)); + __memcpy (dest_pointer, first_chunk_p->data, copy_chunk_chars * sizeof (ecma_char_t)); + dest_pointer += copy_chunk_chars * sizeof (ecma_char_t); + chars_left -= copy_chunk_chars; + + ecma_array_non_first_chunk_t *non_first_chunk_p = ECMA_GET_POINTER(first_chunk_p->header.next_chunk_p); + + while (chars_left > 0) + { + JERRY_ASSERT(chars_left < string_length); + + copy_chunk_chars = JERRY_MIN(sizeof (non_first_chunk_p->data) / sizeof (ecma_char_t), + chars_left); + __memcpy (dest_pointer, non_first_chunk_p->data, copy_chunk_chars * sizeof (ecma_char_t)); dest_pointer += copy_chunk_chars * sizeof (ecma_char_t); chars_left -= copy_chunk_chars; - ecma_array_non_first_chunk_t *non_first_chunk_p = ECMA_GET_POINTER(first_chunk_p->header.next_chunk_p); + non_first_chunk_p = ECMA_GET_POINTER(non_first_chunk_p->next_chunk_p); + } - while (chars_left > 0) - { - JERRY_ASSERT(chars_left < string_length); - - copy_chunk_chars = JERRY_MIN(sizeof (non_first_chunk_p->data) / sizeof (ecma_char_t), - chars_left); - __memcpy (dest_pointer, non_first_chunk_p->data, copy_chunk_chars * sizeof (ecma_char_t)); - dest_pointer += copy_chunk_chars * sizeof (ecma_char_t); - chars_left -= copy_chunk_chars; - - non_first_chunk_p = ECMA_GET_POINTER(non_first_chunk_p->next_chunk_p); - } - - return (ssize_t) required_buffer_size; + return (ssize_t) required_buffer_size; } /* ecma_copy_ecma_string_chars_to_buffer */ /** @@ -593,29 +593,29 @@ ecma_copy_ecma_string_chars_to_buffer (ecma_array_first_chunk_t *first_chunk_p, ecma_array_first_chunk_t* ecma_duplicate_ecma_string (ecma_array_first_chunk_t *first_chunk_p) /**< first chunk of string to duplicate */ { - JERRY_ASSERT(first_chunk_p != NULL); + JERRY_ASSERT(first_chunk_p != NULL); - ecma_array_first_chunk_t *first_chunk_copy_p = ecma_alloc_array_first_chunk (); - __memcpy (first_chunk_copy_p, first_chunk_p, sizeof (ecma_array_first_chunk_t)); + ecma_array_first_chunk_t *first_chunk_copy_p = ecma_alloc_array_first_chunk (); + __memcpy (first_chunk_copy_p, first_chunk_p, sizeof (ecma_array_first_chunk_t)); - ecma_array_non_first_chunk_t *non_first_chunk_p, *non_first_chunk_copy_p; - non_first_chunk_p = ECMA_GET_POINTER(first_chunk_p->header.next_chunk_p); - uint16_t *next_pointer_p = &first_chunk_copy_p->header.next_chunk_p; + ecma_array_non_first_chunk_t *non_first_chunk_p, *non_first_chunk_copy_p; + non_first_chunk_p = ECMA_GET_POINTER(first_chunk_p->header.next_chunk_p); + uint16_t *next_pointer_p = &first_chunk_copy_p->header.next_chunk_p; - while (non_first_chunk_p != NULL) - { - non_first_chunk_copy_p = ecma_alloc_array_non_first_chunk (); - ECMA_SET_POINTER(*next_pointer_p, non_first_chunk_copy_p); - next_pointer_p = &non_first_chunk_copy_p->next_chunk_p; + while (non_first_chunk_p != NULL) + { + non_first_chunk_copy_p = ecma_alloc_array_non_first_chunk (); + ECMA_SET_POINTER(*next_pointer_p, non_first_chunk_copy_p); + next_pointer_p = &non_first_chunk_copy_p->next_chunk_p; - __memcpy (non_first_chunk_copy_p, non_first_chunk_p, sizeof (ecma_array_non_first_chunk_t)); + __memcpy (non_first_chunk_copy_p, non_first_chunk_p, sizeof (ecma_array_non_first_chunk_t)); - non_first_chunk_p = ECMA_GET_POINTER(non_first_chunk_p->next_chunk_p); - } + non_first_chunk_p = ECMA_GET_POINTER(non_first_chunk_p->next_chunk_p); + } - *next_pointer_p = ECMA_NULL_POINTER; + *next_pointer_p = ECMA_NULL_POINTER; - return first_chunk_copy_p; + return first_chunk_copy_p; } /* ecma_duplicate_ecma_string */ /** @@ -626,7 +626,7 @@ ecma_duplicate_ecma_string (ecma_array_first_chunk_t *first_chunk_p) /**< first */ bool ecma_compare_ecma_string_to_ecma_string (const ecma_array_first_chunk_t *string1_p, /* ecma-string */ - const ecma_array_first_chunk_t *string2_p) /* ecma-string */ + const ecma_array_first_chunk_t *string2_p) /* ecma-string */ { JERRY_UNIMPLEMENTED_REF_UNUSED_VARS(string1_p, string2_p); } /* ecma_compare_ecma_string_to_ecma_string */ @@ -639,51 +639,51 @@ ecma_compare_ecma_string_to_ecma_string (const ecma_array_first_chunk_t *string1 */ bool ecma_compare_zt_string_to_ecma_string (const ecma_char_t *string_p, /**< zero-terminated string */ - const ecma_array_first_chunk_t *ecma_string_p) /* ecma-string */ + const ecma_array_first_chunk_t *ecma_string_p) /* ecma-string */ { JERRY_ASSERT(string_p != NULL); JERRY_ASSERT(ecma_string_p != NULL); const ecma_char_t *str_iter_p = string_p; ecma_length_t ecma_str_len = ecma_string_p->header.unit_number; - const ecma_char_t *current_chunk_chars_cur = (const ecma_char_t*) ecma_string_p->data, - *current_chunk_chars_end = (const ecma_char_t*) (ecma_string_p->data - + sizeof (ecma_string_p->data)); + const ecma_char_t *current_chunk_chars_cur = (const ecma_char_t*) ecma_string_p->data; + const ecma_char_t *current_chunk_chars_end = (const ecma_char_t*) (ecma_string_p->data + + sizeof (ecma_string_p->data)); JERRY_STATIC_ASSERT(ECMA_POINTER_FIELD_WIDTH <= sizeof (uint16_t) * JERRY_BITSINBYTE); const uint16_t *next_chunk_compressed_pointer_p = &ecma_string_p->header.next_chunk_p; for (ecma_length_t str_index = 0; - str_index < ecma_str_len; - str_index++, str_iter_p++, current_chunk_chars_cur++) + str_index < ecma_str_len; + str_index++, str_iter_p++, current_chunk_chars_cur++) + { + JERRY_ASSERT(current_chunk_chars_cur <= current_chunk_chars_end); + + if (current_chunk_chars_cur == current_chunk_chars_end) { - JERRY_ASSERT(current_chunk_chars_cur <= current_chunk_chars_end); + /* switching to next chunk */ + ecma_array_non_first_chunk_t *next_chunk_p = ECMA_GET_POINTER(*next_chunk_compressed_pointer_p); - if (current_chunk_chars_cur == current_chunk_chars_end) - { - /* switching to next chunk */ - ecma_array_non_first_chunk_t *next_chunk_p = ECMA_GET_POINTER(*next_chunk_compressed_pointer_p); + JERRY_ASSERT(next_chunk_p != NULL); - JERRY_ASSERT(next_chunk_p != NULL); + current_chunk_chars_cur = (const ecma_char_t*) next_chunk_p->data; + current_chunk_chars_end = (const ecma_char_t*) (next_chunk_p->data + sizeof (next_chunk_p->data)); - current_chunk_chars_cur = (const ecma_char_t*) next_chunk_p->data; - current_chunk_chars_end = (const ecma_char_t*) (next_chunk_p->data + sizeof (next_chunk_p->data)); - - next_chunk_compressed_pointer_p = &next_chunk_p->next_chunk_p; - } - - if (*str_iter_p != *current_chunk_chars_cur) - { - /* - * Either *str_iter_p is 0 (zero-terminated string is shorter), - * or the character is just different. - * - * In both cases strings are not equal. - */ - return false; - } + next_chunk_compressed_pointer_p = &next_chunk_p->next_chunk_p; } + if (*str_iter_p != *current_chunk_chars_cur) + { + /* + * Either *str_iter_p is 0 (zero-terminated string is shorter), + * or the character is just different. + * + * In both cases strings are not equal. + */ + return false; + } + } + /* * Now, we have reached end of ecma-string. * @@ -699,20 +699,20 @@ ecma_compare_zt_string_to_ecma_string (const ecma_char_t *string_p, /**< zero-te void ecma_free_array (ecma_array_first_chunk_t *first_chunk_p) /**< first chunk of the array */ { - JERRY_ASSERT(first_chunk_p != NULL); + JERRY_ASSERT(first_chunk_p != NULL); - ecma_array_non_first_chunk_t *non_first_chunk_p = ECMA_GET_POINTER(first_chunk_p->header.next_chunk_p); + ecma_array_non_first_chunk_t *non_first_chunk_p = ECMA_GET_POINTER(first_chunk_p->header.next_chunk_p); - ecma_dealloc_array_first_chunk (first_chunk_p); + ecma_dealloc_array_first_chunk (first_chunk_p); - while (non_first_chunk_p != NULL) - { - ecma_array_non_first_chunk_t *next_chunk_p = ECMA_GET_POINTER(non_first_chunk_p->next_chunk_p); + while (non_first_chunk_p != NULL) + { + ecma_array_non_first_chunk_t *next_chunk_p = ECMA_GET_POINTER(non_first_chunk_p->next_chunk_p); - ecma_dealloc_array_non_first_chunk (non_first_chunk_p); + ecma_dealloc_array_non_first_chunk (non_first_chunk_p); - non_first_chunk_p = next_chunk_p; - } + non_first_chunk_p = next_chunk_p; + } } /* ecma_free_array */ /** @@ -724,24 +724,25 @@ ecma_free_array (ecma_array_first_chunk_t *first_chunk_p) /**< first chunk of th ecma_property_descriptor_t ecma_make_empty_property_descriptor (void) { - ecma_property_descriptor_t prop_desc = (ecma_property_descriptor_t) { - .is_value_defined = false, - .value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED), + ecma_property_descriptor_t prop_desc = (ecma_property_descriptor_t) + { + .is_value_defined = false, + .value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED), - .is_writable_defined = false, - .writable = ECMA_PROPERTY_NOT_WRITABLE, + .is_writable_defined = false, + .writable = ECMA_PROPERTY_NOT_WRITABLE, - .is_enumerable_defined = false, - .enumerable = ECMA_PROPERTY_NOT_ENUMERABLE, + .is_enumerable_defined = false, + .enumerable = ECMA_PROPERTY_NOT_ENUMERABLE, - .is_configurable_defined = false, - .configurable = ECMA_PROPERTY_NOT_CONFIGURABLE, + .is_configurable_defined = false, + .configurable = ECMA_PROPERTY_NOT_CONFIGURABLE, - .is_get_defined = false, - .get_p = NULL, + .is_get_defined = false, + .get_p = NULL, - .is_set_defined = false, - .set_p = NULL + .is_set_defined = false, + .set_p = NULL }; return prop_desc; diff --git a/src/libecmaobjects/ecma-helpers.h b/src/libecmaobjects/ecma-helpers.h index ec297385a..c84c36e1f 100644 --- a/src/libecmaobjects/ecma-helpers.h +++ b/src/libecmaobjects/ecma-helpers.h @@ -30,28 +30,29 @@ * Get value of pointer from specified compressed pointer field. */ #define ECMA_GET_POINTER(field) \ - ((unlikely (field == ECMA_NULL_POINTER)) ? NULL : mem_decompress_pointer (field)) + ((unlikely (field == ECMA_NULL_POINTER)) ? NULL : mem_decompress_pointer (field)) /** * Set value of compressed pointer field so that it will correspond * to specified non_compressed_pointer. */ #define ECMA_SET_POINTER(field, non_compressed_pointer) \ - do { \ - void *__temp_pointer = non_compressed_pointer; \ - non_compressed_pointer = __temp_pointer; \ - } \ - while (0); \ - (field) = (unlikely ((non_compressed_pointer) == NULL) ? ECMA_NULL_POINTER \ - : mem_compress_pointer (non_compressed_pointer) \ - & ((1u << ECMA_POINTER_FIELD_WIDTH) - 1)) + do \ + { \ + void *__temp_pointer = non_compressed_pointer; \ + non_compressed_pointer = __temp_pointer; \ + } while (0); \ + \ + (field) = (unlikely ((non_compressed_pointer) == NULL) ? ECMA_NULL_POINTER \ + : (mem_compress_pointer (non_compressed_pointer) \ + & ((1u << ECMA_POINTER_FIELD_WIDTH) - 1))) /** * Set value of non-null compressed pointer field so that it will correspond * to specified non_compressed_pointer. */ #define ECMA_SET_NON_NULL_POINTER(field, non_compressed_pointer) \ - (field) = (mem_compress_pointer (non_compressed_pointer) & ((1u << ECMA_POINTER_FIELD_WIDTH) - 1)) + (field) = (mem_compress_pointer (non_compressed_pointer) & ((1u << ECMA_POINTER_FIELD_WIDTH) - 1)) /* ecma-helpers-value.c */ extern bool ecma_is_value_empty (ecma_value_t value); diff --git a/src/libecmaoperations/ecma-comparison.c b/src/libecmaoperations/ecma-comparison.c index 001f99c1d..c32da69b5 100644 --- a/src/libecmaoperations/ecma-comparison.c +++ b/src/libecmaoperations/ecma-comparison.c @@ -36,7 +36,7 @@ */ bool ecma_op_abstract_equality_compare (ecma_value_t x, /**< first operand */ - ecma_value_t y) /**< second operand */ + ecma_value_t y) /**< second operand */ { const bool is_x_undefined = ecma_is_value_undefined (x); const bool is_x_null = ecma_is_value_null (x); @@ -53,18 +53,18 @@ ecma_op_abstract_equality_compare (ecma_value_t x, /**< first operand */ const bool is_y_object = (y.value_type == ECMA_TYPE_OBJECT); const bool is_types_equal = ((is_x_undefined && is_y_undefined) - || (is_x_null && is_y_null) - || (is_x_boolean && is_y_boolean) - || (is_x_number && is_y_number) - || (is_x_string && is_y_string) - || (is_x_object && is_y_object)); + || (is_x_null && is_y_null) + || (is_x_boolean && is_y_boolean) + || (is_x_number && is_y_number) + || (is_x_string && is_y_string) + || (is_x_object && is_y_object)); if (is_types_equal) { // 1. if (is_x_undefined - || is_x_null) + || is_x_null) { // a., b. return true; @@ -92,7 +92,7 @@ ecma_op_abstract_equality_compare (ecma_value_t x, /**< first operand */ return (x.value == y.value); } } else if ((is_x_null && is_y_undefined) - || (is_x_undefined && is_y_null)) + || (is_x_undefined && is_y_null)) { // 2., 3. return true; } else @@ -111,8 +111,8 @@ ecma_op_abstract_equality_compare (ecma_value_t x, /**< first operand */ */ ecma_completion_value_t ecma_op_abstract_relational_compare (ecma_value_t x, /**< first operand */ - ecma_value_t y, /**< second operand */ - bool left_first) /**< 'LeftFirst' flag */ + ecma_value_t y, /**< second operand */ + bool left_first) /**< 'LeftFirst' flag */ { ecma_completion_value_t ret_value, px, py; @@ -134,38 +134,38 @@ ecma_op_abstract_relational_compare (ecma_value_t x, /**< first operand */ const bool is_py_string = (py.value.value_type == ECMA_TYPE_STRING); if (!(is_px_string && is_py_string)) - { // 3. - // a. - ECMA_TRY_CATCH(nx, ecma_op_to_number (px.value), ret_value); + { // 3. + // a. + ECMA_TRY_CATCH(nx, ecma_op_to_number (px.value), ret_value); - // b. - ECMA_TRY_CATCH(ny, ecma_op_to_number (py.value), ret_value); + // b. + ECMA_TRY_CATCH(ny, ecma_op_to_number (py.value), ret_value); - ecma_number_t* num_x_p = (ecma_number_t*)ECMA_GET_POINTER(nx.value.value); - ecma_number_t* num_y_p = (ecma_number_t*)ECMA_GET_POINTER(ny.value.value); + ecma_number_t* num_x_p = (ecma_number_t*)ECMA_GET_POINTER(nx.value.value); + ecma_number_t* num_y_p = (ecma_number_t*)ECMA_GET_POINTER(ny.value.value); - TODO(/* Implement according to ECMA */); + TODO(/* Implement according to ECMA */); - if (*num_x_p >= *num_y_p) - { - ret_value = ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, - ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE), - ECMA_TARGET_ID_RESERVED); - } - else - { - ret_value = ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, - ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE), - ECMA_TARGET_ID_RESERVED); - } - - ECMA_FINALIZE(ny); - ECMA_FINALIZE(nx); + if (*num_x_p >= *num_y_p) + { + ret_value = ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, + ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE), + ECMA_TARGET_ID_RESERVED); } + else + { + ret_value = ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, + ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE), + ECMA_TARGET_ID_RESERVED); + } + + ECMA_FINALIZE(ny); + ECMA_FINALIZE(nx); + } else - { // 4. - JERRY_UNIMPLEMENTED(); - } + { // 4. + JERRY_UNIMPLEMENTED(); + } ECMA_FINALIZE(prim_second_converted_value); ECMA_FINALIZE(prim_first_converted_value); diff --git a/src/libecmaoperations/ecma-conversion.c b/src/libecmaoperations/ecma-conversion.c index fb00c87a0..f857463b2 100644 --- a/src/libecmaoperations/ecma-conversion.c +++ b/src/libecmaoperations/ecma-conversion.c @@ -43,32 +43,34 @@ ecma_op_check_object_coercible (ecma_value_t value) /**< ecma-value */ switch ((ecma_type_t)value.value_type) { case ECMA_TYPE_SIMPLE: + { + if (ecma_is_value_undefined (value)) { - if (ecma_is_value_undefined (value)) - { - return ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); - } - else if (ecma_is_value_boolean (value)) - { - break; - } - else - { - JERRY_UNREACHABLE(); - } - - break; + return ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } - case ECMA_TYPE_NUMBER: - case ECMA_TYPE_STRING: - case ECMA_TYPE_OBJECT: + else if (ecma_is_value_boolean (value)) { break; } - case ECMA_TYPE__COUNT: + else { JERRY_UNREACHABLE(); } + + break; + } + + case ECMA_TYPE_NUMBER: + case ECMA_TYPE_STRING: + case ECMA_TYPE_OBJECT: + { + break; + } + + case ECMA_TYPE__COUNT: + { + JERRY_UNREACHABLE(); + } } return ecma_make_empty_completion_value (); @@ -102,45 +104,45 @@ ecma_op_same_value (ecma_value_t x, /**< ecma-value */ const bool is_y_object = (y.value_type == ECMA_TYPE_OBJECT); const bool is_types_equal = ((is_x_undefined && is_y_undefined) - || (is_x_null && is_y_null) - || (is_x_boolean && is_y_boolean) - || (is_x_number && is_y_number) - || (is_x_string && is_y_string) - || (is_x_object && is_y_object)); + || (is_x_null && is_y_null) + || (is_x_boolean && is_y_boolean) + || (is_x_number && is_y_number) + || (is_x_string && is_y_string) + || (is_x_object && is_y_object)); if (!is_types_equal) - { - return false; - } + { + return false; + } if (is_x_undefined - || is_x_null) - { - return true; - } + || is_x_null) + { + return true; + } if (is_x_number) - { - TODO(Implement according to ECMA); + { + TODO(Implement according to ECMA); - ecma_number_t *x_num_p = (ecma_number_t*)ECMA_GET_POINTER(x.value); - ecma_number_t *y_num_p = (ecma_number_t*)ECMA_GET_POINTER(y.value); + ecma_number_t *x_num_p = (ecma_number_t*)ECMA_GET_POINTER(x.value); + ecma_number_t *y_num_p = (ecma_number_t*)ECMA_GET_POINTER(y.value); - return (*x_num_p == *y_num_p); - } + return (*x_num_p == *y_num_p); + } if (is_x_string) - { - ecma_array_first_chunk_t* x_str_p = (ecma_array_first_chunk_t*)(ECMA_GET_POINTER(x.value)); - ecma_array_first_chunk_t* y_str_p = (ecma_array_first_chunk_t*)(ECMA_GET_POINTER(y.value)); + { + ecma_array_first_chunk_t* x_str_p = (ecma_array_first_chunk_t*)(ECMA_GET_POINTER(x.value)); + ecma_array_first_chunk_t* y_str_p = (ecma_array_first_chunk_t*)(ECMA_GET_POINTER(y.value)); - return ecma_compare_ecma_string_to_ecma_string (x_str_p, y_str_p); - } + return ecma_compare_ecma_string_to_ecma_string (x_str_p, y_str_p); + } if (is_x_boolean) - { - return (ecma_is_value_true (x) == ecma_is_value_true (y)); - } + { + return (ecma_is_value_true (x) == ecma_is_value_true (y)); + } JERRY_ASSERT(is_x_object); @@ -165,19 +167,21 @@ ecma_op_to_primitive (ecma_value_t value, /**< ecma-value */ case ECMA_TYPE_SIMPLE: case ECMA_TYPE_NUMBER: case ECMA_TYPE_STRING: - { - return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, - ecma_copy_value (value, true), - ECMA_TARGET_ID_RESERVED); - } + { + return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, + ecma_copy_value (value, true), + ECMA_TARGET_ID_RESERVED); + } + case ECMA_TYPE_OBJECT: - { - JERRY_UNIMPLEMENTED_REF_UNUSED_VARS(preferred_type); - } + { + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS(preferred_type); + } + case ECMA_TYPE__COUNT: - { - JERRY_UNREACHABLE(); - } + { + JERRY_UNREACHABLE(); + } } JERRY_UNREACHABLE(); @@ -199,51 +203,51 @@ ecma_op_to_boolean (ecma_value_t value) /**< ecma-value */ switch ((ecma_type_t)value.value_type) { case ECMA_TYPE_NUMBER: - { - ecma_number_t *num_p = ECMA_GET_POINTER(value.value); + { + ecma_number_t *num_p = ECMA_GET_POINTER(value.value); - TODO(Implement according to ECMA); + TODO(Implement according to ECMA); - return ecma_make_simple_completion_value ((*num_p == 0) ? ECMA_SIMPLE_VALUE_FALSE - : ECMA_SIMPLE_VALUE_TRUE); + return ecma_make_simple_completion_value ((*num_p == 0) ? ECMA_SIMPLE_VALUE_FALSE + : ECMA_SIMPLE_VALUE_TRUE); - break; - } + break; + } case ECMA_TYPE_SIMPLE: + { + if (ecma_is_value_boolean (value)) { - if (ecma_is_value_boolean (value)) - { - return ecma_make_simple_completion_value (value.value); - } else if (ecma_is_value_undefined (value) - || ecma_is_value_null (value)) - { - return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); - } else - { - JERRY_UNREACHABLE(); - } - - break; - } - case ECMA_TYPE_STRING: + return ecma_make_simple_completion_value (value.value); + } else if (ecma_is_value_undefined (value) + || ecma_is_value_null (value)) { - ecma_array_first_chunk_t *str_p = ECMA_GET_POINTER(value.value); - - return ecma_make_simple_completion_value ((str_p->header.unit_number == 0) ? ECMA_SIMPLE_VALUE_FALSE - : ECMA_SIMPLE_VALUE_TRUE); - - break; - } - case ECMA_TYPE_OBJECT: - { - return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE); - - break; - } - case ECMA_TYPE__COUNT: + return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); + } else { JERRY_UNREACHABLE(); } + + break; + } + case ECMA_TYPE_STRING: + { + ecma_array_first_chunk_t *str_p = ECMA_GET_POINTER(value.value); + + return ecma_make_simple_completion_value ((str_p->header.unit_number == 0) ? ECMA_SIMPLE_VALUE_FALSE + : ECMA_SIMPLE_VALUE_TRUE); + + break; + } + case ECMA_TYPE_OBJECT: + { + return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE); + + break; + } + case ECMA_TYPE__COUNT: + { + JERRY_UNREACHABLE(); + } } JERRY_UNREACHABLE(); @@ -264,30 +268,30 @@ ecma_op_to_number (ecma_value_t value) /**< ecma-value */ switch ((ecma_type_t)value.value_type) { case ECMA_TYPE_NUMBER: - { - return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, - ecma_copy_value (value, true), - ECMA_TARGET_ID_RESERVED); - } + { + return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, + ecma_copy_value (value, true), + ECMA_TARGET_ID_RESERVED); + } case ECMA_TYPE_SIMPLE: case ECMA_TYPE_STRING: - { - JERRY_UNIMPLEMENTED(); - } + { + JERRY_UNIMPLEMENTED(); + } case ECMA_TYPE_OBJECT: - { - ecma_completion_value_t completion_to_primitive = ecma_op_to_primitive (value, ECMA_PREFERRED_TYPE_NUMBER); - JERRY_ASSERT(ecma_is_completion_value_normal (completion_to_primitive)); + { + ecma_completion_value_t completion_to_primitive = ecma_op_to_primitive (value, ECMA_PREFERRED_TYPE_NUMBER); + JERRY_ASSERT(ecma_is_completion_value_normal (completion_to_primitive)); - ecma_completion_value_t completion_to_number = ecma_op_to_number (completion_to_primitive.value); - ecma_free_completion_value (completion_to_primitive); + ecma_completion_value_t completion_to_number = ecma_op_to_number (completion_to_primitive.value); + ecma_free_completion_value (completion_to_primitive); - return completion_to_number; - } + return completion_to_number; + } case ECMA_TYPE__COUNT: - { - JERRY_UNREACHABLE(); - } + { + JERRY_UNREACHABLE(); + } } JERRY_UNREACHABLE(); diff --git a/src/libecmaoperations/ecma-function-object.c b/src/libecmaoperations/ecma-function-object.c index 7491d3c85..4d30f34f1 100644 --- a/src/libecmaoperations/ecma-function-object.c +++ b/src/libecmaoperations/ecma-function-object.c @@ -45,9 +45,9 @@ ecma_pack_code_internal_property_value (bool is_strict, /**< is code strict? */ JERRY_ASSERT(((value) & (1u << is_strict_bit_offset)) == 0); if (is_strict) - { - value |= (1u << is_strict_bit_offset); - } + { + value |= (1u << is_strict_bit_offset); + } return value; } /* ecma_pack_code_internal_property_value */ @@ -86,9 +86,9 @@ bool ecma_op_is_callable (ecma_value_t value) /**< ecma-value */ { if (value.value_type != ECMA_TYPE_OBJECT) - { - return false; - } + { + return false; + } ecma_object_t *obj_p = ECMA_GET_POINTER(value.value); @@ -96,7 +96,7 @@ ecma_op_is_callable (ecma_value_t value) /**< ecma-value */ JERRY_ASSERT(!obj_p->is_lexical_environment); return (obj_p->u.object.type == ECMA_OBJECT_TYPE_FUNCTION - || obj_p->u.object.type == ECMA_OBJECT_TYPE_BOUND_FUNCTION); + || obj_p->u.object.type == ECMA_OBJECT_TYPE_BOUND_FUNCTION); } /* ecma_op_is_callable */ /** @@ -137,9 +137,9 @@ ecma_op_create_function_object (const ecma_char_t* formal_parameter_list_p[], /* // 10., 11., 14., 15. if (formal_parameters_number != 0) - { - JERRY_UNIMPLEMENTED_REF_UNUSED_VARS(formal_parameter_list_p); - } + { + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS(formal_parameter_list_p); + } // 12. ecma_property_t *code_prop_p = ecma_create_internal_property (f, ECMA_INTERNAL_PROPERTY_CODE); @@ -152,19 +152,19 @@ ecma_op_create_function_object (const ecma_char_t* formal_parameter_list_p[], /* // 17. ecma_property_descriptor_t prop_desc = ecma_make_empty_property_descriptor (); - { - prop_desc.is_value_defined = true; - prop_desc.value = ecma_make_object_value (f); + { + prop_desc.is_value_defined = true; + prop_desc.value = ecma_make_object_value (f); - prop_desc.is_writable_defined = true; - prop_desc.writable = ECMA_PROPERTY_WRITABLE; + prop_desc.is_writable_defined = true; + prop_desc.writable = ECMA_PROPERTY_WRITABLE; - prop_desc.is_enumerable_defined = true; - prop_desc.enumerable = ECMA_PROPERTY_NOT_ENUMERABLE; + prop_desc.is_enumerable_defined = true; + prop_desc.enumerable = ECMA_PROPERTY_NOT_ENUMERABLE; - prop_desc.is_configurable_defined = true; - prop_desc.configurable = ECMA_PROPERTY_CONFIGURABLE; - } + prop_desc.is_configurable_defined = true; + prop_desc.configurable = ECMA_PROPERTY_CONFIGURABLE; + } ecma_op_object_define_own_property (proto_p, ecma_get_magic_string (ECMA_MAGIC_STRING_CONSTRUCTOR), @@ -183,37 +183,37 @@ ecma_op_create_function_object (const ecma_char_t* formal_parameter_list_p[], /* // 19. if (is_strict) + { + ecma_object_t *thrower_p = ecma_op_get_throw_type_error (); + + prop_desc = ecma_make_empty_property_descriptor (); { - ecma_object_t *thrower_p = ecma_op_get_throw_type_error (); + prop_desc.is_enumerable_defined = true; + prop_desc.enumerable = ECMA_PROPERTY_NOT_ENUMERABLE; - prop_desc = ecma_make_empty_property_descriptor (); - { - prop_desc.is_enumerable_defined = true; - prop_desc.enumerable = ECMA_PROPERTY_NOT_ENUMERABLE; + prop_desc.is_configurable_defined = true; + prop_desc.configurable = ECMA_PROPERTY_NOT_CONFIGURABLE; - prop_desc.is_configurable_defined = true; - prop_desc.configurable = ECMA_PROPERTY_NOT_CONFIGURABLE; + prop_desc.is_get_defined = true; + prop_desc.get_p = thrower_p; - prop_desc.is_get_defined = true; - prop_desc.get_p = thrower_p; - - prop_desc.is_set_defined = true; - prop_desc.set_p = thrower_p; - } - - ecma_op_object_define_own_property (f, - ecma_get_magic_string (ECMA_MAGIC_STRING_CALLER), - prop_desc, - false); - - ecma_op_object_define_own_property (f, - ecma_get_magic_string (ECMA_MAGIC_STRING_ARGUMENTS), - prop_desc, - false); - - ecma_deref_object (thrower_p); + prop_desc.is_set_defined = true; + prop_desc.set_p = thrower_p; } + ecma_op_object_define_own_property (f, + ecma_get_magic_string (ECMA_MAGIC_STRING_CALLER), + prop_desc, + false); + + ecma_op_object_define_own_property (f, + ecma_get_magic_string (ECMA_MAGIC_STRING_ARGUMENTS), + prop_desc, + false); + + ecma_deref_object (thrower_p); + } + return f; } /* ecma_op_create_function_object */ @@ -236,81 +236,81 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */ JERRY_ASSERT(arguments_list_len == 0 || arguments_list_p != NULL); if (func_obj_p->u.object.type == ECMA_OBJECT_TYPE_FUNCTION) + { + ecma_completion_value_t ret_value; + + /* Entering Function Code (ECMA-262 v5, 10.4.3) */ + + ecma_property_t *scope_prop_p = ecma_get_internal_property (func_obj_p, ECMA_INTERNAL_PROPERTY_SCOPE); + ecma_property_t *code_prop_p = ecma_get_internal_property (func_obj_p, ECMA_INTERNAL_PROPERTY_CODE); + + ecma_object_t *scope_p = ECMA_GET_POINTER(scope_prop_p->u.internal_property.value); + uint32_t code_prop_value = code_prop_p->u.internal_property.value; + + bool is_strict; + // 8. + opcode_counter_t code_first_opcode_idx = ecma_unpack_code_internal_property_value (code_prop_value, &is_strict); + + ecma_value_t this_binding; + // 1. + if (is_strict) { - ecma_completion_value_t ret_value; - - /* Entering Function Code (ECMA-262 v5, 10.4.3) */ - - ecma_property_t *scope_prop_p = ecma_get_internal_property (func_obj_p, ECMA_INTERNAL_PROPERTY_SCOPE); - ecma_property_t *code_prop_p = ecma_get_internal_property (func_obj_p, ECMA_INTERNAL_PROPERTY_CODE); - - ecma_object_t *scope_p = ECMA_GET_POINTER(scope_prop_p->u.internal_property.value); - uint32_t code_prop_value = code_prop_p->u.internal_property.value; - - bool is_strict; - // 8. - opcode_counter_t code_first_opcode_idx = ecma_unpack_code_internal_property_value (code_prop_value, &is_strict); - - ecma_value_t this_binding; - // 1. - if (is_strict) - { - this_binding = ecma_copy_value (this_arg_value, true); - } - else if (ecma_is_value_undefined (this_arg_value) - || ecma_is_value_null (this_arg_value)) - { - // 2. - FIXME(Assign Global object when it will be implemented); - - this_binding = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED); - } - else - { - // 3., 4. - ecma_completion_value_t completion = ecma_op_to_object (this_arg_value); - JERRY_ASSERT(ecma_is_completion_value_normal (completion)); - - this_binding = completion.value; - } - - // 5. - ecma_object_t *local_env_p = ecma_create_decl_lex_env (scope_p); - - // 9. - /* Declaration binding instantiation (ECMA-262 v5, 10.5), block 4 */ - TODO(Perform declaration binding instantion when [[FormalParameters]] list will be supported); - if (arguments_list_len != 0) - { - JERRY_UNIMPLEMENTED_REF_UNUSED_VARS(arguments_list_p); - } - - ecma_completion_value_t completion = run_int_from_pos (code_first_opcode_idx, - this_binding, - local_env_p, - is_strict); - if (ecma_is_completion_value_normal (completion)) - { - JERRY_ASSERT(ecma_is_empty_completion_value (completion)); - - ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED); - } - else - { - ret_value = completion; - } - - ecma_deref_object (local_env_p); - ecma_free_value (this_binding, true); - - return ret_value; + this_binding = ecma_copy_value (this_arg_value, true); } + else if (ecma_is_value_undefined (this_arg_value) + || ecma_is_value_null (this_arg_value)) + { + // 2. + FIXME(Assign Global object when it will be implemented); + + this_binding = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED); + } + else + { + // 3., 4. + ecma_completion_value_t completion = ecma_op_to_object (this_arg_value); + JERRY_ASSERT(ecma_is_completion_value_normal (completion)); + + this_binding = completion.value; + } + + // 5. + ecma_object_t *local_env_p = ecma_create_decl_lex_env (scope_p); + + // 9. + /* Declaration binding instantiation (ECMA-262 v5, 10.5), block 4 */ + TODO(Perform declaration binding instantion when [[FormalParameters]] list will be supported); + if (arguments_list_len != 0) + { + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS(arguments_list_p); + } + + ecma_completion_value_t completion = run_int_from_pos (code_first_opcode_idx, + this_binding, + local_env_p, + is_strict); + if (ecma_is_completion_value_normal (completion)) + { + JERRY_ASSERT(ecma_is_empty_completion_value (completion)); + + ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED); + } + else + { + ret_value = completion; + } + + ecma_deref_object (local_env_p); + ecma_free_value (this_binding, true); + + return ret_value; + } else - { - JERRY_ASSERT(func_obj_p->u.object.type == ECMA_OBJECT_TYPE_BOUND_FUNCTION); + { + JERRY_ASSERT(func_obj_p->u.object.type == ECMA_OBJECT_TYPE_BOUND_FUNCTION); - JERRY_UNIMPLEMENTED(); - } + JERRY_UNIMPLEMENTED(); + } } /* ecma_op_function_call */ /** diff --git a/src/libecmaoperations/ecma-get-put-value.c b/src/libecmaoperations/ecma-get-put-value.c index deae12a04..e45dd573d 100644 --- a/src/libecmaoperations/ecma-get-put-value.c +++ b/src/libecmaoperations/ecma-get-put-value.c @@ -46,10 +46,10 @@ ecma_op_get_value (ecma_reference_t ref) /**< ECMA-reference */ const ecma_value_t base = ref.base; const bool is_unresolvable_reference = ecma_is_value_undefined (base); const bool has_primitive_base = (ecma_is_value_boolean (base) - || base.value_type == ECMA_TYPE_NUMBER - || base.value_type == ECMA_TYPE_STRING); + || base.value_type == ECMA_TYPE_NUMBER + || base.value_type == ECMA_TYPE_STRING); const bool has_object_base = (base.value_type == ECMA_TYPE_OBJECT - && !((ecma_object_t*)ECMA_GET_POINTER(base.value))->is_lexical_environment); + && !((ecma_object_t*)ECMA_GET_POINTER(base.value))->is_lexical_environment); const bool is_property_reference = has_primitive_base || has_object_base; // GetValue_3 @@ -72,31 +72,31 @@ ecma_op_get_value (ecma_reference_t ref) /**< ECMA-reference */ } else { // GetValue_4.b case 2 /* - ecma_object_t *obj_p = ecma_ToObject (base); - JERRY_ASSERT(obj_p != NULL && !obj_p->is_lexical_environment); - ecma_property_t *property = obj_p->[[GetProperty]](ref.referenced_name_p); - if (property->Type == ECMA_PROPERTY_NAMEDDATA) - { - return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, - ecma_copy_value (property->u.named_data_property.value), - ECMA_TARGET_ID_RESERVED); - } else - { - JERRY_ASSERT(property->Type == ECMA_PROPERTY_NAMEDACCESSOR); - - ecma_object_t *getter = ECMA_GET_POINTER(property->u.named_accessor_property.get_p); - - if (getter == NULL) - { + ecma_object_t *obj_p = ecma_ToObject (base); + JERRY_ASSERT(obj_p != NULL && !obj_p->is_lexical_environment); + ecma_property_t *property = obj_p->[[GetProperty]](ref.referenced_name_p); + if (property->Type == ECMA_PROPERTY_NAMEDDATA) + { return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, - ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED), - ECMA_TARGET_ID_RESERVED); - } else - { + ecma_copy_value (property->u.named_data_property.value), + ECMA_TARGET_ID_RESERVED); + } else + { + JERRY_ASSERT(property->Type == ECMA_PROPERTY_NAMEDACCESSOR); + + ecma_object_t *getter = ECMA_GET_POINTER(property->u.named_accessor_property.get_p); + + if (getter == NULL) + { + return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, + ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED), + ECMA_TARGET_ID_RESERVED); + } else + { return [[Call]](getter, base as this); - } - } - */ + } + } + */ JERRY_UNIMPLEMENTED(); } } else @@ -120,15 +120,15 @@ ecma_op_get_value (ecma_reference_t ref) /**< ECMA-reference */ */ ecma_completion_value_t ecma_op_put_value (ecma_reference_t ref, /**< ECMA-reference */ - ecma_value_t value) /**< ECMA-value */ + ecma_value_t value) /**< ECMA-value */ { const ecma_value_t base = ref.base; const bool is_unresolvable_reference = ecma_is_value_undefined (base); const bool has_primitive_base = (ecma_is_value_boolean (base) - || base.value_type == ECMA_TYPE_NUMBER - || base.value_type == ECMA_TYPE_STRING); + || base.value_type == ECMA_TYPE_NUMBER + || base.value_type == ECMA_TYPE_STRING); const bool has_object_base = (base.value_type == ECMA_TYPE_OBJECT - && !((ecma_object_t*)ECMA_GET_POINTER(base.value))->is_lexical_environment); + && !((ecma_object_t*)ECMA_GET_POINTER(base.value))->is_lexical_environment); const bool is_property_reference = has_primitive_base || has_object_base; if (is_unresolvable_reference) // PutValue_3 @@ -138,19 +138,19 @@ ecma_op_put_value (ecma_reference_t ref, /**< ECMA-reference */ return ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_REFERENCE)); } else // PutValue_3.b { - ecma_object_t *global_object_p = ecma_get_global_object (); + ecma_object_t *global_object_p = ecma_get_global_object (); - ecma_completion_value_t completion = ecma_op_object_put (global_object_p, - ref.referenced_name_p, - value, - false); + ecma_completion_value_t completion = ecma_op_object_put (global_object_p, + ref.referenced_name_p, + value, + false); - ecma_deref_object (global_object_p); + ecma_deref_object (global_object_p); - JERRY_ASSERT(ecma_is_completion_value_normal_true (completion) - || ecma_is_completion_value_normal_false (completion)); + JERRY_ASSERT(ecma_is_completion_value_normal_true (completion) + || ecma_is_completion_value_normal_false (completion)); - return ecma_make_empty_completion_value (); + return ecma_make_empty_completion_value (); } } else if (is_property_reference) // PutValue_4 { @@ -165,68 +165,68 @@ ecma_op_put_value (ecma_reference_t ref, /**< ECMA-reference */ // PutValue_4.b case 2 /* - // PutValue_sub_1 - ecma_object_t *obj_p = ecma_ToObject (base); - JERRY_ASSERT(obj_p != NULL && !obj_p->is_lexical_environment); + // PutValue_sub_1 + ecma_object_t *obj_p = ecma_ToObject (base); + JERRY_ASSERT(obj_p != NULL && !obj_p->is_lexical_environment); - // PutValue_sub_2 - if (!obj_p->[[CanPut]](ref.referenced_name_p)) - { - // PutValue_sub_2.a - if (ref.is_strict) - { - return ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); - } else - { // PutValue_sub_2.b - return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, - ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY), - ECMA_TARGET_ID_RESERVED); - } - } + // PutValue_sub_2 + if (!obj_p->[[CanPut]](ref.referenced_name_p)) + { + // PutValue_sub_2.a + if (ref.is_strict) + { + return ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); + } else + { // PutValue_sub_2.b + return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, + ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY), + ECMA_TARGET_ID_RESERVED); + } + } - // PutValue_sub_3 - ecma_property_t *own_prop = obj_p->[[GetOwnProperty]](ref.referenced_name_p); + // PutValue_sub_3 + ecma_property_t *own_prop = obj_p->[[GetOwnProperty]](ref.referenced_name_p); - // PutValue_sub_4 - if (ecma_OpIsDataDescriptor (own_prop)) - { - // PutValue_sub_4.a - if (ref.is_strict) - { - return ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); - } else - { // PutValue_sub_4.b - return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, - ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY), - ECMA_TARGET_ID_RESERVED); - } - } + // PutValue_sub_4 + if (ecma_OpIsDataDescriptor (own_prop)) + { + // PutValue_sub_4.a + if (ref.is_strict) + { + return ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); + } else + { // PutValue_sub_4.b + return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, + ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY), + ECMA_TARGET_ID_RESERVED); + } + } - // PutValue_sub_5 - ecma_property_t *prop = obj_p->[[GetProperty]](ref.referenced_name_p); + // PutValue_sub_5 + ecma_property_t *prop = obj_p->[[GetProperty]](ref.referenced_name_p); - // PutValue_sub_6 - if (ecma_OpIsAccessorDescriptor (prop)) - { - // PutValue_sub_6.a - ecma_object_t *setter = ECMA_GET_POINTER(property->u.named_accessor_property.set_p); - JERRY_ASSERT(setter != NULL); + // PutValue_sub_6 + if (ecma_OpIsAccessorDescriptor (prop)) + { + // PutValue_sub_6.a + ecma_object_t *setter = ECMA_GET_POINTER(property->u.named_accessor_property.set_p); + JERRY_ASSERT(setter != NULL); - // PutValue_sub_6.b - return [[Call]](setter, base as this, value); - } else // PutValue_sub_7 - { - // PutValue_sub_7.a - if (ref.is_strict) - { - return ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); - } - } + // PutValue_sub_6.b + return [[Call]](setter, base as this, value); + } else // PutValue_sub_7 + { + // PutValue_sub_7.a + if (ref.is_strict) + { + return ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); + } + } - // PutValue_sub_8 - return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, - ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY), - ECMA_TARGET_ID_RESERVED); + // PutValue_sub_8 + return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, + ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY), + ECMA_TARGET_ID_RESERVED); */ JERRY_UNIMPLEMENTED(); diff --git a/src/libecmaoperations/ecma-lex-env.c b/src/libecmaoperations/ecma-lex-env.c index d32ade03f..6e2ca64d1 100644 --- a/src/libecmaoperations/ecma-lex-env.c +++ b/src/libecmaoperations/ecma-lex-env.c @@ -40,12 +40,12 @@ static ecma_object_t* ecma_get_lex_env_binding_object (ecma_object_t* obj_lex_env_p) /**< object lexical environment */ { JERRY_ASSERT(obj_lex_env_p != NULL - && obj_lex_env_p->is_lexical_environment - && obj_lex_env_p->u.lexical_environment.type == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND); + && obj_lex_env_p->is_lexical_environment + && obj_lex_env_p->u.lexical_environment.type == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND); ecma_property_t *binding_obj_prop_p = ECMA_GET_POINTER(obj_lex_env_p->properties_p); JERRY_ASSERT(binding_obj_prop_p != NULL - && binding_obj_prop_p->u.internal_property.type == ECMA_INTERNAL_PROPERTY_BINDING_OBJECT); + && binding_obj_prop_p->u.internal_property.type == ECMA_INTERNAL_PROPERTY_BINDING_OBJECT); return ECMA_GET_POINTER(binding_obj_prop_p->u.internal_property.value); } /* ecma_get_lex_env_binding_object */ @@ -61,7 +61,7 @@ ecma_get_lex_env_binding_object (ecma_object_t* obj_lex_env_p) /**< object lexic */ ecma_completion_value_t ecma_op_has_binding (ecma_object_t *lex_env_p, /**< lexical environment */ - const ecma_char_t *name_p) /**< argument N */ + const ecma_char_t *name_p) /**< argument N */ { JERRY_ASSERT(lex_env_p != NULL && lex_env_p->is_lexical_environment); @@ -73,8 +73,7 @@ ecma_op_has_binding (ecma_object_t *lex_env_p, /**< lexical environment */ { ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p); - has_binding = (property_p != NULL) ? ECMA_SIMPLE_VALUE_TRUE - : ECMA_SIMPLE_VALUE_FALSE; + has_binding = (property_p != NULL) ? ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE; break; } @@ -82,16 +81,22 @@ ecma_op_has_binding (ecma_object_t *lex_env_p, /**< lexical environment */ { ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p); - has_binding = ecma_op_object_has_property (binding_obj_p, name_p) ? ECMA_SIMPLE_VALUE_TRUE - : ECMA_SIMPLE_VALUE_FALSE; + if (ecma_op_object_has_property (binding_obj_p, name_p)) + { + has_binding = ECMA_SIMPLE_VALUE_TRUE; + } + else + { + has_binding = ECMA_SIMPLE_VALUE_FALSE; + } break; } } return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, - ecma_make_simple_value (has_binding), - ECMA_TARGET_ID_RESERVED); + ecma_make_simple_value (has_binding), + ECMA_TARGET_ID_RESERVED); } /* ecma_op_has_binding */ /** @@ -104,8 +109,8 @@ ecma_op_has_binding (ecma_object_t *lex_env_p, /**< lexical environment */ */ ecma_completion_value_t ecma_op_create_mutable_binding (ecma_object_t *lex_env_p, /**< lexical environment */ - const ecma_char_t *name_p, /**< argument N */ - bool is_deletable) /**< argument D */ + const ecma_char_t *name_p, /**< argument N */ + bool is_deletable) /**< argument D */ { JERRY_ASSERT(lex_env_p != NULL && lex_env_p->is_lexical_environment); JERRY_ASSERT(name_p != NULL); @@ -121,7 +126,7 @@ ecma_op_create_mutable_binding (ecma_object_t *lex_env_p, /**< lexical environme ECMA_PROPERTY_WRITABLE, ECMA_PROPERTY_NOT_ENUMERABLE, is_deletable ? ECMA_PROPERTY_CONFIGURABLE - : ECMA_PROPERTY_NOT_CONFIGURABLE); + : ECMA_PROPERTY_NOT_CONFIGURABLE); break; @@ -133,20 +138,19 @@ ecma_op_create_mutable_binding (ecma_object_t *lex_env_p, /**< lexical environme JERRY_ASSERT(!ecma_op_object_has_property (binding_obj_p, name_p)); ecma_property_descriptor_t prop_desc = ecma_make_empty_property_descriptor (); - { - prop_desc.is_value_defined = true; - prop_desc.value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED); + { + prop_desc.is_value_defined = true; + prop_desc.value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED); - prop_desc.is_writable_defined = true; - prop_desc.writable = ECMA_PROPERTY_WRITABLE; + prop_desc.is_writable_defined = true; + prop_desc.writable = ECMA_PROPERTY_WRITABLE; - prop_desc.is_enumerable_defined = true; - prop_desc.enumerable = ECMA_PROPERTY_ENUMERABLE; + prop_desc.is_enumerable_defined = true; + prop_desc.enumerable = ECMA_PROPERTY_ENUMERABLE; - prop_desc.is_configurable_defined = true; - prop_desc.configurable = is_deletable ? ECMA_PROPERTY_CONFIGURABLE - : ECMA_PROPERTY_NOT_CONFIGURABLE; - } + prop_desc.is_configurable_defined = true; + prop_desc.configurable = is_deletable ? ECMA_PROPERTY_CONFIGURABLE : ECMA_PROPERTY_NOT_CONFIGURABLE; + } ecma_completion_value_t completion = ecma_op_object_define_own_property (binding_obj_p, name_p, @@ -154,12 +158,12 @@ ecma_op_create_mutable_binding (ecma_object_t *lex_env_p, /**< lexical environme true); if (!(ecma_is_completion_value_normal_true (completion) - || ecma_is_completion_value_normal_false (completion))) - { - JERRY_ASSERT(ecma_is_completion_value_throw (completion)); + || ecma_is_completion_value_normal_false (completion))) + { + JERRY_ASSERT(ecma_is_completion_value_throw (completion)); - return completion; - } + return completion; + } } } @@ -176,9 +180,9 @@ ecma_op_create_mutable_binding (ecma_object_t *lex_env_p, /**< lexical environme */ ecma_completion_value_t ecma_op_set_mutable_binding (ecma_object_t *lex_env_p, /**< lexical environment */ - const ecma_char_t *name_p, /**< argument N */ - ecma_value_t value, /**< argument V */ - bool is_strict) /**< argument S */ + const ecma_char_t *name_p, /**< argument N */ + ecma_value_t value, /**< argument V */ + bool is_strict) /**< argument S */ { JERRY_ASSERT(lex_env_p != NULL && lex_env_p->is_lexical_environment); JERRY_ASSERT(name_p != NULL); @@ -192,16 +196,16 @@ ecma_op_set_mutable_binding (ecma_object_t *lex_env_p, /**< lexical environment ecma_property_t *property_p = ecma_get_named_data_property (lex_env_p, name_p); if (property_p->u.named_data_property.writable == ECMA_PROPERTY_WRITABLE) - { - ecma_free_value (property_p->u.named_data_property.value, false); - property_p->u.named_data_property.value = ecma_copy_value (value, false); + { + ecma_free_value (property_p->u.named_data_property.value, false); + property_p->u.named_data_property.value = ecma_copy_value (value, false); - ecma_gc_update_may_ref_younger_object_flag_by_value (lex_env_p, value); - } + ecma_gc_update_may_ref_younger_object_flag_by_value (lex_env_p, value); + } else if (is_strict) - { - return ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); - } + { + return ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); + } break; } @@ -214,12 +218,12 @@ ecma_op_set_mutable_binding (ecma_object_t *lex_env_p, /**< lexical environment value, is_strict); if (!(ecma_is_completion_value_normal_true (completion) - || ecma_is_completion_value_normal_false (completion))) - { - JERRY_ASSERT(ecma_is_completion_value_throw (completion)); + || ecma_is_completion_value_normal_false (completion))) + { + JERRY_ASSERT(ecma_is_completion_value_throw (completion)); - return completion; - } + return completion; + } break; } @@ -238,8 +242,8 @@ ecma_op_set_mutable_binding (ecma_object_t *lex_env_p, /**< lexical environment */ ecma_completion_value_t ecma_op_get_binding_value (ecma_object_t *lex_env_p, /**< lexical environment */ - const ecma_char_t *name_p, /**< argument N */ - bool is_strict) /**< argument S */ + const ecma_char_t *name_p, /**< argument N */ + bool is_strict) /**< argument S */ { JERRY_ASSERT(lex_env_p != NULL && lex_env_p->is_lexical_environment); JERRY_ASSERT(name_p != NULL); @@ -281,16 +285,16 @@ ecma_op_get_binding_value (ecma_object_t *lex_env_p, /**< lexical environment */ bool has_prop = ecma_op_object_has_property (binding_obj_p, name_p); if (!has_prop) + { + if (is_strict) { - if (is_strict) - { - return ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_REFERENCE)); - } - else - { - return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED); - } + return ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_REFERENCE)); } + else + { + return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED); + } + } return ecma_op_object_get (binding_obj_p, name_p); } @@ -310,7 +314,7 @@ ecma_op_get_binding_value (ecma_object_t *lex_env_p, /**< lexical environment */ */ ecma_completion_value_t ecma_op_delete_binding (ecma_object_t *lex_env_p, /**< lexical environment */ - const ecma_char_t *name_p) /**< argument N */ + const ecma_char_t *name_p) /**< argument N */ { JERRY_ASSERT(lex_env_p != NULL && lex_env_p->is_lexical_environment); JERRY_ASSERT(name_p != NULL); @@ -318,32 +322,32 @@ ecma_op_delete_binding (ecma_object_t *lex_env_p, /**< lexical environment */ switch ((ecma_lexical_environment_type_t) lex_env_p->u.lexical_environment.type) { case ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE: - { - ecma_property_t *prop_p = ecma_find_named_property (lex_env_p, name_p); - ecma_simple_value_t ret_val; + { + ecma_property_t *prop_p = ecma_find_named_property (lex_env_p, name_p); + ecma_simple_value_t ret_val; - if (prop_p == NULL) + if (prop_p == NULL) + { + ret_val = ECMA_SIMPLE_VALUE_TRUE; + } else + { + JERRY_ASSERT(prop_p->type == ECMA_PROPERTY_NAMEDDATA); + + if (prop_p->u.named_data_property.configurable == ECMA_PROPERTY_NOT_CONFIGURABLE) { - ret_val = ECMA_SIMPLE_VALUE_TRUE; + ret_val = ECMA_SIMPLE_VALUE_FALSE; } else { - JERRY_ASSERT(prop_p->type == ECMA_PROPERTY_NAMEDDATA); + ecma_delete_property (lex_env_p, prop_p); - if (prop_p->u.named_data_property.configurable == ECMA_PROPERTY_NOT_CONFIGURABLE) - { - ret_val = ECMA_SIMPLE_VALUE_FALSE; - } else - { - ecma_delete_property (lex_env_p, prop_p); - - ret_val = ECMA_SIMPLE_VALUE_TRUE; - } + ret_val = ECMA_SIMPLE_VALUE_TRUE; } - - return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, - ecma_make_simple_value (ret_val), - ECMA_TARGET_ID_RESERVED); } + + return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, + ecma_make_simple_value (ret_val), + ECMA_TARGET_ID_RESERVED); + } case ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND: { ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p); @@ -371,9 +375,9 @@ ecma_op_implicit_this_value (ecma_object_t *lex_env_p) /**< lexical environment switch ((ecma_lexical_environment_type_t) lex_env_p->u.lexical_environment.type) { case ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE: - { - return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED); - } + { + return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED); + } case ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND: { ecma_property_t *provide_this_prop_p = ecma_get_internal_property (lex_env_p, @@ -382,18 +386,18 @@ ecma_op_implicit_this_value (ecma_object_t *lex_env_p) /**< lexical environment bool provide_this = provide_this_prop_p->u.internal_property.value; if (provide_this) - { - ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p); - ecma_ref_object (binding_obj_p); + { + ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p); + ecma_ref_object (binding_obj_p); - return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, - ecma_make_object_value (binding_obj_p), - ECMA_TARGET_ID_RESERVED); - } + return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, + ecma_make_object_value (binding_obj_p), + ECMA_TARGET_ID_RESERVED); + } else - { - return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED); - } + { + return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED); + } } } @@ -407,31 +411,31 @@ ecma_op_implicit_this_value (ecma_object_t *lex_env_p) /**< lexical environment */ void ecma_op_create_immutable_binding (ecma_object_t *lex_env_p, /**< lexical environment */ - const ecma_char_t *name_p) /**< argument N */ + const ecma_char_t *name_p) /**< argument N */ { JERRY_ASSERT(lex_env_p != NULL && lex_env_p->is_lexical_environment); switch ((ecma_lexical_environment_type_t) lex_env_p->u.lexical_environment.type) { case ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE: - { - JERRY_ASSERT(ecma_is_completion_value_normal_false (ecma_op_has_binding (lex_env_p, name_p))); + { + JERRY_ASSERT(ecma_is_completion_value_normal_false (ecma_op_has_binding (lex_env_p, name_p))); - /* - * Warning: - * Whether immutable bindings are deletable seems not to be defined by ECMA v5. - */ - ecma_property_t *prop_p = ecma_create_named_data_property (lex_env_p, - name_p, - ECMA_PROPERTY_NOT_WRITABLE, - ECMA_PROPERTY_NOT_ENUMERABLE, - ECMA_PROPERTY_NOT_CONFIGURABLE); + /* + * Warning: + * Whether immutable bindings are deletable seems not to be defined by ECMA v5. + */ + ecma_property_t *prop_p = ecma_create_named_data_property (lex_env_p, + name_p, + ECMA_PROPERTY_NOT_WRITABLE, + ECMA_PROPERTY_NOT_ENUMERABLE, + ECMA_PROPERTY_NOT_CONFIGURABLE); - JERRY_ASSERT(ecma_is_value_undefined (prop_p->u.named_data_property.value)); + JERRY_ASSERT(ecma_is_value_undefined (prop_p->u.named_data_property.value)); - prop_p->u.named_data_property.value.value_type = ECMA_TYPE_SIMPLE; - prop_p->u.named_data_property.value.value = ECMA_SIMPLE_VALUE_EMPTY; - } + prop_p->u.named_data_property.value.value_type = ECMA_TYPE_SIMPLE; + prop_p->u.named_data_property.value.value = ECMA_SIMPLE_VALUE_EMPTY; + } case ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND: { JERRY_UNREACHABLE(); @@ -448,27 +452,27 @@ ecma_op_create_immutable_binding (ecma_object_t *lex_env_p, /**< lexical environ */ void ecma_op_initialize_immutable_binding (ecma_object_t *lex_env_p, /**< lexical environment */ - const ecma_char_t *name_p, /**< argument N */ - ecma_value_t value) /**< argument V */ + const ecma_char_t *name_p, /**< argument N */ + ecma_value_t value) /**< argument V */ { JERRY_ASSERT(lex_env_p != NULL && lex_env_p->is_lexical_environment); switch ((ecma_lexical_environment_type_t) lex_env_p->u.lexical_environment.type) { case ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE: - { - JERRY_ASSERT(ecma_is_completion_value_normal_true (ecma_op_has_binding (lex_env_p, name_p))); + { + JERRY_ASSERT(ecma_is_completion_value_normal_true (ecma_op_has_binding (lex_env_p, name_p))); - ecma_property_t *prop_p = ecma_get_named_data_property (lex_env_p, name_p); + ecma_property_t *prop_p = ecma_get_named_data_property (lex_env_p, name_p); - /* The binding must be unitialized immutable binding */ - JERRY_ASSERT(prop_p->u.named_data_property.writable == ECMA_PROPERTY_NOT_WRITABLE - && ecma_is_value_empty (prop_p->u.named_data_property.value)); + /* The binding must be unitialized immutable binding */ + JERRY_ASSERT(prop_p->u.named_data_property.writable == ECMA_PROPERTY_NOT_WRITABLE + && ecma_is_value_empty (prop_p->u.named_data_property.value)); - prop_p->u.named_data_property.value = ecma_copy_value (value, false); + prop_p->u.named_data_property.value = ecma_copy_value (value, false); - ecma_gc_update_may_ref_younger_object_flag_by_value (lex_env_p, value); - } + ecma_gc_update_may_ref_younger_object_flag_by_value (lex_env_p, value); + } case ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND: { JERRY_UNREACHABLE(); diff --git a/src/libecmaoperations/ecma-magic-strings.c b/src/libecmaoperations/ecma-magic-strings.c index 229eb0092..1164830c6 100644 --- a/src/libecmaoperations/ecma-magic-strings.c +++ b/src/libecmaoperations/ecma-magic-strings.c @@ -33,20 +33,14 @@ ecma_get_magic_string (ecma_magic_string_id_t id) /**< magic string id */ TODO(Support UTF-16); switch (id) - { - case ECMA_MAGIC_STRING_ARGUMENTS: - return (ecma_char_t*) "arguments"; - case ECMA_MAGIC_STRING_EVAL: - return (ecma_char_t*) "eval"; - case ECMA_MAGIC_STRING_PROTOTYPE: - return (ecma_char_t*) "prototype"; - case ECMA_MAGIC_STRING_CONSTRUCTOR: - return (ecma_char_t*) "constructor"; - case ECMA_MAGIC_STRING_CALLER: - return (ecma_char_t*) "caller"; - case ECMA_MAGIC_STRING_UNDEFINED: - return (ecma_char_t*) "undefined"; - } + { + case ECMA_MAGIC_STRING_ARGUMENTS: return (ecma_char_t*) "arguments"; + case ECMA_MAGIC_STRING_EVAL: return (ecma_char_t*) "eval"; + case ECMA_MAGIC_STRING_PROTOTYPE: return (ecma_char_t*) "prototype"; + case ECMA_MAGIC_STRING_CONSTRUCTOR: return (ecma_char_t*) "constructor"; + case ECMA_MAGIC_STRING_CALLER: return (ecma_char_t*) "caller"; + case ECMA_MAGIC_STRING_UNDEFINED: return (ecma_char_t*) "undefined"; + } JERRY_UNREACHABLE(); } /* ecma_get_magic_string */ diff --git a/src/libecmaoperations/ecma-number-arithmetic.c b/src/libecmaoperations/ecma-number-arithmetic.c index c7ed1557a..0f9f5b8c1 100644 --- a/src/libecmaoperations/ecma-number-arithmetic.c +++ b/src/libecmaoperations/ecma-number-arithmetic.c @@ -35,7 +35,7 @@ */ ecma_number_t ecma_op_number_add (ecma_number_t left_num, /**< left operand */ - ecma_number_t right_num) /**< right operand */ + ecma_number_t right_num) /**< right operand */ { TODO(Implement according to ECMA); @@ -52,7 +52,7 @@ ecma_op_number_add (ecma_number_t left_num, /**< left operand */ */ ecma_number_t ecma_op_number_substract (ecma_number_t left_num, /**< left operand */ - ecma_number_t right_num) /**< right operand */ + ecma_number_t right_num) /**< right operand */ { return ecma_op_number_add (left_num, ecma_op_number_negate (right_num)); } /* ecma_op_number_substract */ @@ -67,7 +67,7 @@ ecma_op_number_substract (ecma_number_t left_num, /**< left operand */ */ ecma_number_t ecma_op_number_multiply (ecma_number_t left_num, /**< left operand */ - ecma_number_t right_num) /**< right operand */ + ecma_number_t right_num) /**< right operand */ { TODO(Implement according to ECMA); @@ -84,7 +84,7 @@ ecma_op_number_multiply (ecma_number_t left_num, /**< left operand */ */ ecma_number_t ecma_op_number_divide (ecma_number_t left_num, /**< left operand */ - ecma_number_t right_num) /**< right operand */ + ecma_number_t right_num) /**< right operand */ { TODO(Implement according to ECMA); @@ -101,13 +101,13 @@ ecma_op_number_divide (ecma_number_t left_num, /**< left operand */ */ ecma_number_t ecma_op_number_remainder (ecma_number_t left_num, /**< left operand */ - ecma_number_t right_num) /**< right operand */ + ecma_number_t right_num) /**< right operand */ { TODO(Implement according to ECMA); ecma_number_t n = left_num, d = right_num; - return (n - d * (ecma_number_t)((int32_t)(n / d))); + return (n - d * (ecma_number_t) ((int32_t) (n / d))); } /* ecma_op_number_remainder */ /** diff --git a/src/libecmaoperations/ecma-objects-properties.c b/src/libecmaoperations/ecma-objects-properties.c index 702477604..79d55a537 100644 --- a/src/libecmaoperations/ecma-objects-properties.c +++ b/src/libecmaoperations/ecma-objects-properties.c @@ -36,13 +36,13 @@ static ecma_completion_value_t ecma_reject (bool is_throw) /**< Throw flag */ { if (is_throw) - { - return ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); - } + { + return ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); + } else - { - return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); - } + { + return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); + } } /* ecma_reject */ /** @@ -72,35 +72,35 @@ ecma_op_object_get (ecma_object_t *obj_p, /**< the object */ // 2. if (prop_p == NULL) - { - return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED); - } + { + return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED); + } // 3. if (prop_p->type == ECMA_PROPERTY_NAMEDDATA) - { - return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, - ecma_copy_value (prop_p->u.named_data_property.value, true), - ECMA_TARGET_ID_RESERVED); - } + { + return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, + ecma_copy_value (prop_p->u.named_data_property.value, true), + ECMA_TARGET_ID_RESERVED); + } else - { - // 4. - ecma_object_t *getter = ECMA_GET_POINTER(prop_p->u.named_accessor_property.get_p); + { + // 4. + ecma_object_t *getter = ECMA_GET_POINTER(prop_p->u.named_accessor_property.get_p); - // 5. - if (getter == NULL) - { - return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED); - } - else - { - /* - * Return result of O.[[Call]]; - */ - JERRY_UNIMPLEMENTED(); - } + // 5. + if (getter == NULL) + { + return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED); } + else + { + /* + * Return result of O.[[Call]]; + */ + JERRY_UNIMPLEMENTED(); + } + } JERRY_UNREACHABLE(); } /* ecma_op_object_get */ @@ -157,22 +157,22 @@ ecma_op_object_get_property (ecma_object_t *obj_p, /**< the object */ // 2. if (prop_p != NULL) - { - return prop_p; - } + { + return prop_p; + } // 3. ecma_object_t *prototype_p = ECMA_GET_POINTER(obj_p->u.object.prototype_object_p); // 4., 5. if (prototype_p != NULL) - { - return ecma_op_object_get_property (prototype_p, property_name_p); - } + { + return ecma_op_object_get_property (prototype_p, property_name_p); + } else - { - return NULL; - } + { + return NULL; + } } /* ecma_op_object_get_property */ /** @@ -195,85 +195,85 @@ ecma_op_object_put (ecma_object_t *obj_p, /**< the object */ // 1. if (!ecma_op_object_can_put (obj_p, property_name_p)) + { + if (is_throw) { - if (is_throw) - { - // a. - return ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); - } - else - { - // b. - return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); - } + // a. + return ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } + else + { + // b. + return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); + } + } // 2. ecma_property_t *own_desc_p = ecma_op_object_get_own_property (obj_p, property_name_p); // 3. if (own_desc_p != NULL - && own_desc_p->type == ECMA_PROPERTY_NAMEDDATA) + && own_desc_p->type == ECMA_PROPERTY_NAMEDDATA) + { + // a. + ecma_property_descriptor_t value_desc = ecma_make_empty_property_descriptor (); { - // a. - ecma_property_descriptor_t value_desc = ecma_make_empty_property_descriptor (); - { - value_desc.is_value_defined = true; - value_desc.value = value; - } - - // b., c. - return ecma_op_object_define_own_property (obj_p, - property_name_p, - value_desc, - is_throw); + value_desc.is_value_defined = true; + value_desc.value = value; } + // b., c. + return ecma_op_object_define_own_property (obj_p, + property_name_p, + value_desc, + is_throw); + } + // 4. ecma_property_t *desc_p = ecma_op_object_get_property (obj_p, property_name_p); // 5. if (desc_p != NULL - && desc_p->type == ECMA_PROPERTY_NAMEDACCESSOR) - { - // a. - ecma_object_t *setter_p = ECMA_GET_POINTER(desc_p->u.named_accessor_property.set_p); + && desc_p->type == ECMA_PROPERTY_NAMEDACCESSOR) + { + // a. + ecma_object_t *setter_p = ECMA_GET_POINTER(desc_p->u.named_accessor_property.set_p); - JERRY_ASSERT(setter_p != NULL); + JERRY_ASSERT(setter_p != NULL); - // b. - /* - * setter_p->[[Call]](obj_p, value); - */ - JERRY_UNIMPLEMENTED(); - } + // b. + /* + * setter_p->[[Call]](obj_p, value); + */ + JERRY_UNIMPLEMENTED(); + } else + { + // 6. + + // a. + ecma_property_descriptor_t new_desc = ecma_make_empty_property_descriptor (); { - // 6. + new_desc.is_value_defined = true; + new_desc.value = value; - // a. - ecma_property_descriptor_t new_desc = ecma_make_empty_property_descriptor (); - { - new_desc.is_value_defined = true; - new_desc.value = value; + new_desc.is_writable_defined = true; + new_desc.writable = ECMA_PROPERTY_WRITABLE; - new_desc.is_writable_defined = true; - new_desc.writable = ECMA_PROPERTY_WRITABLE; + new_desc.is_enumerable_defined = true; + new_desc.enumerable = ECMA_PROPERTY_ENUMERABLE; - new_desc.is_enumerable_defined = true; - new_desc.enumerable = ECMA_PROPERTY_ENUMERABLE; - - new_desc.is_configurable_defined = true; - new_desc.configurable = ECMA_PROPERTY_CONFIGURABLE; - } - - // b. - return ecma_op_object_define_own_property (obj_p, - property_name_p, - new_desc, - is_throw); + new_desc.is_configurable_defined = true; + new_desc.configurable = ECMA_PROPERTY_CONFIGURABLE; } + // b. + return ecma_op_object_define_own_property (obj_p, + property_name_p, + new_desc, + is_throw); + } + JERRY_UNREACHABLE(); } /* ecma_op_object_put */ @@ -304,79 +304,79 @@ ecma_op_object_can_put (ecma_object_t *obj_p, /**< the object */ // 2. if (prop_p != NULL) + { + // a. + if (prop_p->type == ECMA_PROPERTY_NAMEDACCESSOR) { - // a. - if (prop_p->type == ECMA_PROPERTY_NAMEDACCESSOR) - { - ecma_object_t *setter_p = ECMA_GET_POINTER(prop_p->u.named_accessor_property.set_p); + ecma_object_t *setter_p = ECMA_GET_POINTER(prop_p->u.named_accessor_property.set_p); - // i. - if (setter_p == NULL) - { - return false; - } + // i. + if (setter_p == NULL) + { + return false; + } - // ii. - return true; - } - else - { - // b. - - JERRY_ASSERT(prop_p->type == ECMA_PROPERTY_NAMEDDATA); - - return (prop_p->u.named_data_property.writable == ECMA_PROPERTY_WRITABLE); - } + // ii. + return true; } + else + { + // b. + + JERRY_ASSERT(prop_p->type == ECMA_PROPERTY_NAMEDDATA); + + return (prop_p->u.named_data_property.writable == ECMA_PROPERTY_WRITABLE); + } + } // 3. ecma_object_t *proto_p = ECMA_GET_POINTER(obj_p->u.object.prototype_object_p); // 4. if (proto_p == NULL) - { - return obj_p->u.object.extensible; - } + { + return obj_p->u.object.extensible; + } // 5. ecma_property_t *inherited_p = ecma_op_object_get_property (proto_p, property_name_p); // 6. if (inherited_p == NULL) - { - return obj_p->u.object.extensible; - } + { + return obj_p->u.object.extensible; + } // 7. if (inherited_p->type == ECMA_PROPERTY_NAMEDACCESSOR) + { + ecma_object_t *setter_p = ECMA_GET_POINTER(inherited_p->u.named_accessor_property.set_p); + + // a. + if (setter_p == NULL) { - ecma_object_t *setter_p = ECMA_GET_POINTER(inherited_p->u.named_accessor_property.set_p); - - // a. - if (setter_p == NULL) - { - return false; - } - - // b. - return true; + return false; } + + // b. + return true; + } else - { - // 8. - JERRY_ASSERT(inherited_p->type == ECMA_PROPERTY_NAMEDDATA); + { + // 8. + JERRY_ASSERT(inherited_p->type == ECMA_PROPERTY_NAMEDDATA); - // a. - if (!obj_p->u.object.extensible) - { - return false; - } - else - { - // b. - return (inherited_p->u.named_data_property.writable == ECMA_PROPERTY_WRITABLE); - } + // a. + if (!obj_p->u.object.extensible) + { + return false; } + else + { + // b. + return (inherited_p->u.named_data_property.writable == ECMA_PROPERTY_WRITABLE); + } + } JERRY_UNREACHABLE(); } /* ecma_op_object_can_put */ @@ -436,41 +436,41 @@ ecma_op_object_delete (ecma_object_t *obj_p, /**< the object */ // 2. if (desc_p == NULL) - { - return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE); - } + { + return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE); + } // 3. bool is_configurable; if (desc_p->type == ECMA_PROPERTY_NAMEDACCESSOR) - { - is_configurable = desc_p->u.named_accessor_property.configurable; - } + { + is_configurable = desc_p->u.named_accessor_property.configurable; + } else - { - JERRY_ASSERT(desc_p->type == ECMA_PROPERTY_NAMEDDATA); + { + JERRY_ASSERT(desc_p->type == ECMA_PROPERTY_NAMEDDATA); - is_configurable = desc_p->u.named_data_property.configurable; - } + is_configurable = desc_p->u.named_data_property.configurable; + } if (is_configurable) - { - // a. - ecma_delete_property (obj_p, desc_p); + { + // a. + ecma_delete_property (obj_p, desc_p); - // b. - return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE); - } + // b. + return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE); + } else if (is_throw) - { - // 4. - return ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); - } + { + // 4. + return ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); + } else - { - // 5. - return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); - } + { + // 5. + return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); + } JERRY_UNREACHABLE(); } /* ecma_op_object_delete */ @@ -512,13 +512,13 @@ ecma_op_object_define_own_property (ecma_object_t *obj_p, /**< the object */ JERRY_ASSERT(property_name_p != NULL); const bool is_property_desc_generic_descriptor = (!property_desc.is_value_defined - && !property_desc.is_writable_defined - && !property_desc.is_get_defined - && !property_desc.is_set_defined); + && !property_desc.is_writable_defined + && !property_desc.is_get_defined + && !property_desc.is_set_defined); const bool is_property_desc_data_descriptor = (property_desc.is_value_defined - || property_desc.is_writable_defined); + || property_desc.is_writable_defined); const bool is_property_desc_accessor_descriptor = (property_desc.is_get_defined - || property_desc.is_set_defined); + || property_desc.is_set_defined); // 1. ecma_property_t *current_p = ecma_op_object_get_own_property (obj_p, property_name_p); @@ -527,55 +527,55 @@ ecma_op_object_define_own_property (ecma_object_t *obj_p, /**< the object */ bool extensible = obj_p->u.object.extensible; if (current_p == NULL) + { + // 3. + if (!extensible) { - // 3. - if (!extensible) - { - return ecma_reject (is_throw); - } - else - { - // 4. - - // a. - if (is_property_desc_generic_descriptor - || is_property_desc_data_descriptor) - { - ecma_property_t *new_prop_p = ecma_create_named_data_property (obj_p, - property_name_p, - property_desc.writable, - property_desc.enumerable, - property_desc.configurable); - - new_prop_p->u.named_data_property.value = ecma_copy_value (property_desc.value, false); - - ecma_gc_update_may_ref_younger_object_flag_by_value (obj_p, property_desc.value); - } - else - { - // b. - JERRY_ASSERT(is_property_desc_accessor_descriptor); - - ecma_create_named_accessor_property (obj_p, - property_name_p, - property_desc.get_p, - property_desc.set_p, - property_desc.enumerable, - property_desc.configurable); - - } - - return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE); - } + return ecma_reject (is_throw); } + else + { + // 4. + + // a. + if (is_property_desc_generic_descriptor + || is_property_desc_data_descriptor) + { + ecma_property_t *new_prop_p = ecma_create_named_data_property (obj_p, + property_name_p, + property_desc.writable, + property_desc.enumerable, + property_desc.configurable); + + new_prop_p->u.named_data_property.value = ecma_copy_value (property_desc.value, false); + + ecma_gc_update_may_ref_younger_object_flag_by_value (obj_p, property_desc.value); + } + else + { + // b. + JERRY_ASSERT(is_property_desc_accessor_descriptor); + + ecma_create_named_accessor_property (obj_p, + property_name_p, + property_desc.get_p, + property_desc.set_p, + property_desc.enumerable, + property_desc.configurable); + + } + + return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE); + } + } // 5. if (is_property_desc_generic_descriptor - && !property_desc.is_enumerable_defined - && !property_desc.is_configurable_defined) - { - return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE); - } + && !property_desc.is_enumerable_defined + && !property_desc.is_configurable_defined) + { + return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE); + } // 6. const bool is_current_data_descriptor = (current_p->type == ECMA_PROPERTY_NAMEDDATA); @@ -583,226 +583,226 @@ ecma_op_object_define_own_property (ecma_object_t *obj_p, /**< the object */ const ecma_property_enumerable_value_t current_enumerable = is_current_data_descriptor ? current_p->u.named_data_property.enumerable - : current_p->u.named_accessor_property.enumerable; + : current_p->u.named_accessor_property.enumerable; const ecma_property_configurable_value_t current_configurable = is_current_data_descriptor ? current_p->u.named_data_property.configurable - : current_p->u.named_accessor_property.configurable; + : current_p->u.named_accessor_property.configurable; JERRY_ASSERT(is_current_data_descriptor || is_current_accessor_descriptor); bool is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = true; if (property_desc.is_value_defined) + { + if (!is_current_data_descriptor + || !ecma_op_same_value (property_desc.value, + current_p->u.named_data_property.value)) { - if (!is_current_data_descriptor - || !ecma_op_same_value (property_desc.value, - current_p->u.named_data_property.value)) - { - is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false; - } + is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false; } + } if (property_desc.is_writable_defined) + { + if (!is_current_data_descriptor + || property_desc.writable != current_p->u.named_data_property.writable) { - if (!is_current_data_descriptor - || property_desc.writable != current_p->u.named_data_property.writable) - { - is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false; - } + is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false; } + } if (property_desc.is_get_defined) + { + if (!is_current_accessor_descriptor + || property_desc.get_p != ECMA_GET_POINTER(current_p->u.named_accessor_property.get_p)) { - if (!is_current_accessor_descriptor - || property_desc.get_p != ECMA_GET_POINTER(current_p->u.named_accessor_property.get_p)) - { - is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false; - } + is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false; } + } if (property_desc.is_set_defined) + { + if (!is_current_accessor_descriptor + || property_desc.set_p != ECMA_GET_POINTER(current_p->u.named_accessor_property.set_p)) { - if (!is_current_accessor_descriptor - || property_desc.set_p != ECMA_GET_POINTER(current_p->u.named_accessor_property.set_p)) - { - is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false; - } + is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false; } + } if (property_desc.is_enumerable_defined) + { + if (property_desc.enumerable != current_enumerable) { - if (property_desc.enumerable != current_enumerable) - { - is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false; - } + is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false; } + } if (property_desc.is_configurable_defined) + { + if (property_desc.configurable != current_configurable) { - if (property_desc.configurable != current_configurable) - { - is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false; - } + is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false; } + } if (is_every_field_in_desc_also_occurs_in_current_desc_with_same_value) - { - return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE); - } + { + return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE); + } // 7. if (current_p->u.named_accessor_property.configurable == ECMA_PROPERTY_NOT_CONFIGURABLE) + { + if (property_desc.configurable == ECMA_PROPERTY_CONFIGURABLE + || (property_desc.is_enumerable_defined + && property_desc.enumerable != current_enumerable)) { - if (property_desc.configurable == ECMA_PROPERTY_CONFIGURABLE - || (property_desc.is_enumerable_defined - && property_desc.enumerable != current_enumerable)) - { - // a., b. - return ecma_reject (is_throw); - } + // a., b. + return ecma_reject (is_throw); } + } // 8. if (is_property_desc_generic_descriptor) - { - // no action required - } + { + // no action required + } else if (is_property_desc_data_descriptor != is_current_data_descriptor) + { + // 9. + if (current_configurable == ECMA_PROPERTY_NOT_CONFIGURABLE) { - // 9. - if (current_configurable == ECMA_PROPERTY_NOT_CONFIGURABLE) + // a. + return ecma_reject (is_throw); + } + + ecma_delete_property (obj_p, current_p); + + if (is_current_data_descriptor) + { + // b. + + current_p = ecma_create_named_accessor_property (obj_p, + property_name_p, + NULL, + NULL, + current_enumerable, + current_configurable); + } + else + { + // c. + + current_p = ecma_create_named_data_property (obj_p, + property_name_p, + ECMA_PROPERTY_NOT_WRITABLE, + current_enumerable, + current_configurable); + } + } + else if (is_property_desc_data_descriptor && is_current_data_descriptor) + { + // 10. + if (current_configurable == ECMA_PROPERTY_NOT_CONFIGURABLE) + { + // a. + if (current_p->u.named_data_property.writable == ECMA_PROPERTY_NOT_WRITABLE) + { + // i. + if (property_desc.writable == ECMA_PROPERTY_WRITABLE) { - // a. return ecma_reject (is_throw); } - ecma_delete_property (obj_p, current_p); - - if (is_current_data_descriptor) + // ii. + if (property_desc.is_value_defined + && !ecma_op_same_value (property_desc.value, + current_p->u.named_data_property.value)) { - // b. - - current_p = ecma_create_named_accessor_property (obj_p, - property_name_p, - NULL, - NULL, - current_enumerable, - current_configurable); - } - else - { - // c. - - current_p = ecma_create_named_data_property (obj_p, - property_name_p, - ECMA_PROPERTY_NOT_WRITABLE, - current_enumerable, - current_configurable); - } - } - else if (is_property_desc_data_descriptor && is_current_data_descriptor) - { - // 10. - if (current_configurable == ECMA_PROPERTY_NOT_CONFIGURABLE) - { - // a. - if (current_p->u.named_data_property.writable == ECMA_PROPERTY_NOT_WRITABLE) - { - // i. - if (property_desc.writable == ECMA_PROPERTY_WRITABLE) - { - return ecma_reject (is_throw); - } - - // ii. - if (property_desc.is_value_defined - && !ecma_op_same_value (property_desc.value, - current_p->u.named_data_property.value)) - { - return ecma_reject (is_throw); - } - } + return ecma_reject (is_throw); } + } } + } else + { + JERRY_ASSERT(is_property_desc_accessor_descriptor && is_current_accessor_descriptor); + + // 11. + + if (current_configurable == ECMA_PROPERTY_NOT_CONFIGURABLE) { - JERRY_ASSERT(is_property_desc_accessor_descriptor && is_current_accessor_descriptor); + // a. - // 11. - - if (current_configurable == ECMA_PROPERTY_NOT_CONFIGURABLE) - { - // a. - - if ((property_desc.is_get_defined - && property_desc.get_p != ECMA_GET_POINTER(current_p->u.named_accessor_property.get_p)) - || (property_desc.is_set_defined - && property_desc.set_p != ECMA_GET_POINTER(current_p->u.named_accessor_property.set_p))) - { - // i., ii. - return ecma_reject (is_throw); - } - } + if ((property_desc.is_get_defined + && property_desc.get_p != ECMA_GET_POINTER(current_p->u.named_accessor_property.get_p)) + || (property_desc.is_set_defined + && property_desc.set_p != ECMA_GET_POINTER(current_p->u.named_accessor_property.set_p))) + { + // i., ii. + return ecma_reject (is_throw); + } } + } // 12. if (property_desc.is_value_defined) - { - JERRY_ASSERT(is_current_data_descriptor); + { + JERRY_ASSERT(is_current_data_descriptor); - ecma_free_value (current_p->u.named_data_property.value, false); - current_p->u.named_data_property.value = ecma_copy_value (property_desc.value, false); + ecma_free_value (current_p->u.named_data_property.value, false); + current_p->u.named_data_property.value = ecma_copy_value (property_desc.value, false); - ecma_gc_update_may_ref_younger_object_flag_by_value (obj_p, property_desc.value); - } + ecma_gc_update_may_ref_younger_object_flag_by_value (obj_p, property_desc.value); + } if (property_desc.is_writable_defined) - { - JERRY_ASSERT(is_current_data_descriptor); + { + JERRY_ASSERT(is_current_data_descriptor); - current_p->u.named_data_property.writable = property_desc.writable; - } + current_p->u.named_data_property.writable = property_desc.writable; + } if (property_desc.is_get_defined) - { - JERRY_ASSERT(is_current_accessor_descriptor); + { + JERRY_ASSERT(is_current_accessor_descriptor); - ECMA_SET_POINTER(current_p->u.named_accessor_property.get_p, property_desc.get_p); + ECMA_SET_POINTER(current_p->u.named_accessor_property.get_p, property_desc.get_p); - ecma_gc_update_may_ref_younger_object_flag_by_object (obj_p, property_desc.get_p); - } + ecma_gc_update_may_ref_younger_object_flag_by_object (obj_p, property_desc.get_p); + } if (property_desc.is_set_defined) - { - JERRY_ASSERT(is_current_accessor_descriptor); + { + JERRY_ASSERT(is_current_accessor_descriptor); - ECMA_SET_POINTER(current_p->u.named_accessor_property.set_p, property_desc.set_p); + ECMA_SET_POINTER(current_p->u.named_accessor_property.set_p, property_desc.set_p); - ecma_gc_update_may_ref_younger_object_flag_by_object (obj_p, property_desc.set_p); - } + ecma_gc_update_may_ref_younger_object_flag_by_object (obj_p, property_desc.set_p); + } if (property_desc.is_enumerable_defined) + { + if (is_current_data_descriptor) { - if (is_current_data_descriptor) - { - current_p->u.named_data_property.enumerable = property_desc.enumerable; - } - else - { - current_p->u.named_accessor_property.enumerable = property_desc.enumerable; - } + current_p->u.named_data_property.enumerable = property_desc.enumerable; } + else + { + current_p->u.named_accessor_property.enumerable = property_desc.enumerable; + } + } if (property_desc.is_configurable_defined) + { + if (is_current_data_descriptor) { - if (is_current_data_descriptor) - { - current_p->u.named_data_property.configurable = property_desc.configurable; - } - else - { - current_p->u.named_accessor_property.configurable = property_desc.configurable; - } + current_p->u.named_data_property.configurable = property_desc.configurable; } + else + { + current_p->u.named_accessor_property.configurable = property_desc.configurable; + } + } return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE); } /* ecma_op_object_define_own_property */ diff --git a/src/libecmaoperations/ecma-reference.c b/src/libecmaoperations/ecma-reference.c index c30d987b0..795165b65 100644 --- a/src/libecmaoperations/ecma-reference.c +++ b/src/libecmaoperations/ecma-reference.c @@ -41,8 +41,8 @@ */ ecma_reference_t ecma_op_get_identifier_reference (ecma_object_t *lex_env_p, /**< lexical environment */ - const ecma_char_t *name_p, /**< identifier's name */ - bool is_strict) /**< strict reference flag */ + const ecma_char_t *name_p, /**< identifier's name */ + bool is_strict) /**< strict reference flag */ { JERRY_ASSERT(lex_env_p != NULL); @@ -56,8 +56,8 @@ ecma_op_get_identifier_reference (ecma_object_t *lex_env_p, /**< lexical environ if (ecma_is_completion_value_normal_true (completion_value)) { return ecma_make_reference (ecma_make_object_value (lex_env_iter_p), - name_p, - is_strict); + name_p, + is_strict); } else { JERRY_ASSERT(ecma_is_completion_value_normal_false (completion_value)); @@ -67,8 +67,8 @@ ecma_op_get_identifier_reference (ecma_object_t *lex_env_p, /**< lexical environ } return ecma_make_reference (ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED), - name_p, - is_strict); + name_p, + is_strict); } /* ecma_op_get_identifier_reference */ /** @@ -83,12 +83,15 @@ ecma_op_get_identifier_reference (ecma_object_t *lex_env_p, /**< lexical environ */ ecma_reference_t ecma_make_reference (ecma_value_t base, /**< base value */ - const ecma_char_t *name_p, /**< referenced name */ - bool is_strict) /**< strict reference flag */ + const ecma_char_t *name_p, /**< referenced name */ + bool is_strict) /**< strict reference flag */ { - ecma_reference_t ref = (ecma_reference_t) { .base = ecma_copy_value (base, true), - .referenced_name_p = name_p, - .is_strict = is_strict }; + ecma_reference_t ref = (ecma_reference_t) + { + .base = ecma_copy_value (base, true), + .referenced_name_p = name_p, + .is_strict = is_strict + }; return ref; } /* ecma_make_reference */