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:
@@ -1301,7 +1301,15 @@ jerry_value_to_number (const jerry_value_t value) /**< input value */
|
|||||||
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (error_value_msg_p)));
|
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (error_value_msg_p)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return jerry_return (ecma_op_to_number (value, ECMA_TO_NUMERIC_NO_OPTS));
|
ecma_number_t num;
|
||||||
|
ecma_value_t ret_value = ecma_op_to_number (value, &num);
|
||||||
|
|
||||||
|
if (ECMA_IS_VALUE_ERROR (ret_value))
|
||||||
|
{
|
||||||
|
return ecma_create_error_reference_from_context ();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ecma_make_number_value (num);
|
||||||
} /* jerry_value_to_number */
|
} /* jerry_value_to_number */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -763,11 +763,11 @@ ecma_number_parse_int (const lit_utf8_byte_t *string_buff, /**< routine's first
|
|||||||
|
|
||||||
/* 6. */
|
/* 6. */
|
||||||
ecma_number_t radix_num;
|
ecma_number_t radix_num;
|
||||||
radix = ecma_op_to_numeric (radix, &radix_num, ECMA_TO_NUMERIC_NO_OPTS);
|
radix = ecma_op_to_number (radix, &radix_num);
|
||||||
|
|
||||||
if (!ecma_is_value_empty (radix))
|
if (ECMA_IS_VALUE_ERROR (radix))
|
||||||
{
|
{
|
||||||
return radix;
|
return ECMA_VALUE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t rad = ecma_number_to_int32 (radix_num);
|
int32_t rad = ecma_number_to_int32 (radix_num);
|
||||||
|
|||||||
@@ -1077,7 +1077,7 @@ ecma_builtin_array_prototype_object_sort_compare_helper (ecma_value_t lhs, /**<
|
|||||||
{
|
{
|
||||||
ecma_number_t ret_num;
|
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);
|
ecma_free_value (call_value);
|
||||||
return ECMA_VALUE_ERROR;
|
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++)
|
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))
|
if (ECMA_IS_VALUE_ERROR (value))
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
converted_number[i] = ecma_get_number_from_value (value);
|
|
||||||
ecma_free_value (value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_number_t day_part;
|
ecma_number_t day_part;
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ ecma_date_construct_helper (const ecma_value_t *args, /**< arguments passed to t
|
|||||||
/* 1-7. */
|
/* 1-7. */
|
||||||
for (uint32_t i = 0; i < args_len; i++)
|
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))
|
if (ECMA_IS_VALUE_ERROR (status))
|
||||||
{
|
{
|
||||||
@@ -776,7 +776,8 @@ ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**<
|
|||||||
}
|
}
|
||||||
else
|
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))
|
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;
|
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);
|
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;
|
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))
|
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
|
else
|
||||||
{
|
{
|
||||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
#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)
|
#if ENABLED (JERRY_ESNEXT)
|
||||||
}
|
}
|
||||||
#endif /* 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 */
|
/* 5.a */
|
||||||
if (class_name == LIT_MAGIC_STRING_NUMBER_UL)
|
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);
|
ecma_deref_object (obj_p);
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (value))
|
if (ECMA_IS_VALUE_ERROR (value))
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value = ecma_make_number_value (num);
|
||||||
}
|
}
|
||||||
/* 5.b */
|
/* 5.b */
|
||||||
else if (class_name == LIT_MAGIC_STRING_STRING_UL)
|
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 */
|
/* 5.a */
|
||||||
if (class_name == LIT_MAGIC_STRING_NUMBER_UL)
|
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))
|
if (ECMA_IS_VALUE_ERROR (value))
|
||||||
{
|
{
|
||||||
@@ -1652,8 +1656,7 @@ ecma_builtin_json_stringify (ecma_value_t this_arg, /**< 'this' argument */
|
|||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
space = ecma_make_number_value (num);
|
||||||
space = value;
|
|
||||||
}
|
}
|
||||||
/* 5.b */
|
/* 5.b */
|
||||||
else if (class_name == LIT_MAGIC_STRING_STRING_UL)
|
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
|
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))
|
if (ECMA_IS_VALUE_ERROR (value))
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
arg_num = ecma_get_number_from_value (value);
|
|
||||||
|
|
||||||
ecma_fast_free_value (value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
arg++;
|
arg++;
|
||||||
@@ -215,13 +211,11 @@ ecma_builtin_math_object_hypot (const ecma_value_t *arg, /**< arguments list */
|
|||||||
}
|
}
|
||||||
else
|
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))
|
if (ECMA_IS_VALUE_ERROR (value))
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
arg_num = ecma_get_number_from_value (value);
|
|
||||||
ecma_fast_free_value (value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
arg++;
|
arg++;
|
||||||
@@ -357,16 +351,12 @@ ecma_builtin_math_dispatch_routine (uint16_t builtin_routine_id, /**< built-in w
|
|||||||
}
|
}
|
||||||
else
|
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))
|
if (ECMA_IS_VALUE_ERROR (value))
|
||||||
{
|
{
|
||||||
return 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
|
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))
|
if (ECMA_IS_VALUE_ERROR (value))
|
||||||
{
|
{
|
||||||
return 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
|
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 ENABLED (JERRY_BUILTIN_BIGINT)
|
||||||
if (ecma_is_value_bigint (ret_value))
|
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);
|
ret_value = ecma_bigint_to_number (bigint);
|
||||||
ecma_free_value (bigint);
|
ecma_free_value (bigint);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
#endif /* ENABLED (JERRY_BUILTIN_BIGINT) */
|
#endif /* ENABLED (JERRY_BUILTIN_BIGINT) */
|
||||||
|
{
|
||||||
|
ret_value = ecma_make_number_value (num);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret_value;
|
return ret_value;
|
||||||
@@ -117,7 +127,13 @@ ecma_builtin_number_dispatch_construct (const ecma_value_t *arguments_list_p, /*
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLED (JERRY_BUILTIN_BIGINT)
|
#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))
|
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);
|
value = ecma_bigint_to_number (bigint);
|
||||||
ecma_free_value (bigint);
|
ecma_free_value (bigint);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (ECMA_IS_VALUE_ERROR (value))
|
|
||||||
{
|
{
|
||||||
return value;
|
value = ecma_make_number_value (num);
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_value_t result = ecma_op_create_number_object (value);
|
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-262 v11, 21.1.3.20 6 */
|
||||||
ecma_number_t num;
|
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;
|
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++)
|
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))
|
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;
|
return to_number_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_number_t to_number_num = ecma_get_number_from_value (to_number_value);
|
if (!ecma_op_is_integer (to_number_num))
|
||||||
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))
|
|
||||||
{
|
{
|
||||||
ecma_stringbuilder_destroy (&builder);
|
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);
|
ecma_stringbuilder_destroy (&builder);
|
||||||
return ecma_raise_range_error (ECMA_ERR_MSG ("Error: Invalid code point"));
|
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];
|
ecma_char_t converted_cp[2];
|
||||||
uint8_t encoded_size = lit_utf16_encode_code_point (code_point, converted_cp);
|
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;
|
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 (length_value);
|
||||||
ecma_free_value (obj_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_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);
|
ecma_free_value (call_value);
|
||||||
|
|
||||||
|
|||||||
@@ -924,32 +924,24 @@ ecma_op_array_object_set_length (ecma_object_t *object_p, /**< the array object
|
|||||||
uint32_t flags) /**< configuration options */
|
uint32_t flags) /**< configuration options */
|
||||||
{
|
{
|
||||||
bool is_throw = (flags & ECMA_ARRAY_OBJECT_SET_LENGTH_FLAG_IS_THROW);
|
bool is_throw = (flags & ECMA_ARRAY_OBJECT_SET_LENGTH_FLAG_IS_THROW);
|
||||||
|
ecma_number_t new_len_num;
|
||||||
ecma_value_t completion = ecma_op_to_number (new_value, ECMA_TO_NUMERIC_NO_OPTS);
|
ecma_value_t completion = ecma_op_to_number (new_value, &new_len_num);
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (completion))
|
if (ECMA_IS_VALUE_ERROR (completion))
|
||||||
{
|
{
|
||||||
return completion;
|
return completion;
|
||||||
}
|
}
|
||||||
|
|
||||||
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (completion)
|
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (completion));
|
||||||
&& ecma_is_value_number (completion));
|
|
||||||
|
|
||||||
ecma_number_t new_len_num = ecma_get_number_from_value (completion);
|
|
||||||
|
|
||||||
ecma_free_value (completion);
|
|
||||||
|
|
||||||
if (ecma_is_value_object (new_value))
|
if (ecma_is_value_object (new_value))
|
||||||
{
|
{
|
||||||
ecma_value_t compared_num_val = ecma_op_to_number (new_value, ECMA_TO_NUMERIC_NO_OPTS);
|
ecma_value_t compared_num_val = ecma_op_to_number (new_value, &new_len_num);
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (compared_num_val))
|
if (ECMA_IS_VALUE_ERROR (compared_num_val))
|
||||||
{
|
{
|
||||||
return compared_num_val;
|
return compared_num_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_len_num = ecma_get_number_from_value (compared_num_val);
|
|
||||||
ecma_free_value (compared_num_val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t new_len_uint32 = ecma_number_to_uint32 (new_len_num);
|
uint32_t new_len_uint32 = ecma_number_to_uint32 (new_len_num);
|
||||||
|
|||||||
@@ -119,16 +119,12 @@ ecma_op_create_arraybuffer_object (const ecma_value_t *arguments_list_p, /**< li
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ecma_value_t to_number_value = ecma_op_to_number (arguments_list_p[0], ECMA_TO_NUMERIC_NO_OPTS);
|
ecma_value_t to_number_value = ecma_op_to_number (arguments_list_p[0], &length_num);
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (to_number_value))
|
if (ECMA_IS_VALUE_ERROR (to_number_value))
|
||||||
{
|
{
|
||||||
return to_number_value;
|
return to_number_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
length_num = ecma_get_number_from_value (to_number_value);
|
|
||||||
|
|
||||||
ecma_free_value (to_number_value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ecma_number_is_nan (length_num))
|
if (ecma_number_is_nan (length_num))
|
||||||
|
|||||||
@@ -113,16 +113,17 @@ ecma_op_abstract_equality_compare (ecma_value_t x, /**< first operand */
|
|||||||
if (ecma_is_value_number (y))
|
if (ecma_is_value_number (y))
|
||||||
{
|
{
|
||||||
/* 4. */
|
/* 4. */
|
||||||
ecma_value_t x_num_value = ecma_op_to_number (x, ECMA_TO_NUMERIC_NO_OPTS);
|
ecma_number_t num;
|
||||||
|
ecma_value_t x_num_value = ecma_op_to_number (x, &num);
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (x_num_value))
|
if (ECMA_IS_VALUE_ERROR (x_num_value))
|
||||||
{
|
{
|
||||||
return x_num_value;
|
return x_num_value;
|
||||||
}
|
}
|
||||||
|
ecma_value_t num_value = ecma_make_number_value (num);
|
||||||
|
ecma_value_t compare_result = ecma_op_abstract_equality_compare (num_value, y);
|
||||||
|
|
||||||
ecma_value_t compare_result = ecma_op_abstract_equality_compare (x_num_value, y);
|
ecma_free_value (num_value);
|
||||||
|
|
||||||
ecma_free_value (x_num_value);
|
|
||||||
return compare_result;
|
return compare_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -276,79 +276,11 @@ ecma_op_to_boolean (ecma_value_t value) /**< ecma value */
|
|||||||
* @return ecma value
|
* @return ecma value
|
||||||
* Returned value must be freed with ecma_free_value
|
* Returned value must be freed with ecma_free_value
|
||||||
*/
|
*/
|
||||||
ecma_value_t
|
inline ecma_value_t JERRY_ATTR_ALWAYS_INLINE
|
||||||
ecma_op_to_number (ecma_value_t value, /**< ecma value */
|
ecma_op_to_number (ecma_value_t value, /**< ecma value */
|
||||||
ecma_to_numeric_options_t options) /**< option bits */
|
ecma_number_t *number_p) /**< [out] ecma number */
|
||||||
{
|
{
|
||||||
JERRY_UNUSED (options);
|
return ecma_op_to_numeric (value, number_p, ECMA_TO_NUMERIC_NO_OPTS);
|
||||||
|
|
||||||
ecma_check_value_type_is_spec_defined (value);
|
|
||||||
|
|
||||||
if (ecma_is_value_integer_number (value))
|
|
||||||
{
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ecma_is_value_float_number (value))
|
|
||||||
{
|
|
||||||
return ecma_copy_value (value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ecma_is_value_string (value))
|
|
||||||
{
|
|
||||||
ecma_string_t *str_p = ecma_get_string_from_value (value);
|
|
||||||
return ecma_make_number_value (ecma_string_to_number (str_p));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ecma_is_value_undefined (value))
|
|
||||||
{
|
|
||||||
return ecma_make_nan_value ();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ecma_is_value_null (value))
|
|
||||||
{
|
|
||||||
return ecma_make_integer_value (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ecma_is_value_boolean (value))
|
|
||||||
{
|
|
||||||
return ecma_make_integer_value (ecma_is_value_true (value) ? 1 : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if ENABLED (JERRY_ESNEXT)
|
|
||||||
if (ecma_is_value_symbol (value))
|
|
||||||
{
|
|
||||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Cannot convert a Symbol value to a number"));
|
|
||||||
}
|
|
||||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
|
||||||
|
|
||||||
#if ENABLED (JERRY_BUILTIN_BIGINT)
|
|
||||||
if (ecma_is_value_bigint (value))
|
|
||||||
{
|
|
||||||
if (options & ECMA_TO_NUMERIC_ALLOW_BIGINT)
|
|
||||||
{
|
|
||||||
return ecma_copy_value (value);
|
|
||||||
}
|
|
||||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Cannot convert a BigInt value to a number"));
|
|
||||||
}
|
|
||||||
#endif /* ENABLED (JERRY_BUILTIN_BIGINT) */
|
|
||||||
|
|
||||||
JERRY_ASSERT (ecma_is_value_object (value));
|
|
||||||
|
|
||||||
ecma_object_t *obj_p = ecma_get_object_from_value (value);
|
|
||||||
|
|
||||||
ecma_value_t def_value = ecma_op_object_default_value (obj_p, ECMA_PREFERRED_TYPE_NUMBER);
|
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (def_value))
|
|
||||||
{
|
|
||||||
return def_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
ecma_value_t ret_value = ecma_op_to_number (def_value, options);
|
|
||||||
|
|
||||||
ecma_fast_free_value (def_value);
|
|
||||||
|
|
||||||
return ret_value;
|
|
||||||
} /* ecma_op_to_number */
|
} /* ecma_op_to_number */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -944,6 +876,30 @@ free_desc:
|
|||||||
return ret_value;
|
return ret_value;
|
||||||
} /* ecma_op_to_property_descriptor */
|
} /* ecma_op_to_property_descriptor */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IsInteger operation.
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* ECMA-262 v5, 9.4
|
||||||
|
* ECMA-262 v6, 7.1.4
|
||||||
|
*
|
||||||
|
* @return true - if the argument is integer
|
||||||
|
* false - otherwise
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
ecma_op_is_integer (ecma_number_t num) /**< ecma number */
|
||||||
|
{
|
||||||
|
|
||||||
|
if (ecma_number_is_nan (num) || ecma_number_is_infinity (num))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_number_t floor_fabs = floor (fabs (num));
|
||||||
|
ecma_number_t fabs_value = fabs (num);
|
||||||
|
|
||||||
|
return (floor_fabs == fabs_value);
|
||||||
|
} /* ecma_op_is_integer*/
|
||||||
/**
|
/**
|
||||||
* ToInteger operation.
|
* ToInteger operation.
|
||||||
*
|
*
|
||||||
@@ -964,7 +920,7 @@ ecma_op_to_integer (ecma_value_t value, /**< ecma value */
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 1 */
|
/* 1 */
|
||||||
ecma_value_t to_number = ecma_op_to_numeric (value, number_p, ECMA_TO_NUMERIC_NO_OPTS);
|
ecma_value_t to_number = ecma_op_to_number (value, number_p);
|
||||||
|
|
||||||
/* 2 */
|
/* 2 */
|
||||||
if (ECMA_IS_VALUE_ERROR (to_number))
|
if (ECMA_IS_VALUE_ERROR (to_number))
|
||||||
@@ -988,7 +944,6 @@ ecma_op_to_integer (ecma_value_t value, /**< ecma value */
|
|||||||
}
|
}
|
||||||
|
|
||||||
ecma_number_t floor_fabs = floor (fabs (number));
|
ecma_number_t floor_fabs = floor (fabs (number));
|
||||||
|
|
||||||
/* 5 */
|
/* 5 */
|
||||||
*number_p = ecma_number_is_negative (number) ? -floor_fabs : floor_fabs;
|
*number_p = ecma_number_is_negative (number) ? -floor_fabs : floor_fabs;
|
||||||
return ECMA_VALUE_EMPTY;
|
return ECMA_VALUE_EMPTY;
|
||||||
@@ -1044,7 +999,7 @@ ecma_op_to_length (ecma_value_t value, /**< ecma value */
|
|||||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||||
/* In the case of ES5, ToLength(ES6) operation is the same as ToUint32(ES5) */
|
/* In the case of ES5, ToLength(ES6) operation is the same as ToUint32(ES5) */
|
||||||
ecma_number_t num;
|
ecma_number_t num;
|
||||||
ecma_value_t to_number = ecma_op_to_numeric (value, &num, ECMA_TO_NUMERIC_NO_OPTS);
|
ecma_value_t to_number = ecma_op_to_number (value, &num);
|
||||||
|
|
||||||
/* 2 */
|
/* 2 */
|
||||||
if (ECMA_IS_VALUE_ERROR (to_number))
|
if (ECMA_IS_VALUE_ERROR (to_number))
|
||||||
|
|||||||
@@ -53,11 +53,12 @@ bool ecma_op_same_value_zero (ecma_value_t x, ecma_value_t y, bool strict_equali
|
|||||||
#endif /* ENABLED (JERRY_BUILTIN_MAP) */
|
#endif /* ENABLED (JERRY_BUILTIN_MAP) */
|
||||||
ecma_value_t ecma_op_to_primitive (ecma_value_t value, ecma_preferred_type_hint_t preferred_type);
|
ecma_value_t ecma_op_to_primitive (ecma_value_t value, ecma_preferred_type_hint_t preferred_type);
|
||||||
bool ecma_op_to_boolean (ecma_value_t value);
|
bool ecma_op_to_boolean (ecma_value_t value);
|
||||||
ecma_value_t ecma_op_to_number (ecma_value_t value, ecma_to_numeric_options_t options);
|
ecma_value_t ecma_op_to_number (ecma_value_t value, ecma_number_t *number_p);
|
||||||
ecma_value_t ecma_op_to_numeric (ecma_value_t value, ecma_number_t *number_p, ecma_to_numeric_options_t options);
|
ecma_value_t ecma_op_to_numeric (ecma_value_t value, ecma_number_t *number_p, ecma_to_numeric_options_t options);
|
||||||
ecma_string_t *ecma_op_to_string (ecma_value_t value);
|
ecma_string_t *ecma_op_to_string (ecma_value_t value);
|
||||||
ecma_string_t *ecma_op_to_property_key (ecma_value_t value);
|
ecma_string_t *ecma_op_to_property_key (ecma_value_t value);
|
||||||
ecma_value_t ecma_op_to_object (ecma_value_t value);
|
ecma_value_t ecma_op_to_object (ecma_value_t value);
|
||||||
|
bool ecma_op_is_integer (ecma_number_t value);
|
||||||
ecma_value_t ecma_op_to_integer (ecma_value_t value, ecma_number_t *number_p);
|
ecma_value_t ecma_op_to_integer (ecma_value_t value, ecma_number_t *number_p);
|
||||||
ecma_value_t ecma_op_to_length (ecma_value_t value, ecma_length_t *length);
|
ecma_value_t ecma_op_to_length (ecma_value_t value, ecma_length_t *length);
|
||||||
#if ENABLED (JERRY_ESNEXT)
|
#if ENABLED (JERRY_ESNEXT)
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ ecma_op_dataview_create (const ecma_value_t *arguments_list_p, /**< arguments li
|
|||||||
if (arguments_list_len > 1)
|
if (arguments_list_len > 1)
|
||||||
{
|
{
|
||||||
ecma_number_t number_offset, offset_num;
|
ecma_number_t number_offset, offset_num;
|
||||||
if (ECMA_IS_VALUE_ERROR (ecma_op_to_numeric (arguments_list_p[1], &number_offset, ECMA_TO_NUMERIC_NO_OPTS)))
|
if (ECMA_IS_VALUE_ERROR (ecma_op_to_number (arguments_list_p[1], &number_offset)))
|
||||||
{
|
{
|
||||||
return ECMA_VALUE_ERROR;
|
return ECMA_VALUE_ERROR;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,13 +41,15 @@
|
|||||||
ecma_value_t
|
ecma_value_t
|
||||||
ecma_op_create_number_object (ecma_value_t arg) /**< argument passed to the Number constructor */
|
ecma_op_create_number_object (ecma_value_t arg) /**< argument passed to the Number constructor */
|
||||||
{
|
{
|
||||||
ecma_value_t conv_to_num_completion = ecma_op_to_number (arg, ECMA_TO_NUMERIC_NO_OPTS);
|
ecma_number_t num;
|
||||||
|
ecma_value_t conv_to_num_completion = ecma_op_to_number (arg, &num);
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (conv_to_num_completion))
|
if (ECMA_IS_VALUE_ERROR (conv_to_num_completion))
|
||||||
{
|
{
|
||||||
return conv_to_num_completion;
|
return conv_to_num_completion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conv_to_num_completion = ecma_make_number_value (num);
|
||||||
#if ENABLED (JERRY_BUILTIN_NUMBER)
|
#if ENABLED (JERRY_BUILTIN_NUMBER)
|
||||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE);
|
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE);
|
||||||
#else /* ENABLED (JERRY_BUILTIN_NUMBER) */
|
#else /* ENABLED (JERRY_BUILTIN_NUMBER) */
|
||||||
|
|||||||
@@ -2207,7 +2207,7 @@ ecma_regexp_split_helper (ecma_value_t this_arg, /**< this value */
|
|||||||
{
|
{
|
||||||
/* ECMA-262 v11, 21.2.5.13 13 */
|
/* ECMA-262 v11, 21.2.5.13 13 */
|
||||||
ecma_number_t num;
|
ecma_number_t num;
|
||||||
if (ECMA_IS_VALUE_ERROR (ecma_op_to_numeric (limit_arg, &num, ECMA_TO_NUMERIC_NO_OPTS)))
|
if (ECMA_IS_VALUE_ERROR (ecma_op_to_number (limit_arg, &num)))
|
||||||
{
|
{
|
||||||
goto cleanup_splitter;
|
goto cleanup_splitter;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
#define ECMA_OP_TO_NUMBER_TRY_CATCH(num_var, value, return_value) \
|
#define ECMA_OP_TO_NUMBER_TRY_CATCH(num_var, value, return_value) \
|
||||||
JERRY_ASSERT (return_value == ECMA_VALUE_EMPTY); \
|
JERRY_ASSERT (return_value == ECMA_VALUE_EMPTY); \
|
||||||
ecma_number_t num_var; \
|
ecma_number_t num_var; \
|
||||||
return_value = ecma_op_to_numeric (value, &num_var, ECMA_TO_NUMERIC_NO_OPTS); \
|
return_value = ecma_op_to_number (value, &num_var); \
|
||||||
\
|
\
|
||||||
if (JERRY_LIKELY (ecma_is_value_empty (return_value))) \
|
if (JERRY_LIKELY (ecma_is_value_empty (return_value))) \
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user