Fix AdvanceStringIndex to return an ecma_length_t (#4100)

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai daniel.batyai@h-lab.eu
This commit is contained in:
Dániel Bátyai 2020-08-04 09:08:34 +02:00 committed by GitHub
parent 4ce4b617fd
commit be9dbeffdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 27 deletions

View File

@ -2929,22 +2929,14 @@ ecma_stringbuilder_destroy (ecma_stringbuilder_t *builder_p) /**< string builder
*
* @return uint32_t - the proper character index based on the operation
*/
uint32_t
ecma_length_t
ecma_op_advance_string_index (ecma_string_t *str_p, /**< input string */
ecma_length_t index_num, /**< given character index */
ecma_length_t index, /**< given character index */
bool is_unicode) /**< true - if regexp object's "unicode" flag is set
false - otherwise */
{
JERRY_ASSERT (index_num <= ECMA_NUMBER_MAX_SAFE_INTEGER);
/* Note: The internal string length limit is 2^32 */
if (JERRY_UNLIKELY (index_num >= (UINT32_MAX - 1)))
{
return UINT32_MAX;
}
uint32_t index = (uint32_t) index_num;
uint32_t next_index = index + 1;
JERRY_ASSERT (index <= ECMA_NUMBER_MAX_SAFE_INTEGER);
ecma_length_t next_index = index + 1;
if (!is_unicode)
{
@ -2958,16 +2950,17 @@ ecma_op_advance_string_index (ecma_string_t *str_p, /**< input string */
return next_index;
}
ecma_char_t first = ecma_string_get_char_at_pos (str_p, index);
JERRY_ASSERT (index < UINT32_MAX);
ecma_char_t first = ecma_string_get_char_at_pos (str_p, (lit_utf8_size_t) index);
if (first < LIT_UTF16_HIGH_SURROGATE_MIN || first > LIT_UTF16_HIGH_SURROGATE_MAX)
if (!lit_is_code_point_utf16_high_surrogate (first))
{
return next_index;
}
ecma_char_t second = ecma_string_get_char_at_pos (str_p, next_index);
ecma_char_t second = ecma_string_get_char_at_pos (str_p, (lit_utf8_size_t) next_index);
if (second < LIT_UTF16_LOW_SURROGATE_MIN || second > LIT_UTF16_LOW_SURROGATE_MAX)
if (!lit_is_code_point_utf16_low_surrogate (second))
{
return next_index;
}

View File

@ -314,7 +314,7 @@ lit_magic_string_id_t ecma_get_typeof_lit_id (ecma_value_t value);
#if ENABLED (JERRY_ESNEXT)
ecma_string_t *ecma_new_symbol_from_descriptor_string (ecma_value_t string_desc);
bool ecma_prop_name_is_symbol (ecma_string_t *string_p);
uint32_t ecma_op_advance_string_index (ecma_string_t *str_p, ecma_length_t index_num, bool is_unicode);
ecma_length_t ecma_op_advance_string_index (ecma_string_t *str_p, ecma_length_t index_num, bool is_unicode);
#endif /* ENABLED (JERRY_ESNEXT) */
#if ENABLED (JERRY_BUILTIN_MAP) || ENABLED (JERRY_BUILTIN_SET)
ecma_string_t *ecma_new_map_key_string (ecma_value_t value);

View File

@ -2254,8 +2254,8 @@ ecma_regexp_split_helper (ecma_value_t this_arg, /**< this value */
}
/* 23. */
uint32_t current_index = 0;
uint32_t previous_index = 0;
ecma_length_t current_index = 0;
ecma_length_t previous_index = 0;
ecma_string_t *const lastindex_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL);
@ -2265,7 +2265,7 @@ ecma_regexp_split_helper (ecma_value_t this_arg, /**< this value */
/* 24.a-b. */
result = ecma_op_object_put (splitter_obj_p,
lastindex_str_p,
ecma_make_uint32_value (current_index),
ecma_make_length_value (current_index),
true);
if (ECMA_IS_VALUE_ERROR (result))
@ -2325,7 +2325,10 @@ ecma_regexp_split_helper (ecma_value_t this_arg, /**< this value */
}
/* 24.f.iv.1-4. */
ecma_string_t *const split_str_p = ecma_string_substr (string_p, previous_index, current_index);
JERRY_ASSERT (previous_index <= string_length && current_index <= string_length);
ecma_string_t *const split_str_p = ecma_string_substr (string_p,
(lit_utf8_size_t) previous_index,
(lit_utf8_size_t) current_index);
result = ecma_builtin_helper_def_prop_by_index (array_p,
array_length++,
@ -2343,8 +2346,7 @@ ecma_regexp_split_helper (ecma_value_t this_arg, /**< this value */
}
/* 24.f.iv.6. */
JERRY_ASSERT (end_index <= UINT32_MAX);
previous_index = (uint32_t) end_index;
previous_index = end_index;
/* 24.f.iv.7-8. */
ecma_length_t match_length;
@ -2395,7 +2397,8 @@ ecma_regexp_split_helper (ecma_value_t this_arg, /**< this value */
ecma_deref_object (match_array_p);
}
ecma_string_t *const end_str_p = ecma_string_substr (string_p, previous_index, string_length);
JERRY_ASSERT (previous_index <= string_length);
ecma_string_t *const end_str_p = ecma_string_substr (string_p, (lit_utf8_size_t) previous_index, string_length);
result = ecma_builtin_helper_def_prop_by_index (array_p,
array_length++,
ecma_make_string_value (end_str_p),
@ -3484,11 +3487,11 @@ ecma_regexp_match_helper (ecma_value_t this_arg, /**< this argument */
goto result_cleanup;
}
uint32_t next_index = ecma_op_advance_string_index (str_p, index, full_unicode);
index = ecma_op_advance_string_index (str_p, index, full_unicode);
ecma_value_t next_set_status = ecma_op_object_put (obj_p,
ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL),
ecma_make_uint32_value (next_index),
ecma_make_length_value (index),
true);
#else /* !ENABLED (JERRY_ESNEXT) */
ecma_number_t next_index = ecma_get_number_from_value (this_index);

View File

@ -1926,7 +1926,6 @@
<test id="built-ins/RegExp/prototype/Symbol.matchAll/this-tolength-lastindex-throws.js"><reason></reason></test>
<test id="built-ins/RegExp/prototype/Symbol.matchAll/this-tostring-flags-throws.js"><reason></reason></test>
<test id="built-ins/RegExp/prototype/Symbol.matchAll/this-tostring-flags.js"><reason></reason></test>
<test id="built-ins/RegExp/prototype/Symbol.replace/coerce-lastindex.js"><reason></reason></test>
<test id="built-ins/RegExp/prototype/Symbol.replace/named-groups-fn.js"><reason></reason></test>
<test id="built-ins/RegExp/prototype/Symbol.replace/named-groups.js"><reason></reason></test>
<test id="built-ins/RegExp/prototype/Symbol.replace/poisoned-stdlib.js"><reason></reason></test>