Added RegExp dotAll flag (#4000)

JerryScript-DCO-1.0-Signed-off-by: bence gabor kis kisbg@inf.u-szeged.hu
This commit is contained in:
kisbg
2020-07-24 13:42:57 +02:00
committed by GitHub
parent cf097ca16b
commit d39a076b2e
11 changed files with 87 additions and 11 deletions
@@ -98,6 +98,13 @@ ecma_regexp_parse_flags (ecma_string_t *flags_str_p, /**< Input string with flag
flag = RE_FLAG_UNICODE;
break;
}
#if ENABLED (JERRY_ESNEXT)
case 's':
{
flag = RE_FLAG_DOTALL;
break;
}
#endif /* ENABLED (JERRY_ESNEXT) */
default:
{
flag = RE_FLAG_EMPTY;
@@ -1505,7 +1512,9 @@ class_found:
const lit_code_point_t cp = ecma_regexp_unicode_advance (&str_curr_p, re_ctx_p->input_end_p);
if (JERRY_UNLIKELY (cp <= LIT_UTF16_CODE_UNIT_MAX && lit_char_is_line_terminator ((ecma_char_t) cp)))
if (!(re_ctx_p->flags & RE_FLAG_DOTALL)
&& JERRY_UNLIKELY (cp <= LIT_UTF16_CODE_UNIT_MAX
&& lit_char_is_line_terminator ((ecma_char_t) cp)))
{
goto fail;
}
@@ -1521,8 +1530,13 @@ class_found:
}
const ecma_char_t ch = lit_cesu8_read_next (&str_curr_p);
#if !ENABLED (JERRY_ESNEXT)
bool has_dot_all_flag = false;
#else /* ENABLED (JERRY_ESNEXT) */
bool has_dot_all_flag = (re_ctx_p->flags & RE_FLAG_DOTALL) != 0;
#endif /* !ENABLED (JERRY_ESNEXT) */
if (lit_char_is_line_terminator (ch))
if (!has_dot_all_flag && lit_char_is_line_terminator (ch))
{
goto fail;
}
@@ -40,7 +40,8 @@ typedef enum
RE_FLAG_IGNORE_CASE = (1u << 2), /**< ECMA-262 v5, 15.10.7.3 */
RE_FLAG_MULTILINE = (1u << 3), /**< ECMA-262 v5, 15.10.7.4 */
RE_FLAG_STICKY = (1u << 4), /**< ECMA-262 v6, 21.2.5.12 */
RE_FLAG_UNICODE = (1u << 5) /**< ECMA-262 v6, 21.2.5.15 */
RE_FLAG_UNICODE = (1u << 5), /**< ECMA-262 v6, 21.2.5.15 */
RE_FLAG_DOTALL = (1u << 6) /**< ECMA-262 v9, 21.2.5.3 */
/* Bits from bit 13 is reserved for function types (see CBC_FUNCTION_TYPE_SHIFT). */
} ecma_regexp_flags_t;