Remove several internal property types for primitive objects. (#1399)

Class and value internal properties are always exists for primitive
types (e.g. Boolean, Regex) so they can be stored right after the
object. This improve property access (since internal properties are
searched by a slow linear algorithm) and reduces memory consumption,
since only 8 byte is allocated for these two properties instead of
16 which is the size of a property pair.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2016-10-19 15:36:15 +02:00
committed by GitHub
parent 2ef89eafbf
commit fd98d649b6
29 changed files with 487 additions and 419 deletions
@@ -100,16 +100,15 @@ ecma_builtin_boolean_prototype_object_value_of (ecma_value_t this_arg) /**< this
}
else if (ecma_is_value_object (this_arg))
{
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
if (ecma_object_get_class_name (obj_p) == LIT_MAGIC_STRING_BOOLEAN_UL)
if (ecma_object_class_is (object_p, LIT_MAGIC_STRING_BOOLEAN_UL))
{
ecma_value_t *prim_value_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_ECMA_VALUE);
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
JERRY_ASSERT (ecma_is_value_boolean (*prim_value_prop_p));
JERRY_ASSERT (ecma_is_value_boolean (ext_object_p->u.class_prop.value));
return *prim_value_prop_p;
return ext_object_p->u.class_prop.value;
}
}
@@ -94,7 +94,7 @@ ecma_builtin_date_prototype_to_date_string (ecma_value_t this_arg) /**< this arg
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
if (!ecma_is_value_object (this_arg)
|| ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != LIT_MAGIC_STRING_DATE_UL)
|| !ecma_object_class_is (ecma_get_object_from_value (this_arg), LIT_MAGIC_STRING_DATE_UL))
{
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Incompatible type"));
}
@@ -104,10 +104,10 @@ ecma_builtin_date_prototype_to_date_string (ecma_value_t this_arg) /**< this arg
ecma_op_to_object (this_arg),
ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
ecma_value_t *date_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_DATE_FLOAT);
ecma_number_t *date_num_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t, *date_prop_p);
ecma_object_t *object_p = ecma_get_object_from_value (obj_this);
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
ecma_number_t *date_num_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t,
ext_object_p->u.class_prop.value);
if (ecma_number_is_nan (*date_num_p))
{
@@ -140,7 +140,7 @@ ecma_builtin_date_prototype_to_time_string (ecma_value_t this_arg) /**< this arg
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
if (!ecma_is_value_object (this_arg)
|| ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != LIT_MAGIC_STRING_DATE_UL)
|| !ecma_object_class_is (ecma_get_object_from_value (this_arg), LIT_MAGIC_STRING_DATE_UL))
{
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Incompatible type"));
}
@@ -150,10 +150,10 @@ ecma_builtin_date_prototype_to_time_string (ecma_value_t this_arg) /**< this arg
ecma_op_to_object (this_arg),
ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
ecma_value_t *prim_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_DATE_FLOAT);
ecma_number_t *prim_value_num_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t, *prim_prop_p);
ecma_object_t *object_p = ecma_get_object_from_value (obj_this);
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
ecma_number_t *prim_value_num_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t,
ext_object_p->u.class_prop.value);
if (ecma_number_is_nan (*prim_value_num_p))
{
@@ -245,13 +245,14 @@ ecma_builtin_date_prototype_get_time (ecma_value_t this_arg) /**< this argument
{
if (ecma_is_value_object (this_arg))
{
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
if (ecma_object_get_class_name (obj_p) == LIT_MAGIC_STRING_DATE_UL)
{
ecma_value_t *date_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_DATE_FLOAT);
ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
ecma_number_t *date_num_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t, *date_prop_p);
if (ecma_object_class_is (object_p, LIT_MAGIC_STRING_DATE_UL))
{
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
ecma_number_t *date_num_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t,
ext_object_p->u.class_prop.value);
return ecma_make_number_value (*date_num_p);
}
}
@@ -341,7 +342,7 @@ ecma_builtin_date_prototype_set_time (ecma_value_t this_arg, /**< this argument
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
if (!ecma_is_value_object (this_arg)
|| ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != LIT_MAGIC_STRING_DATE_UL)
|| !ecma_object_class_is (ecma_get_object_from_value (this_arg), LIT_MAGIC_STRING_DATE_UL))
{
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Incompatible type"));
}
@@ -352,12 +353,11 @@ ecma_builtin_date_prototype_set_time (ecma_value_t this_arg, /**< this argument
ecma_number_t value = ecma_date_time_clip (t);
/* 2. */
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
ecma_number_t *date_num_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t,
ext_object_p->u.class_prop.value);
ecma_value_t *date_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_DATE_FLOAT);
ecma_number_t *date_num_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t, *date_prop_p);
*date_num_p = value;
/* 3. */
@@ -481,9 +481,12 @@ ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**<
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_DATE_PROTOTYPE);
ecma_object_t *obj_p = ecma_create_object (prototype_obj_p,
false,
true,
ECMA_OBJECT_TYPE_GENERAL);
sizeof (ecma_extended_object_t),
ECMA_OBJECT_TYPE_CLASS);
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_UNDEFINED;
ecma_deref_object (prototype_obj_p);
if (arguments_list_len == 0)
@@ -546,16 +549,11 @@ ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**<
prim_value_num = ecma_number_make_nan ();
}
ecma_value_t *class_prop_p = ecma_create_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_CLASS);
*class_prop_p = LIT_MAGIC_STRING_DATE_UL;
ecma_value_t *date_prop_p = ecma_create_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_DATE_FLOAT);
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_DATE_UL;
ecma_number_t *date_num_p = ecma_alloc_number ();
*date_num_p = prim_value_num;
ECMA_SET_INTERNAL_VALUE_POINTER (*date_prop_p, date_num_p);
ECMA_SET_INTERNAL_VALUE_POINTER (ext_object_p->u.class_prop.value, date_num_p);
ret_value = ecma_make_object_value (obj_p);
}
@@ -238,8 +238,7 @@ ecma_builtin_function_prototype_object_bind (ecma_value_t this_arg, /**< this ar
/* 4. 11. 18. */
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE);
ecma_object_t *function_p = ecma_create_object (prototype_obj_p,
false,
true,
0,
ECMA_OBJECT_TYPE_BOUND_FUNCTION);
ecma_deref_object (prototype_obj_p);
@@ -897,12 +897,10 @@ ecma_date_set_internal_property (ecma_value_t this_arg, /**< this argument */
ecma_number_t value = ecma_date_time_clip (date);
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
ecma_value_t *date_value_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_DATE_FLOAT);
*ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t, *date_value_prop_p) = value;
*ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t, ext_object_p->u.class_prop.value) = value;
return ecma_make_number_value (value);
} /* ecma_date_set_internal_property */
@@ -1292,18 +1290,17 @@ ecma_date_get_primitive_value (ecma_value_t this_arg) /**< this argument */
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
if (!ecma_is_value_object (this_arg)
|| ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != LIT_MAGIC_STRING_DATE_UL)
|| !ecma_object_class_is (ecma_get_object_from_value (this_arg), LIT_MAGIC_STRING_DATE_UL))
{
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Incompatible type"));
}
else
{
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
ecma_value_t *date_value_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_DATE_FLOAT);
JERRY_ASSERT (date_value_prop_p != NULL);
ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
ecma_number_t date_num = *ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t, *date_value_prop_p);
ecma_number_t date_num = *ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t,
ext_object_p->u.class_prop.value);
ret_value = ecma_make_number_value (date_num);
}
@@ -451,16 +451,15 @@ ecma_builtin_number_prototype_object_value_of (ecma_value_t this_arg) /**< this
}
else if (ecma_is_value_object (this_arg))
{
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
if (ecma_object_get_class_name (obj_p) == LIT_MAGIC_STRING_NUMBER_UL)
if (ecma_object_class_is (object_p, LIT_MAGIC_STRING_NUMBER_UL))
{
ecma_value_t *prim_value_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_ECMA_VALUE);
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
JERRY_ASSERT (ecma_is_value_number (*prim_value_p));
JERRY_ASSERT (ecma_is_value_number (ext_object_p->u.class_prop.value));
return ecma_copy_value (*prim_value_p);
return ecma_copy_value (ext_object_p->u.class_prop.value);
}
}
@@ -66,7 +66,7 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this argument
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
if (!ecma_is_value_object (this_arg)
|| ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != LIT_MAGIC_STRING_REGEXP_UL)
|| !ecma_object_class_is (ecma_get_object_from_value (this_arg), LIT_MAGIC_STRING_REGEXP_UL))
{
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Incomplete RegExp type"));
}
@@ -75,7 +75,7 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this argument
uint16_t flags = 0;
if (ecma_is_value_object (pattern_arg)
&& ecma_object_get_class_name (ecma_get_object_from_value (pattern_arg)) == LIT_MAGIC_STRING_REGEXP_UL)
&& ecma_object_class_is (ecma_get_object_from_value (pattern_arg), LIT_MAGIC_STRING_REGEXP_UL))
{
if (!ecma_is_value_undefined (flags_arg))
{
@@ -130,8 +130,7 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this argument
ecma_object_t *this_obj_p = ecma_get_object_from_value (obj_this);
/* Get bytecode property. */
ecma_value_t *bc_prop_p = ecma_get_internal_property (this_obj_p,
ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE);
ecma_value_t *bc_prop_p = &(((ecma_extended_object_t *) this_obj_p)->u.class_prop.value);
/* TODO: We currently have to re-compile the bytecode, because
* we can't copy it without knowing its length. */
@@ -206,8 +205,7 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this argument
ECMA_TRY_CATCH (obj_this, ecma_op_to_object (this_arg), ret_value);
ecma_object_t *this_obj_p = ecma_get_object_from_value (obj_this);
ecma_value_t *bc_prop_p = ecma_get_internal_property (this_obj_p,
ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE);
ecma_value_t *bc_prop_p = &(((ecma_extended_object_t *) this_obj_p)->u.class_prop.value);
/* Try to compile bytecode from new source. */
const re_compiled_code_t *new_bc_p = NULL;
@@ -262,7 +260,7 @@ ecma_builtin_regexp_prototype_exec (ecma_value_t this_arg, /**< this argument */
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
if (!ecma_is_value_object (this_arg)
|| ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != LIT_MAGIC_STRING_REGEXP_UL)
|| !ecma_object_class_is (ecma_get_object_from_value (this_arg), LIT_MAGIC_STRING_REGEXP_UL))
{
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Incomplete RegExp type"));
}
@@ -275,8 +273,7 @@ ecma_builtin_regexp_prototype_exec (ecma_value_t this_arg, /**< this argument */
ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
ecma_value_t *bytecode_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE);
ecma_value_t *bytecode_prop_p = &(((ecma_extended_object_t *) obj_p)->u.class_prop.value);
void *bytecode_p = ECMA_GET_INTERNAL_VALUE_POINTER (void, *bytecode_prop_p);
@@ -352,7 +349,7 @@ ecma_builtin_regexp_prototype_to_string (ecma_value_t this_arg) /**< this argume
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
if (!ecma_is_value_object (this_arg)
|| ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != LIT_MAGIC_STRING_REGEXP_UL)
|| !ecma_object_class_is (ecma_get_object_from_value (this_arg), LIT_MAGIC_STRING_REGEXP_UL))
{
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Incomplete RegExp type"));
}
@@ -81,7 +81,7 @@ ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /*
}
if (ecma_is_value_object (pattern_value)
&& ecma_object_get_class_name (ecma_get_object_from_value (pattern_value)) == LIT_MAGIC_STRING_REGEXP_UL)
&& ecma_object_class_is (ecma_get_object_from_value (pattern_value), LIT_MAGIC_STRING_REGEXP_UL))
{
if (ecma_is_value_undefined (flags_value))
{
@@ -72,14 +72,15 @@ ecma_builtin_string_prototype_object_to_string (ecma_value_t this_arg) /**< this
}
else if (ecma_is_value_object (this_arg))
{
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
if (ecma_object_get_class_name (obj_p) == LIT_MAGIC_STRING_STRING_UL)
if (ecma_object_class_is (object_p, LIT_MAGIC_STRING_STRING_UL))
{
ecma_value_t *prim_value_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_ECMA_VALUE);
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
return ecma_copy_value (*prim_value_p);
JERRY_ASSERT (ecma_is_value_string (ext_object_p->u.class_prop.value));
return ecma_copy_value (ext_object_p->u.class_prop.value);
}
}
@@ -408,7 +409,7 @@ ecma_builtin_string_prototype_object_match (ecma_value_t this_arg, /**< this arg
ecma_value_t regexp_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
/* 3. */
if (ecma_is_value_object (arg)
&& ecma_object_get_class_name (ecma_get_object_from_value (arg)) == LIT_MAGIC_STRING_REGEXP_UL)
&& ecma_object_class_is (ecma_get_object_from_value (arg), LIT_MAGIC_STRING_REGEXP_UL))
{
regexp_value = ecma_copy_value (arg);
}
@@ -1245,7 +1246,7 @@ ecma_builtin_string_prototype_object_replace (ecma_value_t this_arg, /**< this a
ecma_builtin_replace_search_ctx_t context;
if (ecma_is_value_object (search_value)
&& ecma_object_get_class_name (ecma_get_object_from_value (search_value)) == LIT_MAGIC_STRING_REGEXP_UL)
&& ecma_object_class_is (ecma_get_object_from_value (search_value), LIT_MAGIC_STRING_REGEXP_UL))
{
ecma_object_t *regexp_obj_p = ecma_get_object_from_value (search_value);
ecma_string_t *global_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_GLOBAL);
@@ -1337,7 +1338,7 @@ ecma_builtin_string_prototype_object_search (ecma_value_t this_arg, /**< this ar
/* 3. */
if (ecma_is_value_object (regexp_arg)
&& ecma_object_get_class_name (ecma_get_object_from_value (regexp_arg)) == LIT_MAGIC_STRING_REGEXP_UL)
&& ecma_object_class_is (ecma_get_object_from_value (regexp_arg), LIT_MAGIC_STRING_REGEXP_UL))
{
regexp_value = ecma_copy_value (regexp_arg);
}
@@ -1500,7 +1501,7 @@ ecma_builtin_helper_split_match (ecma_value_t input_string, /**< first argument
/* 1. */
if (ecma_is_value_object (separator)
&& ecma_object_get_class_name (ecma_get_object_from_value (separator)) == LIT_MAGIC_STRING_REGEXP_UL)
&& ecma_object_class_is (ecma_get_object_from_value (separator), LIT_MAGIC_STRING_REGEXP_UL))
{
ecma_value_t regexp_value = ecma_copy_value_if_not_object (separator);
@@ -1687,7 +1688,7 @@ ecma_builtin_string_prototype_object_split (ecma_value_t this_arg, /**< this arg
ecma_value_t separator = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
if (ecma_is_value_object (arg1)
&& ecma_object_get_class_name (ecma_get_object_from_value (arg1)) == LIT_MAGIC_STRING_REGEXP_UL)
&& ecma_object_class_is (ecma_get_object_from_value (arg1), LIT_MAGIC_STRING_REGEXP_UL))
{
separator = ecma_copy_value (arg1);
}
+82 -36
View File
@@ -104,7 +104,15 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
ecma_object_type_t obj_type, /**< object's type */
bool is_extensible) /**< value of object's [[Extensible]] property */
{
ecma_object_t *obj_p = ecma_create_object (prototype_obj_p, true, is_extensible, obj_type);
size_t ext_object_size = (obj_type == ECMA_OBJECT_TYPE_CLASS ? sizeof (ecma_extended_built_in_object_t)
: sizeof (ecma_extended_object_t));
ecma_object_t *obj_p = ecma_create_object (prototype_obj_p, ext_object_size, obj_type);
if (!is_extensible)
{
ecma_set_object_extensible (obj_p, false);
}
/*
* [[Class]] property of built-in object is not stored explicitly.
@@ -113,11 +121,20 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
*/
ecma_set_object_is_builtin (obj_p);
ecma_built_in_props_t *built_in_props_p;
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p;
ext_obj_p->u.built_in.id = obj_builtin_id;
ext_obj_p->u.built_in.routine_id = obj_builtin_id;
ext_obj_p->u.built_in.instantiated_bitset = 0;
if (obj_type == ECMA_OBJECT_TYPE_CLASS)
{
built_in_props_p = &((ecma_extended_built_in_object_t *) obj_p)->built_in;
}
else
{
built_in_props_p = &((ecma_extended_object_t *) obj_p)->u.built_in;
}
built_in_props_p->id = obj_builtin_id;
built_in_props_p->routine_id = obj_builtin_id;
built_in_props_p->instantiated_bitset = 0;
/** Initializing [[PrimitiveValue]] properties of built-in prototype objects */
switch (obj_builtin_id)
@@ -125,6 +142,7 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
#ifndef CONFIG_DISABLE_ARRAY_BUILTIN
case ECMA_BUILTIN_ID_ARRAY_PROTOTYPE:
{
JERRY_ASSERT (obj_type != ECMA_OBJECT_TYPE_CLASS);
ecma_string_t *length_str_p = ecma_new_ecma_length_string ();
ecma_property_value_t *length_prop_value_p;
@@ -143,11 +161,12 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
#ifndef CONFIG_DISABLE_STRING_BUILTIN
case ECMA_BUILTIN_ID_STRING_PROTOTYPE:
{
ecma_string_t *prim_prop_str_value_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
JERRY_ASSERT (obj_type == ECMA_OBJECT_TYPE_CLASS);
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
ecma_value_t *prim_value_p = ecma_create_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_ECMA_VALUE);
*prim_value_p = ecma_make_string_value (prim_prop_str_value_p);
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_STRING_UL;
ecma_string_t *prim_prop_str_value_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
ext_object_p->u.class_prop.value = ecma_make_string_value (prim_prop_str_value_p);
break;
}
#endif /* !CONFIG_DISABLE_STRING_BUILTIN */
@@ -155,9 +174,11 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
#ifndef CONFIG_DISABLE_NUMBER_BUILTIN
case ECMA_BUILTIN_ID_NUMBER_PROTOTYPE:
{
ecma_value_t *prim_value_p = ecma_create_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_ECMA_VALUE);
*prim_value_p = ecma_make_integer_value (0);
JERRY_ASSERT (obj_type == ECMA_OBJECT_TYPE_CLASS);
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_NUMBER_UL;
ext_object_p->u.class_prop.value = ecma_make_integer_value (0);
break;
}
#endif /* !CONFIG_DISABLE_NUMBER_BUILTIN */
@@ -165,9 +186,11 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
#ifndef CONFIG_DISABLE_BOOLEAN_BUILTIN
case ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE:
{
ecma_value_t *prim_value_p = ecma_create_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_ECMA_VALUE);
*prim_value_p = ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE);
JERRY_ASSERT (obj_type == ECMA_OBJECT_TYPE_CLASS);
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_BOOLEAN_UL;
ext_object_p->u.class_prop.value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE);
break;
}
#endif /* !CONFIG_DISABLE_BOOLEAN_BUILTIN */
@@ -175,12 +198,14 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
#ifndef CONFIG_DISABLE_DATE_BUILTIN
case ECMA_BUILTIN_ID_DATE_PROTOTYPE:
{
JERRY_ASSERT (obj_type == ECMA_OBJECT_TYPE_CLASS);
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_DATE_UL;
ecma_number_t *prim_prop_num_value_p = ecma_alloc_number ();
*prim_prop_num_value_p = ecma_number_make_nan ();
ecma_value_t *prim_value_p = ecma_create_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_DATE_FLOAT);
ECMA_SET_INTERNAL_VALUE_POINTER (*prim_value_p, prim_prop_num_value_p);
ECMA_SET_INTERNAL_VALUE_POINTER (ext_object_p->u.class_prop.value, prim_prop_num_value_p);
break;
}
#endif /* !CONFIG_DISABLE_DATE_BUILTIN */
@@ -188,14 +213,17 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
#ifndef CONFIG_DISABLE_REGEXP_BUILTIN
case ECMA_BUILTIN_ID_REGEXP_PROTOTYPE:
{
ecma_value_t *bytecode_prop_p = ecma_create_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE);
*bytecode_prop_p = ECMA_NULL_POINTER;
JERRY_ASSERT (obj_type == ECMA_OBJECT_TYPE_CLASS);
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_REGEXP_UL;
ext_object_p->u.class_prop.value = ECMA_NULL_POINTER;
break;
}
#endif /* !CONFIG_DISABLE_REGEXP_BUILTIN */
default:
{
JERRY_ASSERT (obj_type != ECMA_OBJECT_TYPE_CLASS);
break;
}
}
@@ -288,7 +316,9 @@ ecma_builtin_make_function_object_for_routine (ecma_builtin_id_t builtin_id, /**
{
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE);
ecma_object_t *func_obj_p = ecma_create_object (prototype_obj_p, true, true, ECMA_OBJECT_TYPE_FUNCTION);
ecma_object_t *func_obj_p = ecma_create_object (prototype_obj_p,
sizeof (ecma_extended_object_t),
ECMA_OBJECT_TYPE_FUNCTION);
ecma_deref_object (prototype_obj_p);
@@ -333,8 +363,6 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
{
JERRY_ASSERT (ecma_get_object_is_builtin (object_p));
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p;
if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION
&& ecma_builtin_function_is_routine (object_p))
{
@@ -354,6 +382,7 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
ECMA_PROPERTY_FIXED,
&len_prop_p);
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p;
len_prop_value_p->value = ecma_make_integer_value (ext_obj_p->u.built_in.length);
return len_prop_p;
@@ -369,7 +398,18 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
return NULL;
}
ecma_builtin_id_t builtin_id = (ecma_builtin_id_t) ext_obj_p->u.built_in.id;
ecma_built_in_props_t *built_in_props_p;
if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_CLASS)
{
built_in_props_p = &((ecma_extended_built_in_object_t *) object_p)->built_in;
}
else
{
built_in_props_p = &((ecma_extended_object_t *) object_p)->u.built_in;
}
ecma_builtin_id_t builtin_id = (ecma_builtin_id_t) built_in_props_p->id;
JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT);
JERRY_ASSERT (ecma_builtin_is (object_p, builtin_id));
@@ -395,13 +435,13 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
{
uint32_t bit_for_index = (uint32_t) 1u << index;
if (ext_obj_p->u.built_in.instantiated_bitset & bit_for_index)
if (built_in_props_p->instantiated_bitset & bit_for_index)
{
/* This property was instantiated before. */
return NULL;
}
ext_obj_p->u.built_in.instantiated_bitset |= bit_for_index;
built_in_props_p->instantiated_bitset |= bit_for_index;
}
else
{
@@ -558,8 +598,6 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in
{
JERRY_ASSERT (ecma_get_object_is_builtin (object_p));
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p;
if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION
&& ecma_builtin_function_is_routine (object_p))
{
@@ -575,7 +613,18 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in
}
else
{
ecma_builtin_id_t builtin_id = (ecma_builtin_id_t) ext_obj_p->u.built_in.id;
ecma_built_in_props_t *built_in_props_p;
if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_CLASS)
{
built_in_props_p = &((ecma_extended_built_in_object_t *) object_p)->built_in;
}
else
{
built_in_props_p = &((ecma_extended_object_t *) object_p)->u.built_in;
}
ecma_builtin_id_t builtin_id = (ecma_builtin_id_t) built_in_props_p->id;
JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT);
JERRY_ASSERT (ecma_builtin_is (object_p, builtin_id));
@@ -583,7 +632,7 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in
const ecma_builtin_property_descriptor_t *curr_property_p = ecma_builtin_property_list_references[builtin_id];
ecma_length_t index = 0;
uint32_t instantiated_bitset = ext_obj_p->u.built_in.instantiated_bitset;
uint32_t instantiated_bitset = built_in_props_p->instantiated_bitset;
ecma_collection_header_t *for_non_enumerable_p = (separate_enumerable ? non_enum_collection_p
: main_collection_p);
@@ -698,6 +747,7 @@ ecma_builtin_dispatch_call (ecma_object_t *obj_p, /**< built-in object */
const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< arguments list length */
{
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION);
JERRY_ASSERT (ecma_get_object_is_builtin (obj_p));
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
@@ -713,8 +763,6 @@ ecma_builtin_dispatch_call (ecma_object_t *obj_p, /**< built-in object */
}
else
{
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION);
switch ((ecma_builtin_id_t) ext_obj_p->u.built_in.id)
{
#define BUILTIN(builtin_id, \
@@ -768,8 +816,6 @@ ecma_builtin_dispatch_construct (ecma_object_t *obj_p, /**< built-in object */
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p;
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION);
switch (ext_obj_p->u.built_in.id)
{
#define BUILTIN(builtin_id, \
@@ -53,7 +53,7 @@ BUILTIN (ECMA_BUILTIN_ID_ARRAY,
#ifndef CONFIG_DISABLE_STRING_BUILTIN
/* The String.prototype object (15.5.4) */
BUILTIN (ECMA_BUILTIN_ID_STRING_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_OBJECT_TYPE_CLASS,
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
true,
true,
@@ -71,7 +71,7 @@ BUILTIN (ECMA_BUILTIN_ID_STRING,
#ifndef CONFIG_DISABLE_BOOLEAN_BUILTIN
/* The Boolean.prototype object (15.6.4) */
BUILTIN (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_OBJECT_TYPE_CLASS,
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
true,
true,
@@ -89,7 +89,7 @@ BUILTIN (ECMA_BUILTIN_ID_BOOLEAN,
#ifndef CONFIG_DISABLE_NUMBER_BUILTIN
/* The Number.prototype object (15.7.4) */
BUILTIN (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_OBJECT_TYPE_CLASS,
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
true,
true,
@@ -143,7 +143,7 @@ BUILTIN (ECMA_BUILTIN_ID_JSON,
#ifndef CONFIG_DISABLE_DATE_BUILTIN
/* The Date.prototype object (15.9.4) */
BUILTIN (ECMA_BUILTIN_ID_DATE_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_OBJECT_TYPE_CLASS,
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
true,
true,
@@ -161,7 +161,7 @@ BUILTIN (ECMA_BUILTIN_ID_DATE,
#ifndef CONFIG_DISABLE_REGEXP_BUILTIN
/* The RegExp.prototype object (15.10.6) */
BUILTIN (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_OBJECT_TYPE_CLASS,
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
true,
true,