Common built-in object's constructor.

This commit is contained in:
Ruben Ayrapetyan 2014-09-23 15:29:08 +04:00
parent fd7f153747
commit ae244f0148
4 changed files with 61 additions and 86 deletions

View File

@ -37,10 +37,6 @@
/**
* List of the Global object's built-in property names
*
* Warning:
* values in the array should be sorted in ascending order
* that is checked in the ecma_builtin_init_global_object.
*/
static const ecma_magic_string_id_t ecma_builtin_global_property_names[] =
{
@ -78,44 +74,10 @@ static const ecma_magic_string_id_t ecma_builtin_global_property_names[] =
/**
* Number of the Global object's built-in properties
*/
static const ecma_length_t ecma_builtin_global_property_number = (sizeof (ecma_builtin_global_property_names) /
sizeof (ecma_magic_string_id_t));
const ecma_length_t ecma_builtin_global_property_number = (sizeof (ecma_builtin_global_property_names) /
sizeof (ecma_magic_string_id_t));
JERRY_STATIC_ASSERT (sizeof (ecma_builtin_global_property_names) > sizeof (void*));
/**
* Initialize Global object.
*
* Warning:
* the routine should be called only from ecma_init_builtins
*
* @return pointer to the object
*/
ecma_object_t*
ecma_builtin_init_global_object (void)
{
ecma_object_t *glob_obj_p = ecma_create_object (NULL, true, ECMA_OBJECT_TYPE_GENERAL);
ecma_property_t *class_prop_p = ecma_create_internal_property (glob_obj_p,
ECMA_INTERNAL_PROPERTY_CLASS);
class_prop_p->u.internal_property.value = ECMA_OBJECT_CLASS_OBJECT;
ecma_property_t *built_in_id_prop_p = ecma_create_internal_property (glob_obj_p,
ECMA_INTERNAL_PROPERTY_BUILT_IN_ID);
built_in_id_prop_p->u.internal_property.value = ECMA_BUILTIN_ID_GLOBAL;
ecma_property_t *mask_0_31_prop_p;
mask_0_31_prop_p = ecma_create_internal_property (glob_obj_p,
ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31);
JERRY_STATIC_ASSERT (ecma_builtin_global_property_number < sizeof (uint32_t) * JERRY_BITSINBYTE);
uint32_t builtin_mask = ((uint32_t)1u << ecma_builtin_global_property_number) - 1;
mask_0_31_prop_p->u.internal_property.value = builtin_mask;
ecma_set_object_is_builtin (glob_obj_p, true);
return glob_obj_p;
} /* ecma_builtin_init_global_object */
/**
* The Global object's 'eval' routine
*

View File

@ -40,10 +40,6 @@
/**
* List of the Object object's built-in property names
*
* Warning:
* values in the array should be sorted in ascending order
* that is checked in the ecma_builtin_init_global_object.
*/
static const ecma_magic_string_id_t ecma_builtin_object_property_names[] =
{
@ -67,44 +63,10 @@ static const ecma_magic_string_id_t ecma_builtin_object_property_names[] =
/**
* Number of the Object object's built-in properties
*/
static const ecma_length_t ecma_builtin_object_property_number = (sizeof (ecma_builtin_object_property_names) /
sizeof (ecma_magic_string_id_t));
const ecma_length_t ecma_builtin_object_property_number = (sizeof (ecma_builtin_object_property_names) /
sizeof (ecma_magic_string_id_t));
JERRY_STATIC_ASSERT (sizeof (ecma_builtin_object_property_names) > sizeof (void*));
/**
* Initialize Object object.
*
* Warning:
* the routine should be called only from ecma_init_builtins
*
* @return pointer to the object
*/
ecma_object_t*
ecma_builtin_init_object_object (void)
{
ecma_object_t *object_obj_p = ecma_create_object (NULL, true, ECMA_OBJECT_TYPE_FUNCTION);
ecma_property_t *class_prop_p = ecma_create_internal_property (object_obj_p,
ECMA_INTERNAL_PROPERTY_CLASS);
class_prop_p->u.internal_property.value = ECMA_OBJECT_CLASS_OBJECT;
ecma_property_t *built_in_id_prop_p = ecma_create_internal_property (object_obj_p,
ECMA_INTERNAL_PROPERTY_BUILT_IN_ID);
built_in_id_prop_p->u.internal_property.value = ECMA_BUILTIN_ID_OBJECT;
ecma_property_t *mask_0_31_prop_p;
mask_0_31_prop_p = ecma_create_internal_property (object_obj_p,
ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31);
JERRY_STATIC_ASSERT (ecma_builtin_object_property_number < sizeof (uint32_t) * JERRY_BITSINBYTE);
uint32_t builtin_mask = ((uint32_t) 1u << ecma_builtin_object_property_number) - 1;
mask_0_31_prop_p->u.internal_property.value = builtin_mask;
ecma_set_object_is_builtin (object_obj_p, true);
return object_obj_p;
} /* ecma_builtin_init_object_object */
/**
* Get number of routine's parameters
*

View File

@ -51,8 +51,6 @@ ecma_builtin_make_function_object_for_routine (ecma_builtin_id_t builtin_id,
ecma_magic_string_id_t routine_id);
/* ecma-builtin-global-object.c */
extern ecma_object_t* ecma_builtin_init_global_object (void);
extern ecma_length_t
ecma_builtin_global_get_routine_parameters_number (ecma_magic_string_id_t routine_id);
extern ecma_completion_value_t
@ -63,9 +61,9 @@ extern ecma_property_t*
ecma_builtin_global_try_to_instantiate_property (ecma_object_t *obj_p,
ecma_string_t *prop_name_p);
/* ecma-builtin-object-object.c */
extern ecma_object_t* ecma_builtin_init_object_object (void);
extern const ecma_length_t ecma_builtin_global_property_number;
/* ecma-builtin-object-object.c */
extern ecma_length_t
ecma_builtin_object_get_routine_parameters_number (ecma_magic_string_id_t routine_id);
extern ecma_completion_value_t
@ -82,6 +80,8 @@ extern ecma_completion_value_t
ecma_builtin_object_dispatch_construct (ecma_value_t *arguments_list_p,
ecma_length_t arguments_list_len);
extern const ecma_length_t ecma_builtin_object_property_number;
extern void ecma_builtin_init_object_prototype_object (void);
extern void ecma_builtin_finalize_object_prototype_object (void);
extern ecma_property_t*

View File

@ -75,6 +75,51 @@ ecma_builtin_get (ecma_builtin_id_t builtin_id) /**< id of built-in to check on
return ecma_builtin_objects [builtin_id];
} /* ecma_builtin_get */
/**
* Initialize specified built-in object.
*
* Warning:
* the routine should be called only from ecma_init_builtins
*
* @return pointer to the object
*/
static ecma_object_t*
ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
ecma_object_type_t obj_type, /**< object's type */
ecma_object_class_t obj_class, /**< object's class */
ecma_length_t property_number) /**< number of the object's properties */
{
ecma_object_t *object_obj_p = ecma_create_object (NULL, true, obj_type);
ecma_property_t *class_prop_p = ecma_create_internal_property (object_obj_p,
ECMA_INTERNAL_PROPERTY_CLASS);
class_prop_p->u.internal_property.value = obj_class;
ecma_property_t *built_in_id_prop_p = ecma_create_internal_property (object_obj_p,
ECMA_INTERNAL_PROPERTY_BUILT_IN_ID);
built_in_id_prop_p->u.internal_property.value = obj_builtin_id;
JERRY_STATIC_ASSERT (property_number < sizeof (uint64_t) * JERRY_BITSINBYTE);
uint64_t builtin_mask = ((uint32_t) 1u << property_number) - 1;
ecma_property_t *mask_0_31_prop_p;
mask_0_31_prop_p = ecma_create_internal_property (object_obj_p,
ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31);
mask_0_31_prop_p->u.internal_property.value = (uint32_t) builtin_mask;
if (jrt_extract_bit_field (builtin_mask, 32, 32) != 0)
{
ecma_property_t *mask_32_63_prop_p;
mask_32_63_prop_p = ecma_create_internal_property (object_obj_p,
ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63);
mask_32_63_prop_p->u.internal_property.value = (uint32_t) jrt_extract_bit_field (builtin_mask, 32, 32);
}
ecma_set_object_is_builtin (object_obj_p, true);
return object_obj_p;
} /* ecma_builtin_init_object */
/**
* Initialize ECMA built-in objects
*/
@ -88,9 +133,15 @@ ecma_init_builtins (void)
ecma_builtin_objects [id] = NULL;
}
ecma_builtin_objects [ECMA_BUILTIN_ID_OBJECT] = ecma_builtin_init_object_object ();
ecma_builtin_objects [ECMA_BUILTIN_ID_OBJECT] = ecma_builtin_init_object (ECMA_BUILTIN_ID_OBJECT,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_OBJECT_CLASS_OBJECT,
ecma_builtin_object_property_number);
ecma_builtin_objects [ECMA_BUILTIN_ID_GLOBAL] = ecma_builtin_init_global_object ();
ecma_builtin_objects [ECMA_BUILTIN_ID_GLOBAL] = ecma_builtin_init_object (ECMA_BUILTIN_ID_GLOBAL,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_OBJECT_CLASS_OBJECT,
ecma_builtin_global_property_number);
} /* ecma_init_builtins */
/**