Splitting ecma_create_lexical_environment to ecma_create_decl_lex_env and ecma_create_object_lex_env.

This commit is contained in:
Ruben Ayrapetyan 2014-07-31 14:48:28 +04:00
parent 16cab18ae9
commit c364461b80
4 changed files with 68 additions and 28 deletions

View File

@ -48,8 +48,7 @@ run_int (void)
const opcode_counter_t start_pos = 0; const opcode_counter_t start_pos = 0;
ecma_value_t this_binding_value = ecma_make_simple_value( ECMA_SIMPLE_VALUE_UNDEFINED); 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_object_t *lex_env_p = ecma_create_decl_lex_env (NULL);
ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE);
FIXME( Strict mode ); FIXME( Strict mode );
const bool is_strict = false; const bool is_strict = false;

View File

@ -100,44 +100,84 @@ ecma_create_object( ecma_object_t *prototype_object_p, /**< pointer to prototybe
} /* ecma_create_object */ } /* 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). * (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. * 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 * @return pointer to the descriptor of lexical environment
*/ */
ecma_object_t* ecma_object_t*
ecma_create_lexical_environment(ecma_object_t *outer_lexical_environment_p, /**< outer lexical environment */ ecma_create_decl_lex_env(ecma_object_t *outer_lexical_environment_p) /**< outer lexical environment */
ecma_lexical_environment_type_t type) /**< type of lexical environment to create */
{ {
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->is_lexical_environment = true;
new_lexical_environment_p->u.lexical_environment.type = type; 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.is_object_valid = true;
new_lexical_environment_p->GCInfo.u.refs = 1; new_lexical_environment_p->GCInfo.u.refs = 1;
if ( outer_lexical_environment_p != NULL ) if ( outer_lexical_environment_p != NULL )
{ {
ecma_ref_object( outer_lexical_environment_p); 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_set_pointer( new_lexical_environment_p->u.lexical_environment.outer_reference_p, outer_lexical_environment_p);
return new_lexical_environment_p; return new_lexical_environment_p;
} /* ecma_create_lexical_environment */ } /* ecma_create_decl_lex_env */
/** /**
* Create internal property in an object and link it * Create a declarative lexical environment with specified outer lexical environment
* into the object's properties' linked-list * (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 * @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_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_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_CLASS: /* an enum */
case ECMA_INTERNAL_PROPERTY_CODE: /* an integer */ case ECMA_INTERNAL_PROPERTY_CODE: /* an integer */
{ {

View File

@ -71,7 +71,8 @@ extern bool ecma_is_empty_completion_value( ecma_completion_value_t value);
/* ecma-helpers.c */ /* 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_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_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); extern ecma_property_t* ecma_find_internal_property(ecma_object_t *object_p, ecma_internal_property_id_t property_id);

View File

@ -279,7 +279,7 @@ ecma_op_function_call( ecma_object_t *func_obj_p, /**< Function object */
} }
// 5. // 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. // 9.
/* Declaration binding instantiation (ECMA-262 v5, 10.5), block 4 */ /* Declaration binding instantiation (ECMA-262 v5, 10.5), block 4 */