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
@@ -88,15 +88,38 @@ typedef enum
*/
#define ECMA_ACCESSOR_READ_WRITE_GET_GETTER_ID(value) ((uint8_t) ((value) >> 8))
/**
* Number ob built-in objects excluding global object
*/
#define ECMA_BUILTIN_OBJECTS_COUNT (ECMA_BUILTIN_ID__COUNT - 1)
/**
* Description of built-in global ECMA-object.
*/
typedef struct
{
ecma_extended_object_t extended_object; /**< extended object part */
uint32_t extra_instantiated_bitset[1]; /**< extra bit set for instantiated properties */
#if ENABLED (JERRY_BUILTIN_REALMS)
uint32_t extra_realms_bitset; /**< extra bit set for instantiated properties when realms is enabled */
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
jmem_cpointer_t global_env_cp; /**< global lexical environment */
#if ENABLED (JERRY_ESNEXT)
jmem_cpointer_t global_scope_cp; /**< global lexical scope */
#endif /* ENABLED (JERRY_ESNEXT) */
jmem_cpointer_t builtin_objects[ECMA_BUILTIN_OBJECTS_COUNT]; /**< pointer to instances of built-in objects */
} ecma_global_object_t;
/* ecma-builtins.c */
void ecma_finalize_builtins (void);
ecma_global_object_t *ecma_builtin_create_global_object (void);
ecma_value_t
ecma_builtin_dispatch_call (ecma_object_t *obj_p, ecma_value_t this_arg_value,
const ecma_value_t *arguments_list_p, uint32_t arguments_list_len);
ecma_value_t
ecma_builtin_dispatch_construct (ecma_object_t *obj_p, ecma_object_t *new_target_p,
const ecma_value_t *arguments_list_p, uint32_t arguments_list_len);
ecma_builtin_dispatch_construct (ecma_object_t *obj_p, const ecma_value_t *arguments_list_p,
uint32_t arguments_list_len);
ecma_property_t *
ecma_builtin_routine_try_to_instantiate_property (ecma_object_t *object_p, ecma_string_t *string_p);
ecma_property_t *
@@ -110,7 +133,9 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p,
ecma_collection_t *prop_names_p,
ecma_property_counter_t *prop_counter_p);
bool
ecma_builtin_is (ecma_object_t *obj_p, ecma_builtin_id_t builtin_id);
ecma_builtin_is (ecma_object_t *object_p, ecma_builtin_id_t builtin_id);
bool
ecma_builtin_is_global (ecma_object_t *object_p);
ecma_object_t *
ecma_builtin_get (ecma_builtin_id_t builtin_id);
ecma_object_t *