Implement Regexp.prototype[@@match] method (#3345)
The algorithm is based on ECMA-262 v6, 21.2.5.6 The following helper methods are also implemented: - RegExpExec: ECMA-262 v6, 21.2.5.2.1 - AdvanceStringIndex: ECMA-262 v6, 21.2.5.2.3 JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
This commit is contained in:
committed by
Robert Fancsik
parent
9725936848
commit
0c6b306429
@@ -2605,7 +2605,9 @@ ecma_op_is_regexp (ecma_value_t arg) /**< argument */
|
||||
|
||||
if (!ecma_is_value_undefined (is_regexp))
|
||||
{
|
||||
return ecma_make_boolean_value (ecma_op_to_boolean (is_regexp));
|
||||
const bool to_bool = ecma_op_to_boolean (is_regexp);
|
||||
ecma_free_value (is_regexp);
|
||||
return ecma_make_boolean_value (to_bool);
|
||||
}
|
||||
|
||||
return ecma_make_boolean_value (ecma_object_is_regexp_object (arg));
|
||||
|
||||
@@ -2011,6 +2011,65 @@ cleanup_string:
|
||||
return result;
|
||||
} /* ecma_regexp_replace_helper */
|
||||
|
||||
/**
|
||||
* RegExpExec operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v6.0, 21.2.5.2.1
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_regexp_exec (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_string_t *str_p) /**< input string */
|
||||
{
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ecma_object_t *arg_obj_p = ecma_get_object_from_value (this_arg);
|
||||
|
||||
ecma_value_t exec = ecma_op_object_get_by_magic_id (arg_obj_p, LIT_MAGIC_STRING_EXEC);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (exec))
|
||||
{
|
||||
return exec;
|
||||
}
|
||||
|
||||
if (ecma_op_is_callable (exec))
|
||||
{
|
||||
ecma_object_t *function_p = ecma_get_object_from_value (exec);
|
||||
ecma_value_t arguments[] = { ecma_make_string_value (str_p) };
|
||||
|
||||
ecma_value_t result = ecma_op_function_call (function_p, this_arg, arguments, 1);
|
||||
|
||||
ecma_deref_object (function_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!ecma_is_value_object (result) && !ecma_is_value_null (result))
|
||||
{
|
||||
ecma_free_value (result);
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Return value of 'exec' must be an Object or Null"));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_free_value (exec);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
if (!ecma_object_is_regexp_object (this_arg))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("'this' is not a valid RegExp object"));
|
||||
}
|
||||
|
||||
return ecma_regexp_exec_helper (this_arg, ecma_make_string_value (str_p), false);
|
||||
} /* ecma_op_regexp_exec */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
|
||||
@@ -110,6 +110,8 @@ ecma_value_t
|
||||
ecma_regexp_replace_helper (ecma_value_t this_arg,
|
||||
ecma_value_t string_arg,
|
||||
ecma_value_t replace_arg);
|
||||
|
||||
ecma_value_t ecma_op_regexp_exec (ecma_value_t this_arg, ecma_string_t *str_p);
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
|
||||
Reference in New Issue
Block a user