Eliminate ECMA_TRY_CATCH macros part I. (#3006)
Also this patch introduces several helper function to find/put/delete properties by indexed property names to reduce code duplications. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
committed by
Dániel Bátyai
parent
3af0079a0e
commit
b47c36ad18
@@ -1250,6 +1250,14 @@ typedef enum
|
||||
#define ECMA_CREATE_DIRECT_STRING(type, value) \
|
||||
((uintptr_t) (ECMA_TYPE_DIRECT_STRING | ((type) << ECMA_VALUE_SHIFT) | (value) << ECMA_DIRECT_STRING_SHIFT))
|
||||
|
||||
/**
|
||||
* Create an ecma direct string from the given number.
|
||||
*
|
||||
* Note: the given number must be less or equal than ECMA_DIRECT_STRING_MAX_IMM
|
||||
*/
|
||||
#define ECMA_CREATE_DIRECT_UINT32_STRING(uint32_number) \
|
||||
((ecma_string_t *) ECMA_CREATE_DIRECT_STRING (ECMA_DIRECT_STRING_UINT, (uintptr_t) uint32_number))
|
||||
|
||||
/**
|
||||
* Checks whether the string is direct.
|
||||
*/
|
||||
|
||||
@@ -517,6 +517,27 @@ ecma_new_ecma_string_from_code_units (ecma_char_t first_code_unit, /**< code uni
|
||||
} /* ecma_new_ecma_string_from_code_units */
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
|
||||
|
||||
/**
|
||||
* Allocate new ecma-string and fill it with ecma-number
|
||||
*
|
||||
* Note: the number cannot be represented as direct string
|
||||
*
|
||||
* @return pointer to ecma-string descriptor
|
||||
*/
|
||||
ecma_string_t *
|
||||
ecma_new_non_direct_string_from_uint32 (uint32_t uint32_number) /**< uint32 value of the string */
|
||||
{
|
||||
JERRY_ASSERT (uint32_number > ECMA_DIRECT_STRING_MAX_IMM);
|
||||
|
||||
ecma_string_t *string_p = ecma_alloc_string ();
|
||||
|
||||
string_p->refs_and_container = ECMA_STRING_CONTAINER_UINT32_IN_DESC | ECMA_STRING_REF_ONE;
|
||||
string_p->hash = (lit_string_hash_t) uint32_number;
|
||||
string_p->u.uint32_number = uint32_number;
|
||||
|
||||
return string_p;
|
||||
} /* ecma_new_non_direct_string_from_uint32 */
|
||||
|
||||
/**
|
||||
* Allocate new ecma-string and fill it with ecma-number
|
||||
*
|
||||
@@ -530,13 +551,7 @@ ecma_new_ecma_string_from_uint32 (uint32_t uint32_number) /**< uint32 value of t
|
||||
return (ecma_string_t *) ECMA_CREATE_DIRECT_STRING (ECMA_DIRECT_STRING_UINT, (uintptr_t) uint32_number);
|
||||
}
|
||||
|
||||
ecma_string_t *string_p = ecma_alloc_string ();
|
||||
|
||||
string_p->refs_and_container = ECMA_STRING_CONTAINER_UINT32_IN_DESC | ECMA_STRING_REF_ONE;
|
||||
string_p->hash = (lit_string_hash_t) uint32_number;
|
||||
string_p->u.uint32_number = uint32_number;
|
||||
|
||||
return string_p;
|
||||
return ecma_new_non_direct_string_from_uint32 (uint32_number);
|
||||
} /* ecma_new_ecma_string_from_uint32 */
|
||||
|
||||
/**
|
||||
|
||||
@@ -234,6 +234,7 @@ ecma_string_t *ecma_new_ecma_string_from_code_unit (ecma_char_t code_unit);
|
||||
ecma_string_t *ecma_new_ecma_string_from_code_units (ecma_char_t first_code_unit, ecma_char_t second_code_unit);
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
|
||||
ecma_string_t *ecma_new_ecma_string_from_uint32 (uint32_t uint32_number);
|
||||
ecma_string_t *ecma_new_non_direct_string_from_uint32 (uint32_t uint32_number);
|
||||
ecma_string_t *ecma_get_ecma_string_from_uint32 (uint32_t uint32_number);
|
||||
ecma_string_t *ecma_new_ecma_string_from_number (ecma_number_t num);
|
||||
ecma_string_t *ecma_get_magic_string (lit_magic_string_id_t id);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -472,11 +472,6 @@ ecma_builtin_helper_array_concat_value (ecma_object_t *obj_p, /**< array */
|
||||
ecma_deref_ecma_string (new_array_index_string_p);
|
||||
}
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ret_value = ECMA_VALUE_TRUE;
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_helper_array_concat_value */
|
||||
|
||||
@@ -795,6 +790,41 @@ ecma_builtin_helper_string_find_index (ecma_string_t *original_str_p, /**< index
|
||||
return match_found;
|
||||
} /* ecma_builtin_helper_string_find_index */
|
||||
|
||||
/**
|
||||
* Helper function for using [[DefineOwnProperty]] specialized for indexed property names
|
||||
*
|
||||
* Note: this method falls back to the general ecma_builtin_helper_def_prop
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_def_prop_by_index (ecma_object_t *obj_p, /**< object */
|
||||
uint32_t index, /**< property index */
|
||||
ecma_value_t value, /**< value */
|
||||
uint32_t opts, /**< any combination of ecma_property_flag_t bits */
|
||||
bool is_throw) /**< is_throw */
|
||||
{
|
||||
if (JERRY_LIKELY (index <= ECMA_DIRECT_STRING_MAX_IMM))
|
||||
{
|
||||
return ecma_builtin_helper_def_prop (obj_p,
|
||||
ECMA_CREATE_DIRECT_UINT32_STRING (index),
|
||||
value,
|
||||
opts,
|
||||
is_throw);
|
||||
}
|
||||
|
||||
ecma_string_t *index_str_p = ecma_new_non_direct_string_from_uint32 (index);
|
||||
ecma_value_t ret_value = ecma_builtin_helper_def_prop (obj_p,
|
||||
index_str_p,
|
||||
value,
|
||||
opts,
|
||||
is_throw);
|
||||
ecma_deref_ecma_string (index_str_p);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_helper_def_prop_by_index */
|
||||
|
||||
/**
|
||||
* Helper function for using [[DefineOwnProperty]].
|
||||
*
|
||||
|
||||
@@ -60,6 +60,9 @@ ecma_builtin_helper_string_find_index (ecma_string_t *original_str_p, ecma_strin
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_def_prop (ecma_object_t *obj_p, ecma_string_t *index_p, ecma_value_t value,
|
||||
uint32_t opts, bool is_throw);
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_def_prop_by_index (ecma_object_t *obj_p, uint32_t index, ecma_value_t value,
|
||||
uint32_t opts, bool is_throw);
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_DATE)
|
||||
|
||||
|
||||
@@ -602,6 +602,51 @@ ecma_op_object_find_own (ecma_value_t base_value, /**< base value */
|
||||
return ecma_op_function_call (getter_p, base_value, NULL, 0);
|
||||
} /* ecma_op_object_find_own */
|
||||
|
||||
/**
|
||||
* Search the value corresponding to an uint32_t property index
|
||||
*
|
||||
* Note: this method falls back to the general ecma_op_object_find
|
||||
*
|
||||
* @return ecma value if property is found
|
||||
* ECMA_VALUE_NOT_FOUND if property is not found
|
||||
* Returned value must be freed with ecma_free_value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_object_find_by_uint32_index (ecma_object_t *object_p, /**< the object */
|
||||
uint32_t index) /**< property index */
|
||||
{
|
||||
if (JERRY_LIKELY (index <= ECMA_DIRECT_STRING_MAX_IMM))
|
||||
{
|
||||
return ecma_op_object_find (object_p, ECMA_CREATE_DIRECT_UINT32_STRING (index));
|
||||
}
|
||||
|
||||
ecma_string_t *index_str_p = ecma_new_non_direct_string_from_uint32 (index);
|
||||
ecma_value_t ret_value = ecma_op_object_find (object_p, index_str_p);
|
||||
ecma_deref_ecma_string (index_str_p);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_op_object_find_by_uint32_index */
|
||||
|
||||
/**
|
||||
* Search the value corresponding to an ecma_number_t property index
|
||||
*
|
||||
* Note: this method falls back to the general ecma_op_object_find
|
||||
*
|
||||
* @return ecma value if property is found
|
||||
* ECMA_VALUE_NOT_FOUND if property is not found
|
||||
* Returned value must be freed with ecma_free_value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_object_find_by_number_index (ecma_object_t *object_p, /**< the object */
|
||||
ecma_number_t index) /**< property index */
|
||||
{
|
||||
ecma_string_t *index_str_p = ecma_new_ecma_string_from_number (index);
|
||||
ecma_value_t ret_value = ecma_op_object_find (object_p, index_str_p);
|
||||
ecma_deref_ecma_string (index_str_p);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_op_object_find_by_number_index */
|
||||
|
||||
/**
|
||||
* Search the value corresponding to a property name
|
||||
*
|
||||
@@ -808,6 +853,56 @@ ecma_op_get_method_by_symbol_id (ecma_value_t value, /**< ecma value */
|
||||
} /* ecma_op_get_method_by_symbol_id */
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
||||
|
||||
/**
|
||||
* [[Put]] ecma general object's operation specialized for uint32_ property index
|
||||
*
|
||||
* Note: This function falls back to the general ecma_op_object_put
|
||||
*
|
||||
* @return ecma value
|
||||
* The returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_object_put_by_uint32_index (ecma_object_t *object_p, /**< the object */
|
||||
uint32_t index, /**< property index */
|
||||
ecma_value_t value, /**< ecma value */
|
||||
bool is_throw) /**< flag that controls failure handling */
|
||||
{
|
||||
if (JERRY_LIKELY (index <= ECMA_DIRECT_STRING_MAX_IMM))
|
||||
{
|
||||
return ecma_op_object_put (object_p,
|
||||
ECMA_CREATE_DIRECT_UINT32_STRING (index),
|
||||
value,
|
||||
is_throw);
|
||||
}
|
||||
|
||||
ecma_string_t *index_str_p = ecma_new_non_direct_string_from_uint32 (index);
|
||||
ecma_value_t ret_value = ecma_op_object_put (object_p, index_str_p, value, is_throw);
|
||||
ecma_deref_ecma_string (index_str_p);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_op_object_put_by_uint32_index */
|
||||
|
||||
/**
|
||||
* [[Put]] ecma general object's operation specialized for ecma_number_ property index
|
||||
*
|
||||
* Note: This function falls back to the general ecma_op_object_put
|
||||
*
|
||||
* @return ecma value
|
||||
* The returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_object_put_by_number_index (ecma_object_t *object_p, /**< the object */
|
||||
ecma_number_t index, /**< property index */
|
||||
ecma_value_t value, /**< ecma value */
|
||||
bool is_throw) /**< flag that controls failure handling */
|
||||
{
|
||||
ecma_string_t *index_str_p = ecma_new_ecma_string_from_number (index);
|
||||
ecma_value_t ret_value = ecma_op_object_put (object_p, index_str_p, value, is_throw);
|
||||
ecma_deref_ecma_string (index_str_p);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_op_object_put_by_number_index */
|
||||
|
||||
/**
|
||||
* [[Put]] ecma general object's operation
|
||||
*
|
||||
@@ -1097,6 +1192,53 @@ ecma_op_object_put (ecma_object_t *object_p, /**< the object */
|
||||
return ret_value;
|
||||
} /* ecma_op_object_put */
|
||||
|
||||
/**
|
||||
* [[Delete]] ecma object's operation specialized for uint32_t property index
|
||||
*
|
||||
* Note:
|
||||
* This method falls back to the general ecma_op_object_delete
|
||||
*
|
||||
* @return true - if deleted successfully
|
||||
* false - or type error otherwise (based in 'is_throw')
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_object_delete_by_uint32_index (ecma_object_t *obj_p, /**< the object */
|
||||
uint32_t index, /**< property index */
|
||||
bool is_throw) /**< flag that controls failure handling */
|
||||
{
|
||||
if (JERRY_LIKELY (index <= ECMA_DIRECT_STRING_MAX_IMM))
|
||||
{
|
||||
return ecma_op_object_delete (obj_p, ECMA_CREATE_DIRECT_UINT32_STRING (index), is_throw);
|
||||
}
|
||||
|
||||
ecma_string_t *index_str_p = ecma_new_non_direct_string_from_uint32 (index);
|
||||
ecma_value_t ret_value = ecma_op_object_delete (obj_p, index_str_p, is_throw);
|
||||
ecma_deref_ecma_string (index_str_p);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_op_object_delete_by_uint32_index */
|
||||
|
||||
/**
|
||||
* [[Delete]] ecma object's operation specialized for ecma_number_t property index
|
||||
*
|
||||
* Note:
|
||||
* This method falls back to the general ecma_op_object_delete
|
||||
*
|
||||
* @return true - if deleted successfully
|
||||
* false - or type error otherwise (based in 'is_throw')
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_object_delete_by_number_index (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_number_t index, /**< property index */
|
||||
bool is_throw) /**< flag that controls failure handling */
|
||||
{
|
||||
ecma_string_t *index_str_p = ecma_new_ecma_string_from_number (index);
|
||||
ecma_value_t ret_value = ecma_op_object_delete (obj_p, index_str_p, is_throw);
|
||||
ecma_deref_ecma_string (index_str_p);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_op_object_delete_by_number_index */
|
||||
|
||||
/**
|
||||
* [[Delete]] ecma object's operation
|
||||
*
|
||||
|
||||
@@ -32,6 +32,8 @@ bool ecma_op_object_has_own_property (ecma_object_t *object_p, ecma_string_t *pr
|
||||
bool ecma_op_object_has_property (ecma_object_t *object_p, ecma_string_t *property_name_p);
|
||||
ecma_value_t ecma_op_object_find_own (ecma_value_t base_value, ecma_object_t *object_p, ecma_string_t *property_name_p);
|
||||
ecma_value_t ecma_op_object_find (ecma_object_t *object_p, ecma_string_t *property_name_p);
|
||||
ecma_value_t ecma_op_object_find_by_uint32_index (ecma_object_t *object_p, uint32_t index);
|
||||
ecma_value_t ecma_op_object_find_by_number_index (ecma_object_t *object_p, ecma_number_t index);
|
||||
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);
|
||||
@@ -41,7 +43,13 @@ ecma_value_t ecma_op_get_method_by_symbol_id (ecma_value_t value, lit_magic_stri
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SYMBOL) */
|
||||
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_put_by_uint32_index (ecma_object_t *object_p, uint32_t index,
|
||||
ecma_value_t value, bool is_throw);
|
||||
ecma_value_t ecma_op_object_put_by_number_index (ecma_object_t *object_p, ecma_number_t index,
|
||||
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);
|
||||
ecma_value_t ecma_op_object_delete_by_uint32_index (ecma_object_t *obj_p, uint32_t index, bool is_throw);
|
||||
ecma_value_t ecma_op_object_delete_by_number_index (ecma_object_t *obj_p, ecma_number_t index, bool is_throw);
|
||||
ecma_value_t ecma_op_object_default_value (ecma_object_t *obj_p, ecma_preferred_type_hint_t hint);
|
||||
ecma_value_t ecma_op_object_define_own_property (ecma_object_t *obj_p, ecma_string_t *property_name_p,
|
||||
const ecma_property_descriptor_t *property_desc_p, bool is_throw);
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ OPTIONS_COMMON = ['--lto=off']
|
||||
OPTIONS_PROFILE_MIN = ['--profile=minimal']
|
||||
OPTIONS_PROFILE_ES51 = [] # NOTE: same as ['--profile=es5.1']
|
||||
OPTIONS_PROFILE_ES2015 = ['--profile=es2015-subset']
|
||||
OPTIONS_STACK_LIMIT = ['--stack-limit=128']
|
||||
OPTIONS_STACK_LIMIT = ['--stack-limit=96']
|
||||
OPTIONS_DEBUG = ['--debug']
|
||||
OPTIONS_SNAPSHOT = ['--snapshot-save=on', '--snapshot-exec=on', '--jerry-cmdline-snapshot=on']
|
||||
OPTIONS_UNITTESTS = ['--unittests=on', '--jerry-cmdline=off', '--error-messages=on',
|
||||
|
||||
Reference in New Issue
Block a user