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
@@ -2245,18 +2245,16 @@ ecma_builtin_array_prototype_dispatch_routine (uint16_t builtin_routine_id, /**<
return len_value;
}
ecma_number_t length_number;
ecma_value_t ret_value = ecma_get_number (len_value, &length_number);
uint32_t length = 0;
ecma_value_t ret_value = ecma_op_to_length (len_value, &length);
if (!ecma_is_value_empty (ret_value))
if (ECMA_IS_VALUE_ERROR (ret_value))
{
ecma_free_value (len_value);
ecma_deref_object (obj_p);
return ret_value;
}
uint32_t length = ecma_number_to_uint32 (length_number);
ecma_value_t routine_arg_1 = arguments_list_p[0];
ecma_value_t routine_arg_2 = arguments_list_p[1];
@@ -965,18 +965,10 @@ ecma_builtin_typedarray_prototype_set (ecma_value_t this_arg, /**< this argument
ecma_op_object_get_by_magic_id (source_obj_p, LIT_MAGIC_STRING_LENGTH),
ret_val);
ECMA_OP_TO_NUMBER_TRY_CATCH (source_length_num, source_length, ret_val);
if (ecma_number_is_nan (source_length_num) || source_length_num <= 0)
uint32_t source_length_uint32;
if (ECMA_IS_VALUE_ERROR (ecma_op_to_length (source_length, &source_length_uint32)))
{
source_length_num = 0;
}
uint32_t source_length_uint32 = ecma_number_to_uint32 (source_length_num);
if ((ecma_number_t) source_length_uint32 != source_length_num)
{
return ecma_raise_range_error (ECMA_ERR_MSG ("Invalid source length"));
return ECMA_VALUE_ERROR;
}
/* 20. if srcLength + targetOffset > targetLength, throw a RangeError */
@@ -1012,7 +1004,6 @@ ecma_builtin_typedarray_prototype_set (ecma_value_t this_arg, /**< this argument
target_byte_index += target_info.element_size;
}
ECMA_OP_TO_NUMBER_FINALIZE (source_length_num);
ECMA_FINALIZE (source_length);
ECMA_FINALIZE (source_obj);
ECMA_OP_TO_NUMBER_FINALIZE (target_offset_num);