@@ -1176,19 +1176,45 @@ re_set_result_array_properties (ecma_object_t *array_obj_p, /**< result array */
11761176 * Returned value must be freed with ecma_free_completion_value
11771177 */
11781178ecma_completion_value_t
1179- ecma_regexp_exec_helper (ecma_object_t *obj_p , /* *< RegExp object */
1180- re_bytecode_t *bc_p , /* *< start of the RegExp bytecode */
1181- lit_utf8_iterator_t *iter_p ) /* *< input string iterator */
1179+ ecma_regexp_exec_helper (ecma_value_t regexp_value , /* *< RegExp object */
1180+ ecma_value_t input_string , /* *< input string */
1181+ bool ignore_global ) /* *< ignore global flag */
11821182{
11831183 ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
1184+
1185+ JERRY_ASSERT (ecma_is_value_object (regexp_value));
1186+ JERRY_ASSERT (ecma_is_value_string (input_string));
1187+
1188+ ecma_object_t *regexp_object_p = ecma_get_object_from_value (regexp_value);
1189+
1190+ JERRY_ASSERT (ecma_object_get_class_name (regexp_object_p) == LIT_MAGIC_STRING_REGEXP_UL);
1191+
1192+ ecma_property_t *bytecode_prop_p = ecma_get_internal_property (regexp_object_p,
1193+ ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE);
1194+ re_bytecode_t *bc_p = ECMA_GET_POINTER (re_bytecode_t , bytecode_prop_p->u .internal_property .value );
1195+
1196+ ecma_string_t *input_string_p = ecma_get_string_from_value (input_string);
1197+ lit_utf8_size_t input_string_size = ecma_string_get_size (input_string_p);
1198+
1199+ MEM_DEFINE_LOCAL_ARRAY (input_utf8_buffer_p, input_string_size, lit_utf8_byte_t );
1200+
1201+ ecma_string_to_utf8_string (input_string_p, input_utf8_buffer_p, (ssize_t ) input_string_size);
1202+ lit_utf8_iterator_t iterator = lit_utf8_iterator_create (input_utf8_buffer_p, input_string_size);
1203+
11841204 re_matcher_ctx_t re_ctx;
1185- re_ctx.input_start_p = iter_p-> buf_p ;
1186- re_ctx.input_end_p = iter_p-> buf_p + iter_p-> buf_size ;
1205+ re_ctx.input_start_p = iterator. buf_p ;
1206+ re_ctx.input_end_p = iterator. buf_p + iterator. buf_size ;
11871207 re_ctx.match_limit = 0 ;
11881208 re_ctx.recursion_depth = 0 ;
11891209
11901210 /* 1. Read bytecode header and init regexp matcher context. */
11911211 re_ctx.flags = (uint8_t ) re_get_value (&bc_p);
1212+
1213+ if (ignore_global)
1214+ {
1215+ re_ctx.flags &= (uint8_t ) ~RE_FLAG_GLOBAL;
1216+ }
1217+
11921218 JERRY_DDLOG (" Exec with flags [global: %d, ignoreCase: %d, multiline: %d]\n " ,
11931219 re_ctx.flags & RE_FLAG_GLOBAL,
11941220 re_ctx.flags & RE_FLAG_IGNORE_CASE,
@@ -1217,22 +1243,22 @@ ecma_regexp_exec_helper (ecma_object_t *obj_p, /**< RegExp object */
12171243 bool is_match = false ;
12181244 re_ctx.num_of_iterations_p = num_of_iter_p;
12191245 int32_t index = 0 ;
1220- ecma_length_t input_str_len = lit_utf8_string_length (iter_p-> buf_p , iter_p-> buf_size );
1246+ ecma_length_t input_str_len = lit_utf8_string_length (iterator. buf_p , iterator. buf_size );
12211247
1222- if (iter_p-> buf_p && re_ctx.flags & RE_FLAG_GLOBAL)
1248+ if (iterator. buf_p && ( re_ctx.flags & RE_FLAG_GLOBAL) )
12231249 {
12241250 ecma_string_t *magic_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL);
1225- ecma_property_t *lastindex_prop_p = ecma_op_object_get_property (obj_p , magic_str_p);
1251+ ecma_property_t *lastindex_prop_p = ecma_op_object_get_property (regexp_object_p , magic_str_p);
12261252
12271253 ECMA_OP_TO_NUMBER_TRY_CATCH (lastindex_num, lastindex_prop_p->u .named_data_property .value , ret_value)
12281254 index = ecma_number_to_int32 (lastindex_num);
12291255
1230- JERRY_ASSERT (iter_p-> buf_pos .offset == 0 && !iter_p-> buf_pos .is_non_bmp_middle );
1231- if (!lit_utf8_iterator_is_eos (iter_p )
1256+ JERRY_ASSERT (iterator. buf_pos .offset == 0 && !iterator. buf_pos .is_non_bmp_middle );
1257+ if (!lit_utf8_iterator_is_eos (&iterator )
12321258 && index <= (int32_t ) input_str_len
12331259 && index > 0 )
12341260 {
1235- lit_utf8_iterator_advance (iter_p , (ecma_length_t ) index);
1261+ lit_utf8_iterator_advance (&iterator , (ecma_length_t ) index);
12361262 }
12371263 ECMA_OP_TO_NUMBER_FINALIZE (lastindex_num);
12381264 ecma_deref_ecma_string (magic_str_p);
@@ -1245,42 +1271,45 @@ ecma_regexp_exec_helper (ecma_object_t *obj_p, /**< RegExp object */
12451271 {
12461272 if (index < 0 || index > (int32_t ) input_str_len)
12471273 {
1248- ecma_string_t *magic_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL);
1249- ecma_number_t *lastindex_num_p = ecma_alloc_number ();
1250- *lastindex_num_p = ECMA_NUMBER_ZERO;
1251- ecma_op_object_put (obj_p, magic_str_p, ecma_make_number_value (lastindex_num_p), true );
1252- ecma_dealloc_number (lastindex_num_p);
1253- ecma_deref_ecma_string (magic_str_p);
1274+ if (re_ctx.flags & RE_FLAG_GLOBAL)
1275+ {
1276+ ecma_string_t *magic_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL);
1277+ ecma_number_t *lastindex_num_p = ecma_alloc_number ();
1278+ *lastindex_num_p = ECMA_NUMBER_ZERO;
1279+ ecma_op_object_put (regexp_object_p, magic_str_p, ecma_make_number_value (lastindex_num_p), true );
1280+ ecma_dealloc_number (lastindex_num_p);
1281+ ecma_deref_ecma_string (magic_str_p);
1282+ }
12541283
12551284 is_match = false ;
12561285 break ;
12571286 }
12581287 else
12591288 {
1260- ECMA_TRY_CATCH (match_value, re_match_regexp (&re_ctx, bc_p, *iter_p , &sub_iter), ret_value);
1289+ ECMA_TRY_CATCH (match_value, re_match_regexp (&re_ctx, bc_p, iterator , &sub_iter), ret_value);
12611290
12621291 if (ecma_is_value_true (match_value))
12631292 {
12641293 is_match = true ;
12651294 break ;
12661295 }
12671296
1268- if (!lit_utf8_iterator_is_eos (iter_p ))
1297+ if (!lit_utf8_iterator_is_eos (&iterator ))
12691298 {
1270- lit_utf8_iterator_advance (iter_p , 1 );
1299+ lit_utf8_iterator_advance (&iterator , 1 );
12711300 }
12721301 index++;
12731302
12741303 ECMA_FINALIZE (match_value);
12751304 }
12761305 }
12771306
1278- if (iter_p-> buf_p && re_ctx.flags & RE_FLAG_GLOBAL)
1307+ if (iterator. buf_p && ( re_ctx.flags & RE_FLAG_GLOBAL) )
12791308 {
12801309 ecma_string_t *magic_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL);
12811310 ecma_number_t *lastindex_num_p = ecma_alloc_number ();
12821311 *lastindex_num_p = sub_iter.buf_pos .offset ;
1283- ecma_op_object_put (obj_p , magic_str_p, ecma_make_number_value (lastindex_num_p), true );
1312+ ecma_op_object_put (regexp_object_p , magic_str_p, ecma_make_number_value (lastindex_num_p), true );
12841313 ecma_dealloc_number (lastindex_num_p);
12851314 ecma_deref_ecma_string (magic_str_p);
12861315 }
@@ -1299,9 +1328,9 @@ ecma_regexp_exec_helper (ecma_object_t *obj_p, /**< RegExp object */
12991328 {
13001329 ecma_string_t *index_str_p = ecma_new_ecma_string_from_uint32 (i / 2 );
13011330
1302- /* Note: 'iter_p-> buf_p == NULL' means the input is empty string */
1331+ /* Note: 'iterator. buf_p == NULL' means the input is empty string */
13031332 if (((re_ctx.saved_p [i].buf_p && re_ctx.saved_p [i + 1 ].buf_p )
1304- || (!iter_p-> buf_p && !re_ctx.saved_p [i].buf_p && !re_ctx.saved_p [i + 1 ].buf_p ))
1333+ || (!iterator. buf_p && !re_ctx.saved_p [i].buf_p && !re_ctx.saved_p [i + 1 ].buf_p ))
13051334 && re_ctx.saved_p [i + 1 ].buf_pos .offset >= re_ctx.saved_p [i].buf_pos .offset )
13061335 {
13071336 ecma_length_t capture_str_len;
@@ -1336,8 +1365,10 @@ ecma_regexp_exec_helper (ecma_object_t *obj_p, /**< RegExp object */
13361365 ret_value = ecma_make_normal_completion_value (ecma_make_simple_value (ECMA_SIMPLE_VALUE_NULL));
13371366 }
13381367 }
1368+
13391369 MEM_FINALIZE_LOCAL_ARRAY (num_of_iter_p);
13401370 MEM_FINALIZE_LOCAL_ARRAY (saved_p);
1371+ MEM_FINALIZE_LOCAL_ARRAY (input_utf8_buffer_p);
13411372
13421373 return ret_value;
13431374} /* ecma_regexp_exec_helper */
0 commit comments