[API] Add RegExp C API (#2542)

This patch supports creating a RegExp object through the C API.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
This commit is contained in:
Daniel Balla
2018-11-19 12:18:00 +00:00
committed by László Langó
parent 47fa5904b1
commit 704eb45cb8
7 changed files with 227 additions and 15 deletions
@@ -110,9 +110,15 @@ ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /*
ECMA_FINALIZE (flags_str_value);
}
uint16_t flags = 0;
if (ecma_is_value_empty (ret_value) && (flags_string_p != NULL))
{
ret_value = re_parse_regexp_flags (flags_string_p, &flags);
}
if (ecma_is_value_empty (ret_value))
{
ret_value = ecma_op_create_regexp_object (pattern_string_p, flags_string_p);
ret_value = ecma_op_create_regexp_object (pattern_string_p, flags);
}
if (pattern_string_p != NULL)
@@ -249,22 +249,10 @@ ecma_op_create_regexp_object_from_bytecode (re_compiled_code_t *bytecode_p) /**<
*/
ecma_value_t
ecma_op_create_regexp_object (ecma_string_t *pattern_p, /**< input pattern */
ecma_string_t *flags_str_p) /**< flags */
uint16_t flags) /**< flags */
{
JERRY_ASSERT (pattern_p != NULL);
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
uint16_t flags = 0;
if (flags_str_p != NULL)
{
ECMA_TRY_CATCH (empty, re_parse_regexp_flags (flags_str_p, &flags), ret_value);
ECMA_FINALIZE (empty);
if (!ecma_is_value_empty (ret_value))
{
return ret_value;
}
}
ecma_object_t *re_prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE);
@@ -30,6 +30,8 @@
/**
* RegExp flags
* Note:
* This enum has to be kept in sync with jerry_regexp_flags_t.
*/
typedef enum
{
@@ -53,7 +55,7 @@ typedef struct
} re_matcher_ctx_t;
ecma_value_t ecma_op_create_regexp_object_from_bytecode (re_compiled_code_t *bytecode_p);
ecma_value_t ecma_op_create_regexp_object (ecma_string_t *pattern_p, ecma_string_t *flags_str_p);
ecma_value_t ecma_op_create_regexp_object (ecma_string_t *pattern_p, uint16_t flags);
ecma_value_t ecma_regexp_exec_helper (ecma_value_t regexp_value, ecma_value_t input_string, bool ignore_global);
ecma_value_t ecma_regexp_read_pattern_str_helper (ecma_value_t pattern_arg, ecma_string_t **pattern_string_p);
ecma_char_t re_canonicalize (ecma_char_t ch, bool is_ignorecase);