Providing interface for getting reference to Global lexical environment.
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
#include "ecma-helpers.h"
|
#include "ecma-helpers.h"
|
||||||
#include "ecma-init-finalize.h"
|
#include "ecma-init-finalize.h"
|
||||||
#include "ecma-lcache.h"
|
#include "ecma-lcache.h"
|
||||||
|
#include "ecma-lex-env.h"
|
||||||
#include "ecma-stack.h"
|
#include "ecma-stack.h"
|
||||||
#include "mem-allocator.h"
|
#include "mem-allocator.h"
|
||||||
|
|
||||||
@@ -38,6 +39,7 @@ ecma_init (void)
|
|||||||
ecma_init_builtins ();
|
ecma_init_builtins ();
|
||||||
ecma_lcache_init ();
|
ecma_lcache_init ();
|
||||||
ecma_stack_init ();
|
ecma_stack_init ();
|
||||||
|
ecma_init_environment ();
|
||||||
|
|
||||||
mem_register_a_try_give_memory_back_callback (ecma_try_to_give_back_some_memory);
|
mem_register_a_try_give_memory_back_callback (ecma_try_to_give_back_some_memory);
|
||||||
} /* ecma_init */
|
} /* ecma_init */
|
||||||
@@ -50,6 +52,7 @@ ecma_finalize (void)
|
|||||||
{
|
{
|
||||||
mem_unregister_a_try_give_memory_back_callback (ecma_try_to_give_back_some_memory);
|
mem_unregister_a_try_give_memory_back_callback (ecma_try_to_give_back_some_memory);
|
||||||
|
|
||||||
|
ecma_finalize_environment ();
|
||||||
ecma_stack_finalize ();
|
ecma_stack_finalize ();
|
||||||
ecma_finalize_builtins ();
|
ecma_finalize_builtins ();
|
||||||
ecma_lcache_invalidate_all ();
|
ecma_lcache_invalidate_all ();
|
||||||
|
|||||||
@@ -31,6 +31,77 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \addtogroup globallexicalenvironment Global lexical environment
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Global lexical environment
|
||||||
|
*
|
||||||
|
* See also: ECMA-262 v5, 10.2.3
|
||||||
|
*/
|
||||||
|
ecma_object_t* ecma_global_lex_env_p = NULL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize Global environment
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ecma_init_environment (void)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_ECMA_GLOBAL_ENVIRONMENT_DECLARATIVE
|
||||||
|
ecma_global_lex_env_p = ecma_create_decl_lex_env (NULL);
|
||||||
|
#else /* !CONFIG_ECMA_GLOBAL_ENVIRONMENT_DECLARATIVE */
|
||||||
|
ecma_object_t *glob_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_GLOBAL);
|
||||||
|
|
||||||
|
ecma_global_lex_env_p = ecma_create_object_lex_env (NULL, glob_obj_p, false);
|
||||||
|
|
||||||
|
ecma_deref_object (glob_obj_p);
|
||||||
|
#endif /* !CONFIG_ECMA_GLOBAL_ENVIRONMENT_DECLARATIVE */
|
||||||
|
} /* ecma_init_environment */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finalize Global environment
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ecma_finalize_environment (void)
|
||||||
|
{
|
||||||
|
ecma_deref_object (ecma_global_lex_env_p);
|
||||||
|
ecma_global_lex_env_p = NULL;
|
||||||
|
} /* ecma_finalize_environment */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get reference to Global lexical environment
|
||||||
|
*
|
||||||
|
* @return pointer to the object's instance
|
||||||
|
*/
|
||||||
|
ecma_object_t*
|
||||||
|
ecma_get_global_environment (void)
|
||||||
|
{
|
||||||
|
ecma_ref_object (ecma_global_lex_env_p);
|
||||||
|
|
||||||
|
return ecma_global_lex_env_p;
|
||||||
|
} /* ecma_get_global_environment */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Figure out whether the lexical environment is global.
|
||||||
|
*
|
||||||
|
* @return true - if lexical environment is object-bound and corresponding object is global object,
|
||||||
|
* false - otherwise.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
ecma_is_lexical_environment_global (ecma_object_t *lex_env_p) /**< lexical environment */
|
||||||
|
{
|
||||||
|
JERRY_ASSERT(lex_env_p != NULL
|
||||||
|
&& ecma_is_lexical_environment (lex_env_p));
|
||||||
|
|
||||||
|
return (lex_env_p == ecma_global_lex_env_p);
|
||||||
|
} /* ecma_is_lexical_environment_global */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HasBinding operation.
|
* HasBinding operation.
|
||||||
*
|
*
|
||||||
@@ -423,52 +494,6 @@ ecma_op_initialize_immutable_binding (ecma_object_t *lex_env_p, /**< lexical env
|
|||||||
ecma_named_data_property_assign_value (lex_env_p, prop_p, value);
|
ecma_named_data_property_assign_value (lex_env_p, prop_p, value);
|
||||||
} /* ecma_op_initialize_immutable_binding */
|
} /* ecma_op_initialize_immutable_binding */
|
||||||
|
|
||||||
/**
|
|
||||||
* The Global Environment constructor.
|
|
||||||
*
|
|
||||||
* See also: ECMA-262 v5, 10.2.3
|
|
||||||
*
|
|
||||||
* @return pointer to created lexical environment
|
|
||||||
*/
|
|
||||||
ecma_object_t*
|
|
||||||
ecma_op_create_global_environment (ecma_object_t *glob_obj_p) /**< the Global object */
|
|
||||||
{
|
|
||||||
#ifdef CONFIG_ECMA_GLOBAL_ENVIRONMENT_DECLARATIVE
|
|
||||||
(void) glob_obj_p;
|
|
||||||
ecma_object_t *glob_env_p = ecma_create_decl_lex_env (NULL);
|
|
||||||
#else /* !CONFIG_ECMA_GLOBAL_ENVIRONMENT_DECLARATIVE */
|
|
||||||
ecma_object_t *glob_env_p = ecma_create_object_lex_env (NULL, glob_obj_p, false);
|
|
||||||
#endif /* !CONFIG_ECMA_GLOBAL_ENVIRONMENT_DECLARATIVE */
|
|
||||||
|
|
||||||
return glob_env_p;
|
|
||||||
} /* ecma_op_create_global_environment */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Figure out whether the lexical environment is global.
|
|
||||||
*
|
|
||||||
* @return true - if lexical environment is object-bound and corresponding object is global object,
|
|
||||||
* false - otherwise.
|
|
||||||
*/
|
|
||||||
bool
|
|
||||||
ecma_is_lexical_environment_global (ecma_object_t *lex_env_p) /**< lexical environment */
|
|
||||||
{
|
|
||||||
JERRY_ASSERT(lex_env_p != NULL
|
|
||||||
&& ecma_is_lexical_environment (lex_env_p));
|
|
||||||
|
|
||||||
ecma_lexical_environment_type_t type = ecma_get_lex_env_type (lex_env_p);
|
|
||||||
|
|
||||||
if (type == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND)
|
|
||||||
{
|
|
||||||
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
|
|
||||||
|
|
||||||
return ecma_builtin_is (binding_obj_p, ECMA_BUILTIN_ID_GLOBAL);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} /* ecma_is_lexical_environment_global */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -29,6 +29,20 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \addtogroup globallexicalenvironment Global lexical environment
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern void ecma_init_environment (void);
|
||||||
|
extern void ecma_finalize_environment (void);
|
||||||
|
extern ecma_object_t* ecma_get_global_environment (void);
|
||||||
|
extern bool ecma_is_lexical_environment_global (ecma_object_t *lex_env_p);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
/* ECMA-262 v5, 8.7.1 and 8.7.2 */
|
/* ECMA-262 v5, 8.7.1 and 8.7.2 */
|
||||||
extern ecma_completion_value_t ecma_op_get_value_lex_env_base (ecma_object_t *ref_base_lex_env_p,
|
extern ecma_completion_value_t ecma_op_get_value_lex_env_base (ecma_object_t *ref_base_lex_env_p,
|
||||||
ecma_string_t *var_name_string_p,
|
ecma_string_t *var_name_string_p,
|
||||||
@@ -66,7 +80,6 @@ extern void ecma_op_initialize_immutable_binding (ecma_object_t *lex_env_p,
|
|||||||
const ecma_value_t& value);
|
const ecma_value_t& value);
|
||||||
|
|
||||||
extern ecma_object_t* ecma_op_create_global_environment (ecma_object_t *glob_obj_p);
|
extern ecma_object_t* ecma_op_create_global_environment (ecma_object_t *glob_obj_p);
|
||||||
extern bool ecma_is_lexical_environment_global (ecma_object_t *lex_env_p);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -366,12 +366,10 @@ run_int (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ecma_object_t *glob_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_GLOBAL);
|
ecma_object_t *glob_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_GLOBAL);
|
||||||
|
ecma_object_t *lex_env_p = ecma_get_global_environment ();
|
||||||
ecma_object_t *lex_env_p = ecma_op_create_global_environment (glob_obj_p);
|
|
||||||
ecma_value_t this_binding_value = ecma_make_object_value (glob_obj_p);
|
|
||||||
|
|
||||||
ecma_completion_value_t completion = run_int_from_pos (start_pos,
|
ecma_completion_value_t completion = run_int_from_pos (start_pos,
|
||||||
this_binding_value,
|
ecma_make_object_value (glob_obj_p),
|
||||||
lex_env_p,
|
lex_env_p,
|
||||||
is_strict,
|
is_strict,
|
||||||
false);
|
false);
|
||||||
|
|||||||
Reference in New Issue
Block a user