Implement realm object and support realms for built-ins and JS functions (#4354)

- Type for realm objects is introduced (ecma_global_object_t)
- Realm reference is added to built-in objects and ECMAScript functions
- Resolving built-ins, global environments, and scopes require realm object
- Unnecessary global object accesses are removed from the code

Missing: external functions and static snapshot functions have no realm reference

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2020-12-08 14:36:36 +01:00
committed by GitHub
parent 7cb9f808f7
commit df92c86ecf
32 changed files with 1128 additions and 188 deletions
+20 -2
View File
@@ -79,6 +79,23 @@ ecma_op_resolve_reference_base (ecma_object_t *lex_env_p, /**< starting lexical
} /* ecma_op_resolve_reference_base */
#if ENABLED (JERRY_ESNEXT)
/**
* Check if the passed lexical environment is a global lexical environment
*
* @return true - if the lexical environment is a global lexical environment
* false - otherwise
*/
static inline bool JERRY_ATTR_ALWAYS_INLINE
ecma_op_is_global_environment (ecma_object_t *lex_env_p) /**< lexical environment */
{
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND);
JERRY_ASSERT (lex_env_p->u2.outer_reference_cp != JMEM_CP_NULL
|| ecma_get_lex_env_binding_object (lex_env_p) == ecma_builtin_get_global ());
return lex_env_p->u2.outer_reference_cp == JMEM_CP_NULL;
} /* ecma_op_is_global_environment */
/**
* Perform GetThisEnvironment and GetSuperBase operations
*
@@ -173,6 +190,7 @@ ecma_op_is_prop_unscopable (ecma_object_t *binding_obj_p, /**< binding object */
return ECMA_VALUE_FALSE;
} /* ecma_op_is_prop_unscopable */
#endif /* ENABLED (JERRY_ESNEXT) */
/**
@@ -226,7 +244,7 @@ ecma_op_object_bound_environment_resolve_reference_value (ecma_object_t *lex_env
}
#if ENABLED (JERRY_ESNEXT)
if (JERRY_LIKELY (lex_env_p == ecma_get_global_scope ()))
if (JERRY_LIKELY (ecma_op_is_global_environment (lex_env_p)))
#endif /* ENABLED (JERRY_ESNEXT) */
{
return found_binding;
@@ -297,7 +315,7 @@ ecma_op_resolve_reference_value (ecma_object_t *lex_env_p, /**< starting lexical
else if (lex_env_type == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND)
{
#if ENABLED (JERRY_ESNEXT)
bool lcache_lookup_allowed = (lex_env_p == ecma_get_global_environment ());
bool lcache_lookup_allowed = ecma_op_is_global_environment (lex_env_p);
#else /* !ENABLED (JERRY_ESNEXT)*/
bool lcache_lookup_allowed = true;
#endif /* ENABLED (JERRY_ESNEXT) */