Cleanup toNumber and toNumeric abstract operations (#4034)
JerryScript-DCO-1.0-Signed-off-by: Virag Orkenyi orkvi@inf.u-szeged.hu
This commit is contained in:
@@ -1077,7 +1077,7 @@ ecma_builtin_array_prototype_object_sort_compare_helper (ecma_value_t lhs, /**<
|
||||
{
|
||||
ecma_number_t ret_num;
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_op_to_numeric (call_value, &ret_num, ECMA_TO_NUMERIC_NO_OPTS)))
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_op_to_number (call_value, &ret_num)))
|
||||
{
|
||||
ecma_free_value (call_value);
|
||||
return ECMA_VALUE_ERROR;
|
||||
|
||||
@@ -396,15 +396,12 @@ ecma_builtin_date_prototype_dispatch_set (uint16_t builtin_routine_id, /**< buil
|
||||
|
||||
for (uint32_t i = 0; i < conversions; i++)
|
||||
{
|
||||
ecma_value_t value = ecma_op_to_number (arguments_list[i], ECMA_TO_NUMERIC_NO_OPTS);
|
||||
ecma_value_t value = ecma_op_to_number (arguments_list[i], &converted_number[i]);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
converted_number[i] = ecma_get_number_from_value (value);
|
||||
ecma_free_value (value);
|
||||
}
|
||||
|
||||
ecma_number_t day_part;
|
||||
|
||||
@@ -213,7 +213,7 @@ ecma_date_construct_helper (const ecma_value_t *args, /**< arguments passed to t
|
||||
/* 1-7. */
|
||||
for (uint32_t i = 0; i < args_len; i++)
|
||||
{
|
||||
ecma_value_t status = ecma_op_to_numeric (args[i], date_nums + i, ECMA_TO_NUMERIC_NO_OPTS);
|
||||
ecma_value_t status = ecma_op_to_number (args[i], date_nums + i);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (status))
|
||||
{
|
||||
@@ -776,7 +776,8 @@ ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**<
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_value_t prim_value = ecma_op_to_number (argument, ECMA_TO_NUMERIC_NO_OPTS);
|
||||
ecma_number_t arg;
|
||||
ecma_value_t prim_value = ecma_op_to_number (argument, &arg);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (prim_value))
|
||||
{
|
||||
@@ -785,9 +786,8 @@ ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**<
|
||||
return prim_value;
|
||||
}
|
||||
|
||||
prim_value_num = ecma_date_time_clip (ecma_get_number_from_value (prim_value));
|
||||
prim_value_num = ecma_date_time_clip (arg);
|
||||
|
||||
ecma_free_value (prim_value);
|
||||
}
|
||||
|
||||
ecma_free_value (prim_comp_value);
|
||||
|
||||
@@ -612,7 +612,7 @@ ecma_builtin_global_dispatch_routine (uint16_t builtin_routine_id, /**< built-in
|
||||
{
|
||||
ecma_number_t arg_num;
|
||||
|
||||
routine_arg_1 = ecma_op_to_numeric (routine_arg_1, &arg_num, ECMA_TO_NUMERIC_NO_OPTS);
|
||||
routine_arg_1 = ecma_op_to_number (routine_arg_1, &arg_num);
|
||||
|
||||
if (!ecma_is_value_empty (routine_arg_1))
|
||||
{
|
||||
|
||||
@@ -539,7 +539,7 @@ ecma_builtin_helper_string_prototype_object_index_of (ecma_string_t *original_st
|
||||
else
|
||||
{
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
ret_value = ecma_op_to_numeric (arg2, &pos_num, ECMA_TO_NUMERIC_NO_OPTS);
|
||||
ret_value = ecma_op_to_number (arg2, &pos_num);
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
@@ -1313,13 +1313,16 @@ ecma_builtin_json_serialize_property (ecma_json_stringify_context_t *context_p,
|
||||
/* 5.a */
|
||||
if (class_name == LIT_MAGIC_STRING_NUMBER_UL)
|
||||
{
|
||||
value = ecma_op_to_number (value, ECMA_TO_NUMERIC_NO_OPTS);
|
||||
ecma_number_t num;
|
||||
value = ecma_op_to_number (value, &num);
|
||||
ecma_deref_object (obj_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
value = ecma_make_number_value (num);
|
||||
}
|
||||
/* 5.b */
|
||||
else if (class_name == LIT_MAGIC_STRING_STRING_UL)
|
||||
@@ -1642,7 +1645,8 @@ ecma_builtin_json_stringify (ecma_value_t this_arg, /**< 'this' argument */
|
||||
/* 5.a */
|
||||
if (class_name == LIT_MAGIC_STRING_NUMBER_UL)
|
||||
{
|
||||
ecma_value_t value = ecma_op_to_number (arg3, ECMA_TO_NUMERIC_NO_OPTS);
|
||||
ecma_number_t num;
|
||||
ecma_value_t value = ecma_op_to_number (arg3, &num);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (value))
|
||||
{
|
||||
@@ -1652,8 +1656,7 @@ ecma_builtin_json_stringify (ecma_value_t this_arg, /**< 'this' argument */
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
space = value;
|
||||
space = ecma_make_number_value (num);
|
||||
}
|
||||
/* 5.b */
|
||||
else if (class_name == LIT_MAGIC_STRING_STRING_UL)
|
||||
|
||||
@@ -135,16 +135,12 @@ ecma_builtin_math_object_max_min (bool is_max, /**< 'max' or 'min' operation */
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_value_t value = ecma_op_to_number (*arg, ECMA_TO_NUMERIC_NO_OPTS);
|
||||
ecma_value_t value = ecma_op_to_number (*arg, &arg_num);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
arg_num = ecma_get_number_from_value (value);
|
||||
|
||||
ecma_fast_free_value (value);
|
||||
}
|
||||
|
||||
arg++;
|
||||
@@ -215,13 +211,11 @@ ecma_builtin_math_object_hypot (const ecma_value_t *arg, /**< arguments list */
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_value_t value = ecma_op_to_number (*arg, ECMA_TO_NUMERIC_NO_OPTS);
|
||||
ecma_value_t value = ecma_op_to_number (*arg, &arg_num);
|
||||
if (ECMA_IS_VALUE_ERROR (value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
arg_num = ecma_get_number_from_value (value);
|
||||
ecma_fast_free_value (value);
|
||||
}
|
||||
|
||||
arg++;
|
||||
@@ -357,16 +351,12 @@ ecma_builtin_math_dispatch_routine (uint16_t builtin_routine_id, /**< built-in w
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_value_t value = ecma_op_to_number (arguments_list[0], ECMA_TO_NUMERIC_NO_OPTS);
|
||||
ecma_value_t value = ecma_op_to_number (arguments_list[0], &x);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
x = ecma_get_number_from_value (value);
|
||||
|
||||
ecma_fast_free_value (value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,16 +369,12 @@ ecma_builtin_math_dispatch_routine (uint16_t builtin_routine_id, /**< built-in w
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_value_t value = ecma_op_to_number (arguments_list[1], ECMA_TO_NUMERIC_NO_OPTS);
|
||||
ecma_value_t value = ecma_op_to_number (arguments_list[1], &y);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
y = ecma_get_number_from_value (value);
|
||||
|
||||
ecma_fast_free_value (value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,13 @@ ecma_builtin_number_dispatch_call (const ecma_value_t *arguments_list_p, /**< ar
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_op_to_number (arguments_list_p[0], ECMA_TO_NUMERIC_ALLOW_BIGINT);
|
||||
ecma_number_t num;
|
||||
ret_value = ecma_op_to_numeric (arguments_list_p[0], &num, ECMA_TO_NUMERIC_ALLOW_BIGINT);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (ret_value))
|
||||
{
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_BIGINT)
|
||||
if (ecma_is_value_bigint (ret_value))
|
||||
@@ -94,7 +100,11 @@ ecma_builtin_number_dispatch_call (const ecma_value_t *arguments_list_p, /**< ar
|
||||
ret_value = ecma_bigint_to_number (bigint);
|
||||
ecma_free_value (bigint);
|
||||
}
|
||||
else
|
||||
#endif /* ENABLED (JERRY_BUILTIN_BIGINT) */
|
||||
{
|
||||
ret_value = ecma_make_number_value (num);
|
||||
}
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
@@ -117,7 +127,13 @@ ecma_builtin_number_dispatch_construct (const ecma_value_t *arguments_list_p, /*
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_BIGINT)
|
||||
ecma_value_t value = ecma_op_to_number (arguments_list_p[0], ECMA_TO_NUMERIC_ALLOW_BIGINT);
|
||||
ecma_number_t num;
|
||||
ecma_value_t value = ecma_op_to_numeric (arguments_list_p[0], &num, ECMA_TO_NUMERIC_ALLOW_BIGINT);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
if (ecma_is_value_bigint (value))
|
||||
{
|
||||
@@ -125,10 +141,9 @@ ecma_builtin_number_dispatch_construct (const ecma_value_t *arguments_list_p, /*
|
||||
value = ecma_bigint_to_number (bigint);
|
||||
ecma_free_value (bigint);
|
||||
}
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (value))
|
||||
else
|
||||
{
|
||||
return value;
|
||||
value = ecma_make_number_value (num);
|
||||
}
|
||||
|
||||
ecma_value_t result = ecma_op_create_number_object (value);
|
||||
|
||||
@@ -784,7 +784,7 @@ ecma_builtin_string_prototype_object_split (ecma_value_t this_value, /**< this a
|
||||
{
|
||||
/* ECMA-262 v11, 21.1.3.20 6 */
|
||||
ecma_number_t num;
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_op_to_numeric (limit_value, &num, ECMA_TO_NUMERIC_NO_OPTS)))
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_op_to_number (limit_value, &num)))
|
||||
{
|
||||
goto cleanup_string;
|
||||
}
|
||||
|
||||
@@ -291,7 +291,8 @@ ecma_builtin_string_object_from_code_point (ecma_value_t this_arg, /**< 'this' a
|
||||
|
||||
for (uint32_t index = 0; index < args_number; index++)
|
||||
{
|
||||
ecma_value_t to_number_value = ecma_op_to_number (args[index], ECMA_TO_NUMERIC_NO_OPTS);
|
||||
ecma_number_t to_number_num;
|
||||
ecma_value_t to_number_value = ecma_op_to_number (args[index], &to_number_num);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (to_number_value))
|
||||
{
|
||||
@@ -299,25 +300,21 @@ ecma_builtin_string_object_from_code_point (ecma_value_t this_arg, /**< 'this' a
|
||||
return to_number_value;
|
||||
}
|
||||
|
||||
ecma_number_t to_number_num = ecma_get_number_from_value (to_number_value);
|
||||
ecma_free_value (to_number_value);
|
||||
|
||||
ecma_number_t to_int_num;
|
||||
ecma_value_t to_int_value = ecma_op_to_integer (to_number_value, &to_int_num);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (to_int_value))
|
||||
if (!ecma_op_is_integer (to_number_num))
|
||||
{
|
||||
ecma_stringbuilder_destroy (&builder);
|
||||
return to_int_value;
|
||||
return ecma_raise_range_error ("Error: Invalid code point");
|
||||
}
|
||||
|
||||
if (to_number_num != to_int_num || to_int_num < 0 || to_int_num > LIT_UNICODE_CODE_POINT_MAX)
|
||||
ecma_free_value (to_number_value);
|
||||
|
||||
if (to_number_num < 0 || to_number_num > LIT_UNICODE_CODE_POINT_MAX)
|
||||
{
|
||||
ecma_stringbuilder_destroy (&builder);
|
||||
return ecma_raise_range_error (ECMA_ERR_MSG ("Error: Invalid code point"));
|
||||
}
|
||||
|
||||
lit_code_point_t code_point = (lit_code_point_t) to_int_num;
|
||||
lit_code_point_t code_point = (lit_code_point_t) to_number_num;
|
||||
|
||||
ecma_char_t converted_cp[2];
|
||||
uint8_t encoded_size = lit_utf16_encode_code_point (code_point, converted_cp);
|
||||
|
||||
@@ -1086,7 +1086,7 @@ ecma_builtin_typedarray_prototype_join (ecma_value_t this_arg, /**< this argumen
|
||||
|
||||
ecma_number_t length_number;
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_op_to_numeric (length_value, &length_number, ECMA_TO_NUMERIC_NO_OPTS)))
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_op_to_number (length_value, &length_number)))
|
||||
{
|
||||
ecma_free_value (length_value);
|
||||
ecma_free_value (obj_value);
|
||||
@@ -1408,7 +1408,7 @@ ecma_builtin_typedarray_prototype_sort_compare_helper (ecma_value_t lhs, /**< le
|
||||
}
|
||||
|
||||
ecma_number_t ret_num;
|
||||
ecma_value_t number_result = ecma_op_to_numeric (call_value, &ret_num, ECMA_TO_NUMERIC_NO_OPTS);
|
||||
ecma_value_t number_result = ecma_op_to_number (call_value, &ret_num);
|
||||
|
||||
ecma_free_value (call_value);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user