Add fast path to ecma_op_object_get with magic string. (#2078)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2017-12-05 17:17:56 +01:00
committed by Dániel Bátyai
parent a8dffe023e
commit e964393abe
19 changed files with 133 additions and 208 deletions
@@ -274,10 +274,8 @@ ecma_op_function_has_instance (ecma_object_t *func_obj_p, /**< Function object *
ecma_object_t *v_obj_p = ecma_get_object_from_value (value);
ecma_string_t prototype_magic_string;
ecma_init_ecma_magic_string (&prototype_magic_string, LIT_MAGIC_STRING_PROTOTYPE);
ecma_value_t prototype_obj_value = ecma_op_object_get (func_obj_p, &prototype_magic_string);
ecma_value_t prototype_obj_value = ecma_op_object_get_by_magic_id (func_obj_p,
LIT_MAGIC_STRING_PROTOTYPE);
if (ECMA_IS_VALUE_ERROR (prototype_obj_value))
{
@@ -558,12 +556,10 @@ ecma_op_function_construct_simple_or_external (ecma_object_t *func_obj_p, /**< F
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
ecma_string_t *prototype_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_PROTOTYPE);
/* 5. */
ECMA_TRY_CATCH (func_obj_prototype_prop_value,
ecma_op_object_get (func_obj_p,
prototype_magic_string_p),
ecma_op_object_get_by_magic_id (func_obj_p,
LIT_MAGIC_STRING_PROTOTYPE),
ret_value);
/* 1., 2., 4. */
@@ -620,8 +616,6 @@ ecma_op_function_construct_simple_or_external (ecma_object_t *func_obj_p, /**< F
ECMA_FINALIZE (func_obj_prototype_prop_value);
ecma_deref_ecma_string (prototype_magic_string_p);
return ret_value;
} /* ecma_op_function_construct_simple_or_external */
@@ -214,34 +214,30 @@ ecma_op_general_object_default_value (ecma_object_t *obj_p, /**< the object */
for (uint32_t i = 1; i <= 2; i++)
{
lit_magic_string_id_t function_name_magic_string_id;
lit_magic_string_id_t function_name_id;
if ((i == 1 && hint == ECMA_PREFERRED_TYPE_STRING)
|| (i == 2 && hint == ECMA_PREFERRED_TYPE_NUMBER))
{
function_name_magic_string_id = LIT_MAGIC_STRING_TO_STRING_UL;
function_name_id = LIT_MAGIC_STRING_TO_STRING_UL;
}
else
{
function_name_magic_string_id = LIT_MAGIC_STRING_VALUE_OF_UL;
function_name_id = LIT_MAGIC_STRING_VALUE_OF_UL;
}
ecma_string_t *function_name_p = ecma_get_magic_string (function_name_magic_string_id);
ecma_value_t function_value = ecma_op_object_get_by_magic_id (obj_p, function_name_id);
ecma_value_t function_value_get_completion = ecma_op_object_get (obj_p, function_name_p);
ecma_deref_ecma_string (function_name_p);
if (ECMA_IS_VALUE_ERROR (function_value_get_completion))
if (ECMA_IS_VALUE_ERROR (function_value))
{
return function_value_get_completion;
return function_value;
}
ecma_value_t call_completion = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
if (ecma_op_is_callable (function_value_get_completion))
if (ecma_op_is_callable (function_value))
{
ecma_object_t *func_obj_p = ecma_get_object_from_value (function_value_get_completion);
ecma_object_t *func_obj_p = ecma_get_object_from_value (function_value);
call_completion = ecma_op_function_call (func_obj_p,
ecma_make_object_value (obj_p),
@@ -249,7 +245,7 @@ ecma_op_general_object_default_value (ecma_object_t *obj_p, /**< the object */
0);
}
ecma_free_value (function_value_get_completion);
ecma_free_value (function_value);
if (ECMA_IS_VALUE_ERROR (call_completion)
|| (!ecma_is_value_empty (call_completion)
+52 -1
View File
@@ -666,7 +666,12 @@ ecma_op_object_get_own_data_prop (ecma_object_t *object_p, /**< the object */
} /* ecma_op_object_get_own_data_prop */
/**
* [[Get]] ecma object's operation
* [[Get]] operation of ecma object
*
* This function returns the value of a named property, or undefined
* if the property is not found in the prototype chain. If the property
* is an accessor, it calls the "get" callback function and returns
* with its result (including error throws).
*
* See also:
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
@@ -703,6 +708,52 @@ ecma_op_object_get (ecma_object_t *object_p, /**< the object */
return ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
} /* ecma_op_object_get */
/**
* [[Get]] operation of ecma object where the property name is a magic string
*
* This function returns the value of a named property, or undefined
* if the property is not found in the prototype chain. If the property
* is an accessor, it calls the "get" callback function and returns
* with its result (including error throws).
*
* See also:
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
*
* @return ecma value
* Returned value must be freed with ecma_free_value
*/
ecma_value_t
ecma_op_object_get_by_magic_id (ecma_object_t *object_p, /**< the object */
lit_magic_string_id_t property_id) /**< property magic string id */
{
/* Circular reference is possible in JavaScript and testing it is complicated. */
int max_depth = ECMA_PROPERTY_SEARCH_DEPTH_LIMIT;
ecma_string_t property_name;
ecma_init_ecma_magic_string (&property_name, property_id);
ecma_value_t base_value = ecma_make_object_value (object_p);
do
{
ecma_value_t value = ecma_op_object_find_own (base_value, object_p, &property_name);
if (ecma_is_value_found (value))
{
return value;
}
if (--max_depth == 0)
{
break;
}
object_p = ecma_get_object_prototype (object_p);
}
while (object_p != NULL);
return ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
} /* ecma_op_object_get_by_magic_id */
/**
* [[Put]] ecma general object's operation
*
@@ -36,6 +36,7 @@ ecma_value_t ecma_op_object_find_own (ecma_value_t base_value, ecma_object_t *ob
ecma_value_t ecma_op_object_find (ecma_object_t *object_p, ecma_string_t *property_name_p);
ecma_value_t ecma_op_object_get_own_data_prop (ecma_object_t *object_p, ecma_string_t *property_name_p);
ecma_value_t ecma_op_object_get (ecma_object_t *object_p, ecma_string_t *property_name_p);
ecma_value_t ecma_op_object_get_by_magic_id (ecma_object_t *object_p, lit_magic_string_id_t property_id);
ecma_value_t ecma_op_object_put (ecma_object_t *object_p, ecma_string_t *property_name_p, ecma_value_t value,
bool is_throw);
ecma_value_t ecma_op_object_delete (ecma_object_t *obj_p, ecma_string_t *property_name_p, bool is_throw);
@@ -311,8 +311,8 @@ ecma_promise_resolve_handler (const ecma_value_t function, /**< the function its
}
/* 8. */
ecma_string_t *str_then = ecma_new_ecma_string_from_magic_string_id (LIT_MAGIC_STRING_THEN);
ecma_value_t then = ecma_op_object_get (ecma_get_object_from_value (argv[0]), str_then);
ecma_value_t then = ecma_op_object_get_by_magic_id (ecma_get_object_from_value (argv[0]),
LIT_MAGIC_STRING_THEN);
if (ECMA_IS_VALUE_ERROR (then))
{
@@ -331,7 +331,6 @@ ecma_promise_resolve_handler (const ecma_value_t function, /**< the function its
ecma_enqueue_promise_resolve_thenable_job (promise, argv[0], then);
}
ecma_deref_ecma_string (str_then);
ecma_free_value (then);
end_of_resolve_function:
@@ -398,11 +398,8 @@ ecma_op_typedarray_from (ecma_value_t items_val, /**< the source array-like obje
ecma_object_t *arraylike_object_p = ecma_get_object_from_value (arraylike_object_val);
/* 12 */
ecma_string_t magic_string_length;
ecma_init_ecma_length_string (&magic_string_length);
ECMA_TRY_CATCH (len_value,
ecma_op_object_get (arraylike_object_p, &magic_string_length),
ecma_op_object_get_by_magic_id (arraylike_object_p, LIT_MAGIC_STRING_LENGTH),
ret_value);
ECMA_OP_TO_NUMBER_TRY_CATCH (len_number, len_value, ret_value);