diff --git a/src/libcoreint/interpreter.c b/src/libcoreint/interpreter.c index c109e706a..6ebbafb50 100644 --- a/src/libcoreint/interpreter.c +++ b/src/libcoreint/interpreter.c @@ -48,8 +48,7 @@ run_int (void) const opcode_counter_t start_pos = 0; ecma_value_t this_binding_value = ecma_make_simple_value( ECMA_SIMPLE_VALUE_UNDEFINED); - ecma_object_t *lex_env_p = ecma_create_lexical_environment (NULL, - ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE); + ecma_object_t *lex_env_p = ecma_create_decl_lex_env (NULL); FIXME( Strict mode ); const bool is_strict = false; diff --git a/src/libecmaobjects/ecma-helpers.c b/src/libecmaobjects/ecma-helpers.c index 0baa3e422..14d366a2b 100644 --- a/src/libecmaobjects/ecma-helpers.c +++ b/src/libecmaobjects/ecma-helpers.c @@ -100,44 +100,84 @@ ecma_create_object( ecma_object_t *prototype_object_p, /**< pointer to prototybe } /* ecma_create_object */ /** - * Create a lexical environment with specified outer lexical environment + * Create a declarative lexical environment with specified outer lexical environment * (or NULL if the environment is not nested). * + * See also: ECMA-262 v5, 10.2.1.1 + * * Reference counter's value will be set to one. * - * Warning: after object-bound lexical environment is created, - * caller must create internal properties, that - * specify the bound object and value of 'provideThis'. - * * @return pointer to the descriptor of lexical environment */ 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_create_decl_lex_env(ecma_object_t *outer_lexical_environment_p) /**< outer lexical environment */ { - ecma_object_t *new_lexical_environment_p = ecma_alloc_object(); + ecma_object_t *new_lexical_environment_p = ecma_alloc_object(); - new_lexical_environment_p->is_lexical_environment = true; - new_lexical_environment_p->u.lexical_environment.type = type; + new_lexical_environment_p->is_lexical_environment = true; + new_lexical_environment_p->u.lexical_environment.type = ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE; - new_lexical_environment_p->properties_p = ECMA_NULL_POINTER; + new_lexical_environment_p->properties_p = ECMA_NULL_POINTER; - new_lexical_environment_p->GCInfo.is_object_valid = true; - new_lexical_environment_p->GCInfo.u.refs = 1; + 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); - } + 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; -} /* ecma_create_lexical_environment */ + ecma_set_pointer( new_lexical_environment_p->u.lexical_environment.outer_reference_p, outer_lexical_environment_p); + + return new_lexical_environment_p; +} /* ecma_create_decl_lex_env */ /** - * Create internal property in an object and link it - * into the object's properties' linked-list + * Create a declarative lexical environment with specified outer lexical environment + * (or NULL if the environment is not nested). + * + * See also: ECMA-262 v5, 10.2.1.2 + * + * Reference counter's value will be set to one. + * + * @return pointer to the descriptor of lexical environment + */ +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 */ +{ + JERRY_ASSERT( binding_obj_p != NULL ); + + ecma_object_t *new_lexical_environment_p = ecma_alloc_object(); + + new_lexical_environment_p->is_lexical_environment = true; + new_lexical_environment_p->u.lexical_environment.type = ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND; + + new_lexical_environment_p->properties_p = ECMA_NULL_POINTER; + + 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); + + ecma_property_t *provide_this_prop_p = ecma_create_internal_property( new_lexical_environment_p, ECMA_INTERNAL_PROPERTY_PROVIDE_THIS); + provide_this_prop_p->u.internal_property.value = provide_this; + + ecma_property_t *binding_object_prop_p = ecma_create_internal_property( new_lexical_environment_p, ECMA_INTERNAL_PROPERTY_BINDING_OBJECT); + ecma_set_pointer( binding_object_prop_p->u.internal_property.value, binding_obj_p); + + return new_lexical_environment_p; +} /* ecma_create_object_lex_env */ + +/** + * Create internal property in an object and link it into + * the object's properties' linked-list (at start of the list). * * @return pointer to newly created property */ @@ -431,7 +471,7 @@ 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_PROVIDE_THIS: /* a boolean */ case ECMA_INTERNAL_PROPERTY_CLASS: /* an enum */ case ECMA_INTERNAL_PROPERTY_CODE: /* an integer */ { diff --git a/src/libecmaobjects/ecma-helpers.h b/src/libecmaobjects/ecma-helpers.h index 6ae240462..13f8a213b 100644 --- a/src/libecmaobjects/ecma-helpers.h +++ b/src/libecmaobjects/ecma-helpers.h @@ -71,7 +71,8 @@ extern bool ecma_is_empty_completion_value( ecma_completion_value_t value); /* ecma-helpers.c */ 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); +extern ecma_object_t* ecma_create_decl_lex_env( ecma_object_t *outer_lexical_environment_p); +extern ecma_object_t* ecma_create_object_lex_env( ecma_object_t *outer_lexical_environment_p, ecma_object_t *binding_obj_p, bool provide_this); extern ecma_property_t* ecma_create_internal_property(ecma_object_t *object_p, ecma_internal_property_id_t property_id); extern ecma_property_t* ecma_find_internal_property(ecma_object_t *object_p, ecma_internal_property_id_t property_id); diff --git a/src/libecmaoperations/ecma-function-object.c b/src/libecmaoperations/ecma-function-object.c index 3f9bed09f..eba885e43 100644 --- a/src/libecmaoperations/ecma-function-object.c +++ b/src/libecmaoperations/ecma-function-object.c @@ -279,7 +279,7 @@ ecma_op_function_call( ecma_object_t *func_obj_p, /**< Function object */ } // 5. - ecma_object_t *local_env_p = ecma_create_lexical_environment( scope_p, ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE); + ecma_object_t *local_env_p = ecma_create_decl_lex_env( scope_p); // 9. /* Declaration binding instantiation (ECMA-262 v5, 10.5), block 4 */