Refactor code to use ToLength (#3210)

JerryScript-DCO-1.0-Signed-off-by: Daniella Barsony bella@inf.u-szeged.hu
This commit is contained in:
Daniella Barsony
2019-10-21 14:08:13 +02:00
committed by Robert Fancsik
parent 3fb6f15730
commit 7b589d1381
6 changed files with 46 additions and 58 deletions
@@ -104,8 +104,7 @@ ecma_op_dataview_create (const ecma_value_t *arguments_list_p, /**< arguments li
if (arguments_list_len > 2)
{
/* 12.a */
ecma_number_t byte_length;
ecma_value_t byte_length_value = ecma_get_number (arguments_list_p[2], &byte_length);
ecma_value_t byte_length_value = ecma_op_to_length (arguments_list_p[2], &viewByteLength);
/* 12.b */
if (ECMA_IS_VALUE_ERROR (byte_length_value))
@@ -113,30 +112,6 @@ ecma_op_dataview_create (const ecma_value_t *arguments_list_p, /**< arguments li
return byte_length_value;
}
int32_t byte_length_int32 = ecma_number_to_int32 (byte_length);
if (ecma_number_is_nan (byte_length))
{
viewByteLength = 0;
}
else if (ecma_number_is_infinity (byte_length))
{
if (ecma_number_is_negative (byte_length))
{
return ecma_raise_range_error (ECMA_ERR_MSG ("Invalid DataView length"));
}
viewByteLength = UINT32_MAX;
}
else if (byte_length_int32 <= 0)
{
viewByteLength = 0;
}
else
{
viewByteLength = JERRY_MIN ((ecma_length_t) byte_length_int32, UINT32_MAX);
}
/* 12.c */
if ((ecma_number_t) offset + viewByteLength > buffer_byte_length)
{
@@ -960,7 +960,6 @@ ecma_op_create_typedarray (const ecma_value_t *arguments_list_p, /**< the arg li
: ECMA_VALUE_UNDEFINED);
ECMA_OP_TO_NUMBER_TRY_CATCH (num2, arg2, ret);
uint32_t offset = ecma_number_to_uint32 (num2);
if (ecma_number_is_negative (ecma_number_to_int32 (num2)) || (offset % (uint32_t) (1 << element_size_shift) != 0))
@@ -993,9 +992,11 @@ ecma_op_create_typedarray (const ecma_value_t *arguments_list_p, /**< the arg li
}
else
{
ECMA_OP_TO_NUMBER_TRY_CATCH (num3, arg3, ret);
int32_t new_length = ecma_number_to_int32 (num3);
new_length = (new_length > 0) ? new_length : 0;
uint32_t new_length;
if (ECMA_IS_VALUE_ERROR (ecma_op_to_length (arg3, &new_length)))
{
return ECMA_VALUE_ERROR;
}
if ((uint32_t) new_length > (UINT32_MAX >> element_size_shift))
{
@@ -1010,8 +1011,6 @@ ecma_op_create_typedarray (const ecma_value_t *arguments_list_p, /**< the arg li
ret = ecma_raise_range_error (ECMA_ERR_MSG ("Invalid length."));
}
}
ECMA_OP_TO_NUMBER_FINALIZE (num3);
}
if (ecma_is_value_empty (ret))