Update ToLength operation to conform ES6 spec (#4007)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-iterator-object.h"
|
||||
#include "ecma-typedarray-object.h"
|
||||
#include "ecma-arraybuffer-object.h"
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
|
||||
@@ -78,16 +79,31 @@ ecma_builtin_array_iterator_prototype_object_next (ecma_value_t this_val) /**< t
|
||||
|
||||
ecma_object_t *array_object_p = ecma_get_object_from_value (iterated_value);
|
||||
|
||||
/* 8 - 9. */
|
||||
uint32_t length;
|
||||
ecma_value_t len_value = ecma_op_object_get_length (array_object_p, &length);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (len_value))
|
||||
/* 8. */
|
||||
ecma_length_t length;
|
||||
if (ecma_object_is_typedarray (array_object_p))
|
||||
{
|
||||
return len_value;
|
||||
/* a. */
|
||||
ecma_object_t *arraybuffer_p = ecma_typedarray_get_arraybuffer (array_object_p);
|
||||
if (ecma_arraybuffer_is_detached (arraybuffer_p))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("ArrayBuffer has been detached."));
|
||||
}
|
||||
|
||||
/* b. */
|
||||
length = ecma_typedarray_get_length (array_object_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_value_t len_value = ecma_op_object_get_length (array_object_p, &length);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (len_value))
|
||||
{
|
||||
return len_value;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t index = ext_obj_p->u.pseudo_array.u1.iterator_index;
|
||||
ecma_length_t index = ext_obj_p->u.pseudo_array.u1.iterator_index;
|
||||
|
||||
if (JERRY_UNLIKELY (index == ECMA_ITERATOR_INDEX_LIMIT))
|
||||
{
|
||||
@@ -98,12 +114,12 @@ ecma_builtin_array_iterator_prototype_object_next (ecma_value_t this_val) /**< t
|
||||
|
||||
if (!ecma_is_value_undefined (index_value))
|
||||
{
|
||||
index = (uint32_t) (ecma_get_number_from_value (index_value) + 1);
|
||||
index = (ecma_length_t) (ecma_get_number_from_value (index_value) + 1);
|
||||
}
|
||||
|
||||
ecma_value_t put_result = ecma_op_object_put (obj_p,
|
||||
prop_name_p,
|
||||
ecma_make_uint32_value (index),
|
||||
ecma_make_length_value (index),
|
||||
true);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_true (put_result));
|
||||
@@ -128,11 +144,11 @@ ecma_builtin_array_iterator_prototype_object_next (ecma_value_t this_val) /**< t
|
||||
if (iterator_kind == ECMA_ITERATOR_KEYS)
|
||||
{
|
||||
/* 12. */
|
||||
return ecma_create_iter_result_object (ecma_make_uint32_value (index), ECMA_VALUE_FALSE);
|
||||
return ecma_create_iter_result_object (ecma_make_length_value (index), ECMA_VALUE_FALSE);
|
||||
}
|
||||
|
||||
/* 14. */
|
||||
ecma_value_t get_value = ecma_op_object_get_by_uint32_index (array_object_p, index);
|
||||
ecma_value_t get_value = ecma_op_object_get_by_index (array_object_p, index);
|
||||
|
||||
/* 15. */
|
||||
if (ECMA_IS_VALUE_ERROR (get_value))
|
||||
@@ -155,7 +171,7 @@ ecma_builtin_array_iterator_prototype_object_next (ecma_value_t this_val) /**< t
|
||||
/* 17.b */
|
||||
ecma_value_t entry_array_value;
|
||||
entry_array_value = ecma_create_array_from_iter_element (get_value,
|
||||
ecma_make_uint32_value (index));
|
||||
ecma_make_length_value (index));
|
||||
|
||||
result = ecma_create_iter_result_object (entry_array_value, ECMA_VALUE_FALSE);
|
||||
ecma_free_value (entry_array_value);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -274,7 +274,7 @@ iterator_cleanup:
|
||||
ecma_object_t *array_like_obj_p = ecma_get_object_from_value (array_like);
|
||||
|
||||
/* 10. */
|
||||
uint32_t len;
|
||||
ecma_length_t len;
|
||||
ecma_value_t len_value = ecma_op_object_get_length (array_like_obj_p, &len);
|
||||
|
||||
/* 11. */
|
||||
@@ -283,7 +283,7 @@ iterator_cleanup:
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
len_value = ecma_make_uint32_value (len);
|
||||
len_value = ecma_make_length_value (len);
|
||||
|
||||
/* 12. */
|
||||
ecma_value_t array;
|
||||
@@ -319,13 +319,13 @@ iterator_cleanup:
|
||||
ecma_object_t *array_obj_p = ecma_get_object_from_value (array);
|
||||
|
||||
/* 15. */
|
||||
uint32_t k = 0;
|
||||
ecma_length_t k = 0;
|
||||
|
||||
/* 16. */
|
||||
while (k < len)
|
||||
{
|
||||
/* 16.b */
|
||||
ecma_value_t k_value = ecma_op_object_get_by_uint32_index (array_like_obj_p, k);
|
||||
ecma_value_t k_value = ecma_op_object_get_by_index (array_like_obj_p, k);
|
||||
|
||||
/* 16.c */
|
||||
if (ECMA_IS_VALUE_ERROR (k_value))
|
||||
@@ -338,7 +338,7 @@ iterator_cleanup:
|
||||
if (mapfn_obj_p != NULL)
|
||||
{
|
||||
/* 16.d.i */
|
||||
ecma_value_t args_p[2] = { k_value, ecma_make_uint32_value (k) };
|
||||
ecma_value_t args_p[2] = { k_value, ecma_make_length_value (k) };
|
||||
mapped_value = ecma_op_function_call (mapfn_obj_p, call_this_arg, args_p, 2);
|
||||
ecma_free_value (args_p[1]);
|
||||
ecma_free_value (k_value);
|
||||
@@ -372,7 +372,7 @@ iterator_cleanup:
|
||||
}
|
||||
|
||||
/* 17. */
|
||||
len_value = ecma_make_uint32_value (k);
|
||||
len_value = ecma_make_length_value (k);
|
||||
ecma_value_t set_status = ecma_op_object_put (array_obj_p,
|
||||
ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH),
|
||||
len_value,
|
||||
|
||||
@@ -111,18 +111,18 @@ ecma_builtin_arraybuffer_prototype_object_slice (ecma_value_t this_arg, /**< thi
|
||||
|
||||
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (arg1,
|
||||
len,
|
||||
&start)))
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (arg1,
|
||||
len,
|
||||
&start)))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
if (!ecma_is_value_undefined (arg2))
|
||||
{
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (arg2,
|
||||
len,
|
||||
&end)))
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (arg2,
|
||||
len,
|
||||
&end)))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ ecma_builtin_function_prototype_object_apply (ecma_object_t *func_obj_p, /**< th
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg2);
|
||||
|
||||
/* 4-5. */
|
||||
uint32_t length;
|
||||
ecma_length_t length;
|
||||
ecma_value_t len_value = ecma_op_object_get_length (obj_p, &length);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (len_value))
|
||||
@@ -130,12 +130,12 @@ ecma_builtin_function_prototype_object_apply (ecma_object_t *func_obj_p, /**< th
|
||||
/* 6. */
|
||||
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
||||
JMEM_DEFINE_LOCAL_ARRAY (arguments_list_p, length, ecma_value_t);
|
||||
uint32_t index = 0;
|
||||
ecma_length_t index = 0;
|
||||
|
||||
/* 7. */
|
||||
for (index = 0; index < length; index++)
|
||||
{
|
||||
ecma_value_t get_value = ecma_op_object_get_by_uint32_index (obj_p, index);
|
||||
ecma_value_t get_value = ecma_op_object_get_by_index (obj_p, index);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (get_value))
|
||||
{
|
||||
@@ -152,7 +152,7 @@ ecma_builtin_function_prototype_object_apply (ecma_object_t *func_obj_p, /**< th
|
||||
ret_value = ecma_op_function_call (func_obj_p,
|
||||
arg1,
|
||||
arguments_list_p,
|
||||
length);
|
||||
(uint32_t) length);
|
||||
}
|
||||
|
||||
for (uint32_t remove_index = 0; remove_index < index; remove_index++)
|
||||
|
||||
@@ -196,9 +196,9 @@ ecma_builtin_helper_object_to_string (const ecma_value_t this_arg) /**< this arg
|
||||
*/
|
||||
ecma_string_t *
|
||||
ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, /**< this object */
|
||||
uint32_t index) /**< array index */
|
||||
ecma_length_t index) /**< array index */
|
||||
{
|
||||
ecma_value_t index_value = ecma_op_object_get_by_uint32_index (obj_p, index);
|
||||
ecma_value_t index_value = ecma_op_object_get_by_index (obj_p, index);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (index_value))
|
||||
{
|
||||
@@ -232,9 +232,46 @@ ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, /**< th
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.4.4.10 steps 5, 6, 7 part 2, 8
|
||||
* ECMA-262 v5, 15.4.4.12 steps 5, 6
|
||||
* ECMA-262 v5, 15.5.4.13 steps 4 - 7
|
||||
*
|
||||
* ECMA-262 v6, 22.1.3.6 steps 5 - 7, 8 part 2, 9, 10
|
||||
* ECMA-262 v6, 22.1.3.3 steps 5 - 10, 11 part 2, 12, 13
|
||||
*
|
||||
* Used by:
|
||||
* - The Array.prototype.slice routine.
|
||||
* - The Array.prototype.splice routine.
|
||||
* - The Array.prototype.fill routine.
|
||||
* - The Array.prototype.copyWithin routine.
|
||||
*
|
||||
* @return ECMA_VALUE_EMPTY if successful
|
||||
* conversion error otherwise
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_array_index_normalize (ecma_value_t arg, /**< index */
|
||||
ecma_length_t length, /**< array's length */
|
||||
ecma_length_t *number_p) /**< [out] ecma_length_t */
|
||||
{
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
ecma_number_t to_int;
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (arg, &to_int)))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
*number_p = ((to_int < 0) ? (ecma_length_t) JERRY_MAX (((ecma_number_t) length + to_int), 0)
|
||||
: (ecma_length_t) JERRY_MIN (to_int, (ecma_number_t) length));
|
||||
|
||||
return ECMA_VALUE_EMPTY;
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
return ecma_builtin_helper_uint32_index_normalize (arg, length, number_p);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
} /* ecma_builtin_helper_array_index_normalize */
|
||||
|
||||
/**
|
||||
* Helper function to normalizing an uint32 index
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.5.4.13 steps 4 - 7
|
||||
* ECMA-262 v6, 22.2.3.5 steps 5 - 10, 11 part 2, 12, 13
|
||||
* ECMA-262 v6, 22.2.3.23 steps 5 - 10
|
||||
* ECMA-262 v6, 24.1.4.3 steps 6 - 8, 9 part 2, 10, 11
|
||||
@@ -242,10 +279,7 @@ ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, /**< th
|
||||
* ECMA-262 v6, 22.2.3.8 steps 5 - 7, 8 part 2, 9, 10
|
||||
*
|
||||
* Used by:
|
||||
* - The Array.prototype.slice routine.
|
||||
* - The Array.prototype.splice routine.
|
||||
* - The String.prototype.slice routine.
|
||||
* - The Array.prototype.fill routine.
|
||||
* - The Array.prototype.copyWithin routine.
|
||||
* - The TypedArray.prototype.copyWithin routine.
|
||||
* - The TypedArray.prototype.slice routine.
|
||||
@@ -256,10 +290,10 @@ ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, /**< th
|
||||
* @return ECMA_VALUE_EMPTY if successful
|
||||
* conversion error otherwise
|
||||
*/
|
||||
uint32_t
|
||||
ecma_builtin_helper_array_index_normalize (ecma_value_t arg, /**< index */
|
||||
uint32_t length, /**< array's length */
|
||||
uint32_t *number_p) /**< [out] uint32_t */
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_uint32_index_normalize (ecma_value_t arg, /**< index */
|
||||
uint32_t length, /**< array's length */
|
||||
uint32_t *number_p) /**< [out] uint32_t number */
|
||||
{
|
||||
ecma_number_t to_int;
|
||||
|
||||
@@ -268,11 +302,11 @@ ecma_builtin_helper_array_index_normalize (ecma_value_t arg, /**< index */
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
*number_p = ((to_int < 0) ? (uint32_t) JERRY_MAX ((length + to_int), 0)
|
||||
*number_p = ((to_int < 0) ? (uint32_t) JERRY_MAX (length + to_int, 0)
|
||||
: (uint32_t) JERRY_MIN (to_int, length));
|
||||
|
||||
return ECMA_VALUE_EMPTY;
|
||||
} /* ecma_builtin_helper_array_index_normalize */
|
||||
} /* ecma_builtin_helper_uint32_index_normalize */
|
||||
|
||||
/**
|
||||
* Helper function for concatenating an ecma_value_t to an Array.
|
||||
@@ -288,7 +322,7 @@ ecma_builtin_helper_array_index_normalize (ecma_value_t arg, /**< index */
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_array_concat_value (ecma_object_t *array_obj_p, /**< array */
|
||||
uint32_t *length_p, /**< [in,out] array's length */
|
||||
ecma_length_t *length_p, /**< [in,out] array's length */
|
||||
ecma_value_t value) /**< value to concat */
|
||||
{
|
||||
/* 5.b */
|
||||
@@ -314,22 +348,28 @@ ecma_builtin_helper_array_concat_value (ecma_object_t *array_obj_p, /**< array *
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (value);
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
uint32_t arg_len;
|
||||
ecma_length_t arg_len;
|
||||
ecma_value_t error = ecma_op_object_get_length (obj_p, &arg_len);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (error))
|
||||
{
|
||||
return error;
|
||||
}
|
||||
|
||||
/* 4 . */
|
||||
if (*length_p + arg_len > ECMA_NUMBER_MAX_SAFE_INTEGER)
|
||||
{
|
||||
return ecma_raise_range_error (ECMA_ERR_MSG ("Invalid array length."));
|
||||
}
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
/* 5.b.ii */
|
||||
uint32_t arg_len = ecma_array_get_length (obj_p);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
/* 5.b.iii */
|
||||
for (uint32_t array_index = 0; array_index < arg_len; array_index++)
|
||||
for (ecma_length_t array_index = 0; array_index < arg_len; array_index++)
|
||||
{
|
||||
/* 5.b.iii.2 */
|
||||
ecma_value_t get_value = ecma_op_object_find_by_uint32_index (obj_p, array_index);
|
||||
ecma_value_t get_value = ecma_op_object_find_by_index (obj_p, array_index);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (get_value))
|
||||
{
|
||||
@@ -725,7 +765,7 @@ ecma_builtin_helper_string_find_index (ecma_string_t *original_str_p, /**< index
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_def_prop_by_index (ecma_object_t *obj_p, /**< object */
|
||||
uint32_t index, /**< property index */
|
||||
ecma_length_t index, /**< property index */
|
||||
ecma_value_t value, /**< value */
|
||||
uint32_t opts) /**< any combination of ecma_property_flag_t bits */
|
||||
{
|
||||
@@ -737,11 +777,8 @@ ecma_builtin_helper_def_prop_by_index (ecma_object_t *obj_p, /**< object */
|
||||
opts);
|
||||
}
|
||||
|
||||
ecma_string_t *index_str_p = ecma_new_non_direct_string_from_uint32 (index);
|
||||
ecma_value_t ret_value = ecma_builtin_helper_def_prop (obj_p,
|
||||
index_str_p,
|
||||
value,
|
||||
opts);
|
||||
ecma_string_t *index_str_p = ecma_new_ecma_string_from_length (index);
|
||||
ecma_value_t ret_value = ecma_builtin_helper_def_prop (obj_p, index_str_p, value, opts);
|
||||
ecma_deref_ecma_string (index_str_p);
|
||||
|
||||
return ret_value;
|
||||
|
||||
@@ -44,12 +44,14 @@ typedef enum
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_object_to_string (const ecma_value_t this_arg);
|
||||
ecma_string_t *
|
||||
ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, uint32_t index);
|
||||
ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, ecma_length_t index);
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_array_concat_value (ecma_object_t *obj_p, ecma_length_t *length_p, ecma_value_t value);
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_uint32_index_normalize (ecma_value_t arg, uint32_t length, uint32_t *number_p);
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_array_index_normalize (ecma_value_t arg, ecma_length_t length, ecma_length_t *number_p);
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_array_concat_value (ecma_object_t *obj_p, uint32_t *length_p, ecma_value_t value);
|
||||
uint32_t
|
||||
ecma_builtin_helper_array_index_normalize (ecma_value_t arg, uint32_t length, uint32_t *number_p);
|
||||
uint32_t
|
||||
ecma_builtin_helper_string_index_normalize (ecma_number_t index, uint32_t length, bool nan_to_zero);
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_string_prototype_object_index_of (ecma_string_t *original_str_p, ecma_value_t arg1,
|
||||
@@ -61,8 +63,8 @@ ecma_value_t
|
||||
ecma_builtin_helper_def_prop (ecma_object_t *obj_p, ecma_string_t *name_p, ecma_value_t value, uint32_t opts);
|
||||
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_def_prop_by_index (ecma_object_t *obj_p, uint32_t index, ecma_value_t value, uint32_t opts);
|
||||
|
||||
ecma_builtin_helper_def_prop_by_index (ecma_object_t *obj_p, ecma_length_t index, ecma_value_t value,
|
||||
uint32_t opts);
|
||||
/**
|
||||
* Context for replace substitutions
|
||||
*/
|
||||
|
||||
@@ -649,20 +649,23 @@ ecma_builtin_json_internalize_property (ecma_object_t *reviver_p, /**< reviver f
|
||||
if (ecma_is_value_true (is_array))
|
||||
{
|
||||
/* 3.c.ii */
|
||||
uint32_t len;
|
||||
ecma_value_t to_len = ecma_op_object_get_length (object_p, &len);
|
||||
ecma_length_t length;
|
||||
ecma_value_t to_len = ecma_op_object_get_length (object_p, &length);
|
||||
|
||||
/* 3.c.iii */
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
if (ECMA_IS_VALUE_ERROR (to_len))
|
||||
{
|
||||
ecma_deref_object (object_p);
|
||||
return to_len;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
JERRY_ASSERT (ecma_is_value_empty (to_len));
|
||||
|
||||
/* 3.c.iv */
|
||||
for (uint32_t i = 0; i < len; i++)
|
||||
for (ecma_length_t i = 0; i < length; i++)
|
||||
{
|
||||
ecma_string_t *prop_index = ecma_new_ecma_string_from_uint32 (i);
|
||||
ecma_string_t *prop_index = ecma_new_ecma_string_from_length (i);
|
||||
|
||||
ecma_value_t new_element = ecma_builtin_json_internalize_property (reviver_p, object_p, prop_index);
|
||||
|
||||
@@ -675,9 +678,7 @@ ecma_builtin_json_internalize_property (ecma_object_t *reviver_p, /**< reviver f
|
||||
|
||||
if (ecma_is_value_undefined (new_element))
|
||||
{
|
||||
ecma_value_t delete_val = ecma_op_object_delete_by_uint32_index (object_p,
|
||||
i,
|
||||
false);
|
||||
ecma_value_t delete_val = ecma_op_object_delete (object_p, prop_index, false);
|
||||
JERRY_ASSERT (ecma_is_value_boolean (delete_val));
|
||||
}
|
||||
else
|
||||
@@ -1113,23 +1114,16 @@ ecma_builtin_json_serialize_array (ecma_json_stringify_context_t *context_p, /**
|
||||
const bool has_gap = !ecma_compare_ecma_string_to_magic_id (context_p->gap_str_p, LIT_MAGIC_STRING__EMPTY);
|
||||
|
||||
/* 6. */
|
||||
uint32_t array_length;
|
||||
ecma_length_t array_length;
|
||||
ecma_value_t length_value = ecma_op_object_get_length (obj_p, &array_length);
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_IS_PROXY (obj_p))
|
||||
if (ECMA_IS_VALUE_ERROR (length_value))
|
||||
{
|
||||
ecma_value_t length_value = ecma_op_object_get_length (obj_p, &array_length);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (length_value))
|
||||
{
|
||||
return length_value;
|
||||
}
|
||||
return length_value;
|
||||
}
|
||||
else
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
{
|
||||
array_length = ((ecma_extended_object_t *) obj_p)->u.array.length;
|
||||
}
|
||||
JERRY_ASSERT (ecma_is_value_empty (length_value));
|
||||
|
||||
ecma_stringbuilder_append_byte (&context_p->result_builder, LIT_CHAR_LEFT_SQUARE);
|
||||
|
||||
@@ -1137,10 +1131,10 @@ ecma_builtin_json_serialize_array (ecma_json_stringify_context_t *context_p, /**
|
||||
lit_utf8_size_t last_prop = left_square;
|
||||
|
||||
/* 8. - 9. */
|
||||
for (uint32_t index = 0; index < array_length; index++)
|
||||
for (ecma_length_t index = 0; index < array_length; index++)
|
||||
{
|
||||
/* 9.a */
|
||||
ecma_string_t *index_str_p = ecma_new_ecma_string_from_uint32 (index);
|
||||
ecma_string_t *index_str_p = ecma_new_ecma_string_from_length (index);
|
||||
|
||||
if (has_gap)
|
||||
{
|
||||
@@ -1506,13 +1500,16 @@ ecma_builtin_json_stringify (ecma_value_t this_arg, /**< 'this' argument */
|
||||
|
||||
if (ecma_is_value_true (is_array))
|
||||
{
|
||||
uint32_t array_length;
|
||||
ecma_length_t array_length;
|
||||
ecma_value_t to_len = ecma_op_object_get_length (obj_p, &array_length);
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
if (ECMA_IS_VALUE_ERROR (to_len))
|
||||
{
|
||||
return to_len;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
JERRY_ASSERT (ecma_is_value_empty (to_len));
|
||||
|
||||
context.property_list_p = ecma_new_collection ();
|
||||
|
||||
@@ -1521,7 +1518,7 @@ ecma_builtin_json_stringify (ecma_value_t this_arg, /**< 'this' argument */
|
||||
/* 4.b.iii.5 */
|
||||
while (index < array_length)
|
||||
{
|
||||
ecma_value_t value = ecma_op_object_get_by_uint32_index (obj_p, index);
|
||||
ecma_value_t value = ecma_op_object_get_by_index (obj_p, index);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (value))
|
||||
{
|
||||
|
||||
@@ -688,9 +688,9 @@ ecma_builtin_string_prototype_object_slice (ecma_string_t *get_string_val, /**<
|
||||
/* 4. 6. */
|
||||
lit_utf8_size_t start = 0, end = len;
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (arg1,
|
||||
len,
|
||||
&start)))
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (arg1,
|
||||
len,
|
||||
&start)))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
@@ -702,9 +702,9 @@ ecma_builtin_string_prototype_object_slice (ecma_string_t *get_string_val, /**<
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (arg2,
|
||||
len,
|
||||
&end)))
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (arg2,
|
||||
len,
|
||||
&end)))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
@@ -778,7 +778,8 @@ ecma_builtin_string_prototype_object_split (ecma_value_t this_value, /**< this a
|
||||
}
|
||||
|
||||
/* 8. */
|
||||
uint32_t limit = UINT32_MAX;
|
||||
uint32_t limit = UINT32_MAX - 1;
|
||||
|
||||
if (!ecma_is_value_undefined (limit_value))
|
||||
{
|
||||
/* ECMA-262 v11, 21.1.3.20 6 */
|
||||
|
||||
@@ -180,7 +180,7 @@ ecma_builtin_string_object_raw (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t ret_value = ECMA_VALUE_ERROR;
|
||||
|
||||
/* 7 - 8. */
|
||||
uint32_t literal_segments;
|
||||
ecma_length_t literal_segments;
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_op_object_get_length (raw_obj_p, &literal_segments)))
|
||||
{
|
||||
goto cleanup;
|
||||
@@ -197,13 +197,13 @@ ecma_builtin_string_object_raw (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_stringbuilder_t builder = ecma_stringbuilder_create ();
|
||||
|
||||
/* 11. */
|
||||
uint32_t next_index = 0;
|
||||
ecma_length_t next_index = 0;
|
||||
|
||||
/* 12. */
|
||||
while (true)
|
||||
{
|
||||
/* 12.a,b */
|
||||
ecma_value_t next_seg = ecma_op_object_get_by_uint32_index (raw_obj_p, next_index);
|
||||
ecma_value_t next_seg = ecma_op_object_get_by_index (raw_obj_p, next_index);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (next_seg))
|
||||
{
|
||||
|
||||
@@ -914,20 +914,22 @@ ecma_builtin_typedarray_prototype_set (ecma_value_t this_arg, /**< this argument
|
||||
/* 18.~ 19. */
|
||||
ecma_object_t *source_obj_p = ecma_get_object_from_value (source_obj);
|
||||
|
||||
uint32_t source_length_uint32;
|
||||
ecma_length_t source_length;
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_op_object_get_length (source_obj_p, &source_length_uint32)))
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_op_object_get_length (source_obj_p, &source_length)))
|
||||
{
|
||||
ecma_deref_object (source_obj_p);
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
/* 20. if srcLength + targetOffset > targetLength, throw a RangeError */
|
||||
if ((int64_t) source_length_uint32 + target_offset_uint32 > target_info.length)
|
||||
if ((int64_t) source_length + target_offset_uint32 > target_info.length)
|
||||
{
|
||||
ecma_deref_object (source_obj_p);
|
||||
return ecma_raise_range_error (ECMA_ERR_MSG ("Invalid range of index"));
|
||||
}
|
||||
JERRY_ASSERT (source_length <= UINT32_MAX);
|
||||
uint32_t source_length_uint32 = (uint32_t) source_length;
|
||||
|
||||
/* 21.~ 25. */
|
||||
uint32_t target_byte_index = target_offset_uint32 * target_info.element_size;
|
||||
@@ -937,7 +939,7 @@ ecma_builtin_typedarray_prototype_set (ecma_value_t this_arg, /**< this argument
|
||||
|
||||
while (k < source_length_uint32)
|
||||
{
|
||||
ecma_value_t elem = ecma_op_object_get_by_uint32_index (source_obj_p, k);
|
||||
ecma_value_t elem = ecma_op_object_get_by_index (source_obj_p, k);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (elem))
|
||||
{
|
||||
@@ -981,7 +983,7 @@ static ecma_string_t *
|
||||
ecma_op_typedarray_get_to_string_at_index (ecma_object_t *obj_p, /**< this object */
|
||||
uint32_t index) /**< array index */
|
||||
{
|
||||
ecma_value_t index_value = ecma_op_object_get_by_uint32_index (obj_p, index);
|
||||
ecma_value_t index_value = ecma_op_object_get_by_index (obj_p, index);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (index_value))
|
||||
{
|
||||
@@ -1159,9 +1161,9 @@ ecma_builtin_typedarray_prototype_subarray (ecma_value_t this_arg, /**< this arg
|
||||
uint32_t begin_index_uint32 = 0, end_index_uint32 = 0;
|
||||
|
||||
/* 7. relativeBegin */
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (begin,
|
||||
info.length,
|
||||
&begin_index_uint32)))
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (begin,
|
||||
info.length,
|
||||
&begin_index_uint32)))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
@@ -1173,9 +1175,9 @@ ecma_builtin_typedarray_prototype_subarray (ecma_value_t this_arg, /**< this arg
|
||||
else
|
||||
{
|
||||
/* 10. relativeEnd */
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (end,
|
||||
info.length,
|
||||
&end_index_uint32)))
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (end,
|
||||
info.length,
|
||||
&end_index_uint32)))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
@@ -1244,9 +1246,9 @@ ecma_builtin_typedarray_prototype_fill (ecma_value_t this_arg, /**< this argumen
|
||||
|
||||
uint32_t begin_index_uint32 = 0, end_index_uint32 = 0;
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (begin,
|
||||
info.length,
|
||||
&begin_index_uint32)))
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (begin,
|
||||
info.length,
|
||||
&begin_index_uint32)))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
@@ -1257,9 +1259,9 @@ ecma_builtin_typedarray_prototype_fill (ecma_value_t this_arg, /**< this argumen
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (end,
|
||||
info.length,
|
||||
&end_index_uint32)))
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (end,
|
||||
info.length,
|
||||
&end_index_uint32)))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
@@ -1772,27 +1774,27 @@ ecma_builtin_typedarray_prototype_copy_within (ecma_value_t this_arg, /**< this
|
||||
|
||||
if (args_number > 0)
|
||||
{
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (args[0],
|
||||
info.length,
|
||||
&relative_target)))
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (args[0],
|
||||
info.length,
|
||||
&relative_target)))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
if (args_number > 1)
|
||||
{
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (args[1],
|
||||
info.length,
|
||||
&relative_start)))
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (args[1],
|
||||
info.length,
|
||||
&relative_start)))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
if (args_number > 2 && args[2] != ECMA_VALUE_UNDEFINED)
|
||||
{
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (args[2],
|
||||
info.length,
|
||||
&relative_end)))
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (args[2],
|
||||
info.length,
|
||||
&relative_end)))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
@@ -1850,18 +1852,18 @@ ecma_builtin_typedarray_prototype_slice (ecma_value_t this_arg, /**< this argume
|
||||
|
||||
if (args_number > 0)
|
||||
{
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (args[0],
|
||||
info.length,
|
||||
&relative_start)))
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (args[0],
|
||||
info.length,
|
||||
&relative_start)))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
if (args_number > 1
|
||||
&& args[1] != ECMA_VALUE_UNDEFINED
|
||||
&& ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (args[1],
|
||||
info.length,
|
||||
&relative_end)))
|
||||
&& ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (args[1],
|
||||
info.length,
|
||||
&relative_end)))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
@@ -2059,7 +2061,7 @@ ecma_builtin_typedarray_prototype_includes (ecma_value_t this_arg, /**< this arg
|
||||
|
||||
if (args_number > 1)
|
||||
{
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (args[1], info.length, &from_index)))
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (args[1], info.length, &from_index)))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user