@@ -1176,19 +1176,45 @@ re_set_result_array_properties (ecma_object_t *array_obj_p, /**< result array */
1176
1176
* Returned value must be freed with ecma_free_completion_value
1177
1177
*/
1178
1178
ecma_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 */
1182
1182
{
1183
1183
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
+
1184
1204
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 ;
1187
1207
re_ctx.match_limit = 0 ;
1188
1208
re_ctx.recursion_depth = 0 ;
1189
1209
1190
1210
/* 1. Read bytecode header and init regexp matcher context. */
1191
1211
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
+
1192
1218
JERRY_DDLOG (" Exec with flags [global: %d, ignoreCase: %d, multiline: %d]\n " ,
1193
1219
re_ctx.flags & RE_FLAG_GLOBAL,
1194
1220
re_ctx.flags & RE_FLAG_IGNORE_CASE,
@@ -1217,22 +1243,22 @@ ecma_regexp_exec_helper (ecma_object_t *obj_p, /**< RegExp object */
1217
1243
bool is_match = false ;
1218
1244
re_ctx.num_of_iterations_p = num_of_iter_p;
1219
1245
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 );
1221
1247
1222
- if (iter_p-> buf_p && re_ctx.flags & RE_FLAG_GLOBAL)
1248
+ if (iterator. buf_p && ( re_ctx.flags & RE_FLAG_GLOBAL) )
1223
1249
{
1224
1250
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);
1226
1252
1227
1253
ECMA_OP_TO_NUMBER_TRY_CATCH (lastindex_num, lastindex_prop_p->u .named_data_property .value , ret_value)
1228
1254
index = ecma_number_to_int32 (lastindex_num);
1229
1255
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 )
1232
1258
&& index <= (int32_t ) input_str_len
1233
1259
&& index > 0 )
1234
1260
{
1235
- lit_utf8_iterator_advance (iter_p , (ecma_length_t ) index);
1261
+ lit_utf8_iterator_advance (&iterator , (ecma_length_t ) index);
1236
1262
}
1237
1263
ECMA_OP_TO_NUMBER_FINALIZE (lastindex_num);
1238
1264
ecma_deref_ecma_string (magic_str_p);
@@ -1245,42 +1271,45 @@ ecma_regexp_exec_helper (ecma_object_t *obj_p, /**< RegExp object */
1245
1271
{
1246
1272
if (index < 0 || index > (int32_t ) input_str_len)
1247
1273
{
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
+ }
1254
1283
1255
1284
is_match = false ;
1256
1285
break ;
1257
1286
}
1258
1287
else
1259
1288
{
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);
1261
1290
1262
1291
if (ecma_is_value_true (match_value))
1263
1292
{
1264
1293
is_match = true ;
1265
1294
break ;
1266
1295
}
1267
1296
1268
- if (!lit_utf8_iterator_is_eos (iter_p ))
1297
+ if (!lit_utf8_iterator_is_eos (&iterator ))
1269
1298
{
1270
- lit_utf8_iterator_advance (iter_p , 1 );
1299
+ lit_utf8_iterator_advance (&iterator , 1 );
1271
1300
}
1272
1301
index++;
1273
1302
1274
1303
ECMA_FINALIZE (match_value);
1275
1304
}
1276
1305
}
1277
1306
1278
- if (iter_p-> buf_p && re_ctx.flags & RE_FLAG_GLOBAL)
1307
+ if (iterator. buf_p && ( re_ctx.flags & RE_FLAG_GLOBAL) )
1279
1308
{
1280
1309
ecma_string_t *magic_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL);
1281
1310
ecma_number_t *lastindex_num_p = ecma_alloc_number ();
1282
1311
*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 );
1284
1313
ecma_dealloc_number (lastindex_num_p);
1285
1314
ecma_deref_ecma_string (magic_str_p);
1286
1315
}
@@ -1299,9 +1328,9 @@ ecma_regexp_exec_helper (ecma_object_t *obj_p, /**< RegExp object */
1299
1328
{
1300
1329
ecma_string_t *index_str_p = ecma_new_ecma_string_from_uint32 (i / 2 );
1301
1330
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 */
1303
1332
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 ))
1305
1334
&& re_ctx.saved_p [i + 1 ].buf_pos .offset >= re_ctx.saved_p [i].buf_pos .offset )
1306
1335
{
1307
1336
ecma_length_t capture_str_len;
@@ -1336,8 +1365,10 @@ ecma_regexp_exec_helper (ecma_object_t *obj_p, /**< RegExp object */
1336
1365
ret_value = ecma_make_normal_completion_value (ecma_make_simple_value (ECMA_SIMPLE_VALUE_NULL));
1337
1366
}
1338
1367
}
1368
+
1339
1369
MEM_FINALIZE_LOCAL_ARRAY (num_of_iter_p);
1340
1370
MEM_FINALIZE_LOCAL_ARRAY (saved_p);
1371
+ MEM_FINALIZE_LOCAL_ARRAY (input_utf8_buffer_p);
1341
1372
1342
1373
return ret_value;
1343
1374
} /* ecma_regexp_exec_helper */
0 commit comments