Reduce code duplication between RegExp.construct and [[Call]] (#2287)
JerryScript-DCO-1.0-Signed-off-by: Mátyás Mustoha mmatyas@inf.u-szeged.hu
This commit is contained in:
committed by
László Langó
parent
a76926623a
commit
63ce292173
@@ -159,28 +159,7 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this argument
|
||||
ecma_string_t *pattern_string_p = NULL;
|
||||
|
||||
/* Get source string. */
|
||||
if (!ecma_is_value_undefined (pattern_arg))
|
||||
{
|
||||
ECMA_TRY_CATCH (regexp_str_value,
|
||||
ecma_op_to_string (pattern_arg),
|
||||
ret_value);
|
||||
|
||||
if (ecma_string_is_empty (ecma_get_string_from_value (regexp_str_value)))
|
||||
{
|
||||
pattern_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
|
||||
}
|
||||
else
|
||||
{
|
||||
pattern_string_p = ecma_get_string_from_value (regexp_str_value);
|
||||
ecma_ref_ecma_string (pattern_string_p);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (regexp_str_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
pattern_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
|
||||
}
|
||||
ret_value = ecma_regexp_read_pattern_str_helper (pattern_arg, &pattern_string_p);
|
||||
|
||||
/* Parse flags. */
|
||||
if (ecma_is_value_empty (ret_value) && !ecma_is_value_undefined (flags_arg))
|
||||
|
||||
@@ -96,28 +96,7 @@ ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /*
|
||||
ecma_string_t *pattern_string_p = NULL;
|
||||
ecma_string_t *flags_string_p = NULL;
|
||||
|
||||
if (!ecma_is_value_undefined (pattern_value))
|
||||
{
|
||||
ECMA_TRY_CATCH (regexp_str_value,
|
||||
ecma_op_to_string (pattern_value),
|
||||
ret_value);
|
||||
|
||||
if (ecma_string_is_empty (ecma_get_string_from_value (regexp_str_value)))
|
||||
{
|
||||
pattern_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
|
||||
}
|
||||
else
|
||||
{
|
||||
pattern_string_p = ecma_get_string_from_value (regexp_str_value);
|
||||
ecma_ref_ecma_string (pattern_string_p);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (regexp_str_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
pattern_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
|
||||
}
|
||||
ret_value = ecma_regexp_read_pattern_str_helper (pattern_value, &pattern_string_p);
|
||||
|
||||
if (ecma_is_value_empty (ret_value) && !ecma_is_value_undefined (flags_value))
|
||||
{
|
||||
|
||||
@@ -1427,6 +1427,44 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
|
||||
return ret_value;
|
||||
} /* ecma_regexp_exec_helper */
|
||||
|
||||
/**
|
||||
* Helper function for converting a RegExp pattern parameter to string.
|
||||
*
|
||||
* See also:
|
||||
* RegExp.compile
|
||||
* RegExp dispatch call
|
||||
*
|
||||
* @return empty value if success, error value otherwise
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_regexp_read_pattern_str_helper (ecma_value_t pattern_arg, /**< the RegExp pattern */
|
||||
ecma_string_t **pattern_string_p) /**< [out] ptr to the pattern string ptr */
|
||||
{
|
||||
if (!ecma_is_value_undefined (pattern_arg))
|
||||
{
|
||||
ecma_value_t regexp_str_value = ecma_op_to_string (pattern_arg);
|
||||
if (ECMA_IS_VALUE_ERROR (regexp_str_value))
|
||||
{
|
||||
return regexp_str_value;
|
||||
}
|
||||
|
||||
*pattern_string_p = ecma_get_string_from_value (regexp_str_value);
|
||||
if (!ecma_string_is_empty (*pattern_string_p))
|
||||
{
|
||||
ecma_ref_ecma_string (*pattern_string_p);
|
||||
}
|
||||
|
||||
ecma_free_value (regexp_str_value); // must be freed *after* ecma_ref_ecma_string
|
||||
}
|
||||
|
||||
if (!*pattern_string_p || ecma_string_is_empty (*pattern_string_p))
|
||||
{
|
||||
*pattern_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
|
||||
}
|
||||
return ECMA_VALUE_EMPTY;
|
||||
} /* ecma_regexp_read_pattern_str_helper */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
|
||||
@@ -55,6 +55,7 @@ typedef struct
|
||||
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_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);
|
||||
void re_set_result_array_properties (ecma_object_t *array_obj_p, ecma_string_t *input_str_p, uint32_t num_of_elements,
|
||||
int32_t index);
|
||||
|
||||
Reference in New Issue
Block a user