From be9dbeffdbd6faa80d1158243e26462bb924a674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20B=C3=A1tyai?= Date: Tue, 4 Aug 2020 09:08:34 +0200 Subject: [PATCH] Fix AdvanceStringIndex to return an ecma_length_t (#4100) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai daniel.batyai@h-lab.eu --- jerry-core/ecma/base/ecma-helpers-string.c | 25 +++++++------------ jerry-core/ecma/base/ecma-helpers.h | 2 +- .../ecma/operations/ecma-regexp-object.c | 21 +++++++++------- tests/test262-esnext-excludelist.xml | 1 - 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/jerry-core/ecma/base/ecma-helpers-string.c b/jerry-core/ecma/base/ecma-helpers-string.c index 183ca6ab1..67b71f387 100644 --- a/jerry-core/ecma/base/ecma-helpers-string.c +++ b/jerry-core/ecma/base/ecma-helpers-string.c @@ -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; } diff --git a/jerry-core/ecma/base/ecma-helpers.h b/jerry-core/ecma/base/ecma-helpers.h index e75529c69..a4d796323 100644 --- a/jerry-core/ecma/base/ecma-helpers.h +++ b/jerry-core/ecma/base/ecma-helpers.h @@ -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); diff --git a/jerry-core/ecma/operations/ecma-regexp-object.c b/jerry-core/ecma/operations/ecma-regexp-object.c index 17d8876fa..160fb51ae 100644 --- a/jerry-core/ecma/operations/ecma-regexp-object.c +++ b/jerry-core/ecma/operations/ecma-regexp-object.c @@ -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); diff --git a/tests/test262-esnext-excludelist.xml b/tests/test262-esnext-excludelist.xml index 863a96c8a..e97347ebc 100644 --- a/tests/test262-esnext-excludelist.xml +++ b/tests/test262-esnext-excludelist.xml @@ -1926,7 +1926,6 @@ -