5555#define RE_GLOBAL_START_IDX 0
5656#define RE_GLOBAL_END_IDX 1
5757
58+ /**
59+ * Check if a RegExp opcode is a capture group or not
60+ */
61+ #define RE_IS_CAPTURE_GROUP (x ) (((x) < RE_OP_NON_CAPTURE_GROUP_START) ? 1 : 0)
62+
5863/**
5964 * Parse RegExp flags (global, ignoreCase, multiline)
6065 *
6166 * See also: ECMA-262 v5, 15.10.4.1
6267 *
63- * @return ecma value
68+ * @return empty ecma value - if parsed successfully
69+ * error ecma value - otherwise
70+ *
6471 * Returned value must be freed with ecma_free_value
6572 */
6673ecma_value_t
@@ -123,7 +130,7 @@ re_parse_regexp_flags (ecma_string_t *flags_str_p, /**< Input string with flags
123130 return ret_value ;
124131} /* re_parse_regexp_flags */
125132
126- /*
133+ /**
127134 * Initializes the source, global, ignoreCase, multiline, and lastIndex properties of RegExp instance.
128135 */
129136void
@@ -223,11 +230,11 @@ re_initialize_props (ecma_object_t *re_obj_p, /**< RegExp obejct */
223230 *
224231 * See also: ECMA-262 v5, 15.10.4.1
225232 *
226- * @return ecma value
233+ * @return constructed RegExp object
227234 * Returned value must be freed with ecma_free_value
228235 */
229236ecma_value_t
230- ecma_op_create_regexp_object_from_bytecode (re_compiled_code_t * bytecode_p ) /**< input pattern */
237+ ecma_op_create_regexp_object_from_bytecode (re_compiled_code_t * bytecode_p ) /**< RegExp bytecode */
231238{
232239 JERRY_ASSERT (bytecode_p != NULL );
233240
@@ -259,7 +266,9 @@ ecma_op_create_regexp_object_from_bytecode (re_compiled_code_t *bytecode_p) /**<
259266 *
260267 * See also: ECMA-262 v5, 15.10.4.1
261268 *
262- * @return ecma value
269+ * @return constructed RegExp object - if pattern and flags were parsed successfully
270+ * error ecma value - otherwise
271+ *
263272 * Returned value must be freed with ecma_free_value
264273 */
265274ecma_value_t
@@ -367,8 +376,10 @@ re_canonicalize (ecma_char_t ch, /**< character */
367376 * See also:
368377 * ECMA-262 v5, 15.10.2.1
369378 *
370- * @return ecma value
371- * Returned value must be freed with ecma_free_value
379+ * @return true - if matched
380+ * false - otherwise
381+ *
382+ * May raise error, so returned value must be freed with ecma_free_value
372383 */
373384static ecma_value_t
374385re_match_regexp (re_matcher_ctx_t * re_ctx_p , /**< RegExp matcher context */
@@ -400,7 +411,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
400411 }
401412
402413 bool is_ignorecase = re_ctx_p -> flags & RE_FLAG_IGNORE_CASE ;
403- ecma_char_t ch1 = (ecma_char_t ) re_get_value (& bc_p ); /* Already canonicalized. */
414+ ecma_char_t ch1 = (ecma_char_t ) re_get_char (& bc_p ); /* Already canonicalized. */
404415 ecma_char_t ch2 = re_canonicalize (lit_utf8_read_next (& str_curr_p ), is_ignorecase );
405416 JERRY_DDLOG ("Character matching %d to %d: " , ch1 , ch2 );
406417
@@ -613,8 +624,8 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
613624
614625 while (num_of_ranges )
615626 {
616- ecma_char_t ch1 = re_canonicalize (( ecma_char_t ) re_get_value (& bc_p ), is_ignorecase );
617- ecma_char_t ch2 = re_canonicalize (( ecma_char_t ) re_get_value (& bc_p ), is_ignorecase );
627+ ecma_char_t ch1 = re_canonicalize (re_get_char (& bc_p ), is_ignorecase );
628+ ecma_char_t ch2 = re_canonicalize (re_get_char (& bc_p ), is_ignorecase );
618629 JERRY_DDLOG ("num_of_ranges=%d, ch1=%d, ch2=%d, curr_ch=%d; " ,
619630 num_of_ranges , ch1 , ch2 , curr_ch );
620631
@@ -698,6 +709,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
698709 uint32_t offset = re_get_value (& bc_p );
699710 lit_utf8_byte_t * sub_str_p = NULL ;
700711 ecma_value_t match_value = re_match_regexp (re_ctx_p , bc_p , str_curr_p , & sub_str_p );
712+
701713 if (ecma_is_value_true (match_value ))
702714 {
703715 * out_str_p = sub_str_p ;
@@ -707,6 +719,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
707719 {
708720 return match_value ;
709721 }
722+
710723 bc_p += offset ;
711724 old_bc_p = bc_p ;
712725 }
@@ -839,6 +852,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
839852 {
840853 offset = re_get_value (& bc_p );
841854 ecma_value_t match_value = re_match_regexp (re_ctx_p , bc_p , str_curr_p , & sub_str_p );
855+
842856 if (ecma_is_value_true (match_value ))
843857 {
844858 * out_str_p = sub_str_p ;
@@ -848,6 +862,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
848862 {
849863 return match_value ;
850864 }
865+
851866 bc_p += offset ;
852867 old_bc_p = bc_p ;
853868 }
@@ -915,6 +930,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
915930
916931 lit_utf8_byte_t * sub_str_p = NULL ;
917932 ecma_value_t match_value = re_match_regexp (re_ctx_p , bc_p , str_curr_p , & sub_str_p );
933+
918934 if (ecma_is_value_true (match_value ))
919935 {
920936 * out_str_p = sub_str_p ;
@@ -1225,7 +1241,13 @@ re_set_result_array_properties (ecma_object_t *array_obj_p, /**< result array */
12251241 * RegExp helper function to start the recursive matching algorithm
12261242 * and create the result Array object
12271243 *
1228- * @return ecma value
1244+ * See also:
1245+ * ECMA-262 v5, 15.10.6.2
1246+ *
1247+ * @return array object - if matched
1248+ * null - otherwise
1249+ *
1250+ * May raise error.
12291251 * Returned value must be freed with ecma_free_value
12301252 */
12311253ecma_value_t
@@ -1475,4 +1497,4 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
14751497 * @}
14761498 */
14771499
1478- #endif /* CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN */
1500+ #endif /* ! CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN */
0 commit comments