From 0dd67e4799688142d5415375ad4fee18e77de605 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Wed, 30 Jul 2014 14:24:01 +0400 Subject: [PATCH] Introducing ecma_object_class_t type that describes ecma-defined object classes (value of ECMA_INTERNAL_PROPERTY_CLASS internal property); adding outer lexical environment's reference counter increment in ecma_create_lexical_environment; updating ecma_create_object to support object type field (that is not connected with ecma-defined object class, but is internal implementation defined type of an object). --- src/libecmaobjects/ecma-globals.h | 40 +++++++++++++++++++++++-------- src/libecmaobjects/ecma-helpers.c | 15 +++++++++--- src/libecmaobjects/ecma-helpers.h | 2 +- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/libecmaobjects/ecma-globals.h b/src/libecmaobjects/ecma-globals.h index 58e5d0761..8230d81ab 100644 --- a/src/libecmaobjects/ecma-globals.h +++ b/src/libecmaobjects/ecma-globals.h @@ -147,6 +147,8 @@ typedef enum { 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, @@ -243,7 +245,7 @@ typedef struct ecma_property_t { unsigned int internal_property_type : 4; /** Value (may be a compressed pointer) */ - unsigned int value : ECMA_POINTER_FIELD_WIDTH; + uint32_t value; } internal_property; } u; } ecma_property_t; @@ -289,16 +291,34 @@ typedef enum { * Internal object types */ typedef enum { - ECMA_GENERAL_OBJECT, /**< 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_STRING_OBJECT, /**< String objects (15.5) */ - ECMA_FUNCTION_OBJECT, /**< Function objects (15.3) */ - ECMA_ARGUMENTS_OBJECT, /**< Arguments object (10.6) */ - ECMA_ARRAY_OBJECT, /**< Array object (15.4) */ - ECMA_HOST_OBJECT /**< Host object */ + 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) */ + 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" */ +} ecma_object_class_t; + /** * Description of ECMA-object or lexical environment * (depending on is_lexical_environment). @@ -324,7 +344,7 @@ typedef struct ecma_object_t { unsigned int extensible : 1; /** Implementation internal object type (ecma_object_type_t) */ - unsigned int object_type : 3; + unsigned int type : 3; /** Compressed pointer to prototype object (ecma_object_t) */ unsigned int prototype_object_p : ECMA_POINTER_FIELD_WIDTH; diff --git a/src/libecmaobjects/ecma-helpers.c b/src/libecmaobjects/ecma-helpers.c index bc7f67b6a..be6c2ddc5 100644 --- a/src/libecmaobjects/ecma-helpers.c +++ b/src/libecmaobjects/ecma-helpers.c @@ -79,7 +79,8 @@ ecma_decompress_pointer(uintptr_t compressed_pointer) /**< pointer to decompress */ ecma_object_t* ecma_create_object( ecma_object_t *prototype_object_p, /**< pointer to prototybe of the object (or NULL) */ - bool is_extensible) /**< value of extensible attribute */ + bool is_extensible, /**< value of extensible attribute */ + ecma_object_type_t type) /**< object type */ { ecma_object_t *object_p = ecma_alloc_object(); @@ -93,6 +94,7 @@ ecma_create_object( ecma_object_t *prototype_object_p, /**< pointer to prototybe 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; } /* ecma_create_object */ @@ -111,7 +113,7 @@ ecma_create_object( ecma_object_t *prototype_object_p, /**< pointer to prototybe */ ecma_object_t* ecma_create_lexical_environment(ecma_object_t *outer_lexical_environment_p, /**< outer lexical environment */ - ecma_lexical_environment_type_t type) /**< type of lexical environment to create */ + ecma_lexical_environment_type_t type) /**< type of lexical environment to create */ { ecma_object_t *new_lexical_environment_p = ecma_alloc_object(); @@ -123,6 +125,11 @@ ecma_create_lexical_environment(ecma_object_t *outer_lexical_environment_p, /**< new_lexical_environment_p->GCInfo.is_object_valid = true; new_lexical_environment_p->GCInfo.u.refs = 1; + if ( outer_lexical_environment_p != NULL ) + { + ecma_ref_object( outer_lexical_environment_p); + } + ecma_set_pointer( new_lexical_environment_p->u.lexical_environment.outer_reference_p, outer_lexical_environment_p); return new_lexical_environment_p; @@ -407,9 +414,9 @@ ecma_free_internal_property( ecma_property_t *property_p) /**< the property */ switch ( property_id ) { - case ECMA_INTERNAL_PROPERTY_CLASS: /* a string */ 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; @@ -425,6 +432,8 @@ ecma_free_internal_property( ecma_property_t *property_p) /**< the property */ 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 flag */ + case ECMA_INTERNAL_PROPERTY_CLASS: /* an enum */ + case ECMA_INTERNAL_PROPERTY_CODE: /* an integer */ { break; } diff --git a/src/libecmaobjects/ecma-helpers.h b/src/libecmaobjects/ecma-helpers.h index f82a1331a..c43e083da 100644 --- a/src/libecmaobjects/ecma-helpers.h +++ b/src/libecmaobjects/ecma-helpers.h @@ -69,7 +69,7 @@ extern bool ecma_is_completion_value_normal_true( ecma_completion_value_t value) extern bool ecma_is_completion_value_normal_false( ecma_completion_value_t value); extern bool ecma_is_empty_completion_value( ecma_completion_value_t value); -extern ecma_object_t* ecma_create_object( ecma_object_t *prototype_object_p, bool is_extensible); +extern ecma_object_t* ecma_create_object( ecma_object_t *prototype_object_p, bool is_extensible, ecma_object_type_t type); extern ecma_object_t* ecma_create_lexical_environment( ecma_object_t *outer_lexical_environment_p, ecma_lexical_environment_type_t type); /* ecma-helpers.c */