Refactor code to use ToInteger (#3224)
Fixes #3325 Fixes #3237 JerryScript-DCO-1.0-Signed-off-by: Daniella Barsony bella@inf.u-szeged.hu
This commit is contained in:
committed by
Robert Fancsik
parent
5ceffd209e
commit
89db9253c8
@@ -63,25 +63,27 @@ ecma_op_dataview_create (const ecma_value_t *arguments_list_p, /**< arguments li
|
||||
}
|
||||
|
||||
/* 4 - 6. */
|
||||
int32_t offset = 0;
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (arguments_list_len > 1)
|
||||
{
|
||||
ecma_number_t number_offset;
|
||||
ecma_value_t number_offset_value = ecma_get_number (arguments_list_p[1], &number_offset);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (number_offset_value))
|
||||
ecma_number_t number_offset, offset_num;
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_get_number (arguments_list_p[1], &number_offset)))
|
||||
{
|
||||
return number_offset_value;
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (arguments_list_p[1], &offset_num)))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
offset = ecma_number_to_int32 (number_offset);
|
||||
|
||||
/* 7. */
|
||||
if (number_offset != offset || offset < 0)
|
||||
if (number_offset != offset_num || offset_num < 0)
|
||||
{
|
||||
return ecma_raise_range_error (ECMA_ERR_MSG ("Start offset is outside the bounds of the buffer."));
|
||||
}
|
||||
|
||||
offset = (uint32_t) offset_num;
|
||||
}
|
||||
|
||||
/* 8. */
|
||||
@@ -240,7 +242,7 @@ ecma_op_dataview_get_set_view_value (ecma_value_t view, /**< the operation's 'vi
|
||||
|
||||
/* 3 - 5. */
|
||||
ecma_number_t number_index;
|
||||
ecma_value_t number_index_value = ecma_get_number (request_index, &number_index);
|
||||
ecma_value_t number_index_value = ecma_op_to_integer (request_index, &number_index);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (number_index_value))
|
||||
{
|
||||
|
||||
@@ -1308,7 +1308,8 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
|
||||
ecma_value_t lastindex_value = ecma_op_object_get_own_data_prop (regexp_object_p, lastindex_str_p);
|
||||
|
||||
ecma_number_t lastindex_num;
|
||||
ret_value = ecma_get_number (lastindex_value, &lastindex_num);
|
||||
ret_value = ecma_op_to_integer (lastindex_value, &lastindex_num);
|
||||
|
||||
ecma_free_value (lastindex_value);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (ret_value))
|
||||
|
||||
@@ -949,10 +949,13 @@ ecma_op_create_typedarray (const ecma_value_t *arguments_list_p, /**< the arg li
|
||||
ecma_value_t arg3 = ((arguments_list_len > 2) ? arguments_list_p[2]
|
||||
: ECMA_VALUE_UNDEFINED);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (num2, arg2, ret);
|
||||
uint32_t offset = ecma_number_to_uint32 (num2);
|
||||
ecma_number_t offset;
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (arg2, &offset)))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
if (ecma_number_is_negative (ecma_number_to_int32 (num2)) || (offset % (uint32_t) (1 << element_size_shift) != 0))
|
||||
if (ecma_number_is_negative (offset))
|
||||
{
|
||||
ret = ecma_raise_range_error (ECMA_ERR_MSG ("Invalid offset."));
|
||||
}
|
||||
@@ -1007,15 +1010,13 @@ ecma_op_create_typedarray (const ecma_value_t *arguments_list_p, /**< the arg li
|
||||
{
|
||||
ecma_length_t array_length = new_byte_length >> element_size_shift;
|
||||
ret = ecma_typedarray_create_object_with_buffer (arraybuffer_p,
|
||||
offset,
|
||||
(ecma_length_t) offset,
|
||||
array_length,
|
||||
proto_p,
|
||||
element_size_shift,
|
||||
typedarray_id);
|
||||
}
|
||||
}
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (num2);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user