@@ -52,8 +52,13 @@ re_append_char_class (void *re_ctx_p, /**< RegExp compiler context */
52
52
53
53
/**
54
54
* Insert simple atom iterator
55
+ *
56
+ * @return empty ecma value - if inserted successfully
57
+ * error ecma value - otherwise
58
+ *
59
+ * Returned value must be freed with ecma_free_value
55
60
*/
56
- static void
61
+ static ecma_value_t
57
62
re_insert_simple_iterator (re_compiler_ctx_t * re_ctx_p , /**< RegExp compiler context */
58
63
uint32_t new_atom_start_offset ) /**< atom start offset */
59
64
{
@@ -63,7 +68,15 @@ re_insert_simple_iterator (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler con
63
68
64
69
qmin = re_ctx_p -> current_token .qmin ;
65
70
qmax = re_ctx_p -> current_token .qmax ;
66
- JERRY_ASSERT (qmin <= qmax );
71
+
72
+ if (qmin == 1 && qmax == 1 )
73
+ {
74
+ return ECMA_VALUE_EMPTY ;
75
+ }
76
+ else if (qmin > qmax )
77
+ {
78
+ return ecma_raise_syntax_error (ECMA_ERR_MSG ("RegExp quantifier error: qmin > qmax." ));
79
+ }
67
80
68
81
/* TODO: optimize bytecode length. Store 0 rather than INF */
69
82
@@ -83,6 +96,8 @@ re_insert_simple_iterator (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler con
83
96
{
84
97
re_insert_opcode (re_ctx_p -> bytecode_ctx_p , offset , RE_OP_NON_GREEDY_ITERATOR );
85
98
}
99
+
100
+ return ECMA_VALUE_EMPTY ;
86
101
} /* re_insert_simple_iterator */
87
102
88
103
/**
@@ -271,21 +286,15 @@ re_parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context
271
286
re_append_char (bc_ctx_p , re_canonicalize ((ecma_char_t ) re_ctx_p -> current_token .value ,
272
287
re_ctx_p -> flags & RE_FLAG_IGNORE_CASE ));
273
288
274
- if ((re_ctx_p -> current_token .qmin != 1 ) || (re_ctx_p -> current_token .qmax != 1 ))
275
- {
276
- re_insert_simple_iterator (re_ctx_p , new_atom_start_offset );
277
- }
289
+ ret_value = re_insert_simple_iterator (re_ctx_p , new_atom_start_offset );
278
290
break ;
279
291
}
280
292
case RE_TOK_PERIOD :
281
293
{
282
294
JERRY_TRACE_MSG ("Compile a period\n" );
283
295
re_append_opcode (bc_ctx_p , RE_OP_PERIOD );
284
296
285
- if ((re_ctx_p -> current_token .qmin != 1 ) || (re_ctx_p -> current_token .qmax != 1 ))
286
- {
287
- re_insert_simple_iterator (re_ctx_p , new_atom_start_offset );
288
- }
297
+ ret_value = re_insert_simple_iterator (re_ctx_p , new_atom_start_offset );
289
298
break ;
290
299
}
291
300
case RE_TOK_ALTERNATIVE :
@@ -387,21 +396,17 @@ re_parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context
387
396
: RE_OP_CHAR_CLASS );
388
397
uint32_t offset = re_get_bytecode_length (re_ctx_p -> bytecode_ctx_p );
389
398
390
- ECMA_TRY_CATCH (empty_value ,
391
- re_parse_char_class (re_ctx_p -> parser_ctx_p ,
392
- re_append_char_class ,
393
- re_ctx_p ,
394
- & (re_ctx_p -> current_token )),
395
- ret_value );
396
- re_insert_u32 (bc_ctx_p , offset , re_ctx_p -> parser_ctx_p -> num_of_classes );
399
+ ret_value = re_parse_char_class (re_ctx_p -> parser_ctx_p ,
400
+ re_append_char_class ,
401
+ re_ctx_p ,
402
+ & (re_ctx_p -> current_token ));
397
403
398
- if (( re_ctx_p -> current_token . qmin != 1 ) || ( re_ctx_p -> current_token . qmax != 1 ))
404
+ if (! ECMA_IS_VALUE_ERROR ( ret_value ))
399
405
{
400
- re_insert_simple_iterator (re_ctx_p , new_atom_start_offset );
406
+ re_insert_u32 (bc_ctx_p , offset , re_ctx_p -> parser_ctx_p -> num_of_classes );
407
+ ret_value = re_insert_simple_iterator (re_ctx_p , new_atom_start_offset );
401
408
}
402
409
403
- ECMA_FINALIZE (empty_value );
404
-
405
410
break ;
406
411
}
407
412
case RE_TOK_END_GROUP :
0 commit comments