mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Add RegExp object constructor, regular expression matching procedures, RegExp and RegExp.prototype built-in objects.
JerryScript-DCO-1.0-Signed-off-by: Szilard Ledan szledan.u-szeged@partner.samsung.com JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
This commit is contained in:
parent
4ffcb4d464
commit
f992f5d92e
@ -330,6 +330,7 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
|
||||
case ECMA_INTERNAL_PROPERTY_EXTENSION_ID: /* an integer */
|
||||
case ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31: /* an integer (bit-mask) */
|
||||
case ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63: /* an integer (bit-mask) */
|
||||
case ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE:
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
@ -255,6 +255,11 @@ typedef enum
|
||||
*/
|
||||
ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63,
|
||||
|
||||
/**
|
||||
* RegExp bytecode array
|
||||
*/
|
||||
ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE,
|
||||
|
||||
/**
|
||||
* Number of internal properties' types
|
||||
*/
|
||||
|
||||
@ -809,6 +809,11 @@ ecma_free_internal_property (ecma_property_t *property_p) /**< the property */
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
case ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE:
|
||||
{
|
||||
void *bytecode_p = ECMA_GET_NON_NULL_POINTER (void, property_value);
|
||||
mem_heap_free_block (bytecode_p);
|
||||
}
|
||||
}
|
||||
|
||||
ecma_dealloc_property (property_p);
|
||||
|
||||
@ -32,6 +32,13 @@ ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_STRING, "string")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_OBJECT, "object")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_FUNCTION, "function")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_LENGTH, "length")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SOURCE, "source")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GLOBAL, "global")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_IGNORECASE_UL, "ignoreCase")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_MULTILINE, "multiline")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_INDEX, "index")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_INPUT, "input")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_LASTINDEX_UL, "lastIndex")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_NAN, "NaN")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_INFINITY_UL, "Infinity")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_UNDEFINED_UL, "Undefined")
|
||||
@ -44,7 +51,8 @@ ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_STRING_UL, "String")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_BOOLEAN_UL, "Boolean")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_NUMBER_UL, "Number")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_DATE_UL, "Date")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_REG_EXP_UL, "RegExp")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_REGEXP_UL, "RegExp")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_REGEXP_SOURCE_UL, "Source")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_ERROR_UL, "Error")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_EVAL_ERROR_UL, "EvalError")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_RANGE_ERROR_UL, "RangeError")
|
||||
@ -205,6 +213,11 @@ ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_EXEC, "exec")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TEST, "test")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_NAME, "name")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_MESSAGE, "message")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_G_CHAR, "g")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_I_CHAR, "i")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_M_CHAR, "m")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SLASH_CHAR, "/")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP, "(?:)")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_LEFT_SQUARE_CHAR, "[")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_RIGHT_SQUARE_CHAR, "]")
|
||||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_COLON_CHAR, ":")
|
||||
|
||||
@ -133,12 +133,14 @@ OBJECT_VALUE (ECMA_MAGIC_STRING_DATE_UL,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
#endif /* CONFIG_ECMA_COMPACT_PROFILE_DISABLE_DATE_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN
|
||||
// ECMA-262 v5, 15.1.4.8
|
||||
CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_REG_EXP_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_REGEXP_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
|
||||
// ECMA-262 v5, 15.1.4.9
|
||||
|
||||
@ -0,0 +1,229 @@
|
||||
/* Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
|
||||
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN
|
||||
#include "ecma-regexp-object.h"
|
||||
#include "re-compiler.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-regexp-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID regexp_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup regexp ECMA RegExp.prototype object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The RegExp.prototype object's 'exec' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.10.6.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_regexp_prototype_exec (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||
|
||||
if (ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != ECMA_MAGIC_STRING_REGEXP_UL)
|
||||
{
|
||||
ret_value = ecma_raise_type_error ((const ecma_char_t *) "Incomplete RegExp type");
|
||||
}
|
||||
else
|
||||
{
|
||||
ECMA_TRY_CATCH (obj_this, ecma_op_to_object (this_arg), ret_value);
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
|
||||
ecma_property_t *bytecode_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE);
|
||||
re_bytecode_t *bytecode_p = ECMA_GET_POINTER (re_bytecode_t, bytecode_prop_p->u.internal_property.value);
|
||||
|
||||
ECMA_TRY_CATCH (input_str_value,
|
||||
ecma_op_to_string (arg),
|
||||
ret_value);
|
||||
|
||||
ecma_string_t *input_str_p = ecma_get_string_from_value (input_str_value);
|
||||
|
||||
/* Convert ecma_String_t *to regexp_bytecode_t* */
|
||||
int32_t input_str_len = ecma_string_get_length (input_str_p);
|
||||
|
||||
MEM_DEFINE_LOCAL_ARRAY (input_zt_str_p, input_str_len + 1, ecma_char_t);
|
||||
|
||||
ssize_t zt_str_size = (ssize_t) sizeof (ecma_char_t) * (input_str_len + 1);
|
||||
ecma_string_to_zt_string (input_str_p, input_zt_str_p, zt_str_size);
|
||||
|
||||
ret_value = ecma_regexp_exec_helper (obj_p, bytecode_p, input_zt_str_p);
|
||||
|
||||
MEM_FINALIZE_LOCAL_ARRAY (input_zt_str_p);
|
||||
|
||||
ECMA_FINALIZE (input_str_value);
|
||||
|
||||
ECMA_FINALIZE (obj_this);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_regexp_prototype_exec */
|
||||
|
||||
/**
|
||||
* The RegExp.prototype object's 'test' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.10.6.3
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_regexp_prototype_test (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||
|
||||
ECMA_TRY_CATCH (match_value,
|
||||
ecma_builtin_regexp_prototype_exec (this_arg, arg),
|
||||
ret_value);
|
||||
|
||||
if (ecma_is_value_undefined (match_value))
|
||||
{
|
||||
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (match_value);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_regexp_prototype_test */
|
||||
|
||||
/**
|
||||
* The RegExp.prototype object's 'toString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.10.6.4
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_regexp_prototype_to_string (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||
|
||||
if (ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != ECMA_MAGIC_STRING_REGEXP_UL)
|
||||
{
|
||||
ret_value = ecma_raise_type_error ((const ecma_char_t *) "Incomplete RegExp type");
|
||||
}
|
||||
else
|
||||
{
|
||||
ECMA_TRY_CATCH (obj_this,
|
||||
ecma_op_to_object (this_arg),
|
||||
ret_value);
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
|
||||
|
||||
/* Get RegExp source from the source property */
|
||||
ecma_string_t *magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_SOURCE);
|
||||
ecma_property_t *source_prop_p = ecma_op_object_get_property (obj_p, magic_string_p);
|
||||
ecma_deref_ecma_string (magic_string_p);
|
||||
|
||||
ecma_string_t *src_sep_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_SLASH_CHAR);
|
||||
ecma_string_t *source_str_p = ecma_get_string_from_value (source_prop_p->u.named_data_property.value);
|
||||
ecma_string_t *output_str_p = ecma_concat_ecma_strings (src_sep_str_p, ecma_copy_or_ref_ecma_string (source_str_p));
|
||||
ecma_deref_ecma_string (source_str_p);
|
||||
|
||||
ecma_string_t *concat_p = ecma_concat_ecma_strings (output_str_p, src_sep_str_p);
|
||||
ecma_deref_ecma_string (src_sep_str_p);
|
||||
ecma_deref_ecma_string (output_str_p);
|
||||
output_str_p = concat_p;
|
||||
|
||||
/* Check the global flag */
|
||||
magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_GLOBAL);
|
||||
ecma_property_t *global_prop_p = ecma_op_object_get_property (obj_p, magic_string_p);
|
||||
ecma_deref_ecma_string (magic_string_p);
|
||||
|
||||
if (ecma_is_value_true (global_prop_p->u.named_data_property.value))
|
||||
{
|
||||
ecma_string_t *g_flag_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_G_CHAR);
|
||||
concat_p = ecma_concat_ecma_strings (output_str_p, g_flag_str_p);
|
||||
ecma_deref_ecma_string (output_str_p);
|
||||
ecma_deref_ecma_string (g_flag_str_p);
|
||||
output_str_p = concat_p;
|
||||
}
|
||||
|
||||
/* Check the ignoreCase flag */
|
||||
magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_IGNORECASE_UL);
|
||||
ecma_property_t *ignorecase_prop_p = ecma_op_object_get_property (obj_p, magic_string_p);
|
||||
ecma_deref_ecma_string (magic_string_p);
|
||||
|
||||
if (ecma_is_value_true (ignorecase_prop_p->u.named_data_property.value))
|
||||
{
|
||||
ecma_string_t *ic_flag_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_I_CHAR);
|
||||
concat_p = ecma_concat_ecma_strings (output_str_p, ic_flag_str_p);
|
||||
ecma_deref_ecma_string (output_str_p);
|
||||
ecma_deref_ecma_string (ic_flag_str_p);
|
||||
output_str_p = concat_p;
|
||||
}
|
||||
|
||||
/* Check the global flag */
|
||||
magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_MULTILINE);
|
||||
ecma_property_t *multiline_prop_p = ecma_op_object_get_property (obj_p, magic_string_p);
|
||||
ecma_deref_ecma_string (magic_string_p);
|
||||
|
||||
if (ecma_is_value_true (multiline_prop_p->u.named_data_property.value))
|
||||
{
|
||||
ecma_string_t *m_flag_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_M_CHAR);
|
||||
concat_p = ecma_concat_ecma_strings (output_str_p, m_flag_str_p);
|
||||
ecma_deref_ecma_string (output_str_p);
|
||||
ecma_deref_ecma_string (m_flag_str_p);
|
||||
output_str_p = concat_p;
|
||||
}
|
||||
|
||||
ret_value = ecma_make_normal_completion_value (ecma_make_string_value (output_str_p));
|
||||
|
||||
ECMA_FINALIZE (obj_this);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_regexp_prototype_to_string */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN */
|
||||
@ -0,0 +1,52 @@
|
||||
/* Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* RegExp.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE)
|
||||
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
ROUTINE (ECMA_MAGIC_STRING_EXEC, ecma_builtin_regexp_prototype_exec, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_TEST, ecma_builtin_regexp_prototype_test, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_TO_STRING_UL, ecma_builtin_regexp_prototype_to_string, 0, 0)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef CP_UNIMPLEMENTED_VALUE
|
||||
#undef ROUTINE
|
||||
142
jerry-core/ecma/builtin-objects/ecma-builtin-regexp.cpp
Normal file
142
jerry-core/ecma/builtin-objects/ecma-builtin-regexp.cpp
Normal file
@ -0,0 +1,142 @@
|
||||
/* Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-regexp-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
|
||||
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-regexp.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID regexp
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup regexp ECMA RegExp object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in RegExp object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_regexp_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_regexp_dispatch_construct (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_regexp_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in RegExp object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||
ecma_value_t pattern_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
ecma_value_t flags_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
|
||||
if (arguments_list_len > 0)
|
||||
{
|
||||
/* pattern string or RegExp object */
|
||||
pattern_value = arguments_list_p[0];
|
||||
|
||||
if (arguments_list_len > 1)
|
||||
{
|
||||
flags_value = arguments_list_p[1];
|
||||
}
|
||||
}
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
ecma_string_t *magic_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
|
||||
ret_value = ecma_op_create_regexp_object (magic_str_p, NULL);
|
||||
ecma_deref_ecma_string (magic_str_p);
|
||||
}
|
||||
else if (ecma_is_value_object (pattern_value)
|
||||
&& ecma_object_get_class_name (ecma_get_object_from_value (pattern_value)) == ECMA_MAGIC_STRING_REGEXP_UL)
|
||||
{
|
||||
if (arguments_list_len == 1
|
||||
|| (arguments_list_len > 1 && ecma_is_value_undefined (flags_value)))
|
||||
{
|
||||
ret_value = ecma_make_normal_completion_value (ecma_copy_value (pattern_value, true));
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_raise_type_error ((const ecma_char_t *) "Invalid argument of RegExp call.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ECMA_TRY_CATCH (regexp_str_value,
|
||||
ecma_op_to_string (pattern_value),
|
||||
ret_value);
|
||||
|
||||
ecma_string_t *pattern_string_p = ecma_get_string_from_value (regexp_str_value);
|
||||
|
||||
ecma_string_t *flags_string_p = NULL;
|
||||
|
||||
if (arguments_list_len > 1)
|
||||
{
|
||||
ECMA_TRY_CATCH (flags_str_value,
|
||||
ecma_op_to_string (flags_value),
|
||||
ret_value);
|
||||
|
||||
flags_string_p = ecma_copy_or_ref_ecma_string (ecma_get_string_from_value (flags_str_value));
|
||||
ECMA_FINALIZE (flags_str_value);
|
||||
}
|
||||
|
||||
if (ecma_is_completion_value_empty (ret_value))
|
||||
{
|
||||
ret_value = ecma_op_create_regexp_object (pattern_string_p, flags_string_p);
|
||||
}
|
||||
|
||||
if (flags_string_p != NULL)
|
||||
{
|
||||
ecma_deref_ecma_string (flags_string_p);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (regexp_str_value);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_regexp_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN */
|
||||
97
jerry-core/ecma/builtin-objects/ecma-builtin-regexp.inc.h
Normal file
97
jerry-core/ecma/builtin-objects/ecma-builtin-regexp.inc.h
Normal file
@ -0,0 +1,97 @@
|
||||
/* Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* RegExp built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef SIMPLE_VALUE
|
||||
# define SIMPLE_VALUE(name, simple_value, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !SIMPLE_VALUE */
|
||||
|
||||
#ifndef STRING_VALUE
|
||||
# define STRING_VALUE(name, magic_string_id, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !STRING_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_REGEXP)
|
||||
|
||||
// ECMA-262 v5, 15.10.5.1
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE),
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.10.7.1
|
||||
STRING_VALUE (ECMA_MAGIC_STRING_SOURCE,
|
||||
ECMA_MAGIC_STRING_REGEXP_SOURCE_UL,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.10.7.2
|
||||
SIMPLE_VALUE (ECMA_MAGIC_STRING_GLOBAL,
|
||||
ECMA_SIMPLE_VALUE_FALSE,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.10.7.3
|
||||
SIMPLE_VALUE (ECMA_MAGIC_STRING_IGNORECASE_UL,
|
||||
ECMA_SIMPLE_VALUE_FALSE,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
// ECMA-262 v5, 15.10.7.4
|
||||
SIMPLE_VALUE (ECMA_MAGIC_STRING_MULTILINE,
|
||||
ECMA_SIMPLE_VALUE_FALSE,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.10.7.5
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_LASTINDEX_UL,
|
||||
0,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
|
||||
2,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef CP_UNIMPLEMENTED_VALUE
|
||||
#undef ROUTINE
|
||||
@ -148,6 +148,24 @@ BUILTIN (ECMA_BUILTIN_ID_DATE,
|
||||
date)
|
||||
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_DATE_BUILTIN*/
|
||||
|
||||
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN
|
||||
/* The RegExp.prototype object (15.10.6) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
regexp_prototype)
|
||||
|
||||
/* The RegExp object (15.10) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_REGEXP,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
regexp)
|
||||
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
|
||||
/* The Error.prototype object (15.11.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
|
||||
|
||||
@ -681,6 +681,12 @@ ecma_object_get_class_name (ecma_object_t *obj_p) /**< object */
|
||||
return ECMA_MAGIC_STRING_ERROR_UL;
|
||||
}
|
||||
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
|
||||
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN
|
||||
case ECMA_BUILTIN_ID_REGEXP_PROTOTYPE:
|
||||
{
|
||||
return ECMA_MAGIC_STRING_REGEXP_UL;
|
||||
}
|
||||
#endif /* CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN */
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_GLOBAL));
|
||||
|
||||
1329
jerry-core/ecma/operations/ecma-regexp-object.cpp
Normal file
1329
jerry-core/ecma/operations/ecma-regexp-object.cpp
Normal file
File diff suppressed because it is too large
Load Diff
66
jerry-core/ecma/operations/ecma-regexp-object.h
Normal file
66
jerry-core/ecma/operations/ecma-regexp-object.h
Normal file
@ -0,0 +1,66 @@
|
||||
/* Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ECMA_REGEXP_OBJECT_H
|
||||
#define ECMA_REGEXP_OBJECT_H
|
||||
|
||||
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "re-compiler.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmaregexpobject ECMA RegExp object related routines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define RE_EXECUTE_RECURSION_LIMIT 1000 /* Limit of RegExp executor recursion depth */
|
||||
#define RE_EXECUTE_MATCH_LIMIT 10000 /* Limit of RegExp execetur matching steps */
|
||||
|
||||
/**
|
||||
* RegExp executor context
|
||||
*
|
||||
* FIXME:
|
||||
* Add comments with description of the structure members
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
const ecma_char_t **saved_p;
|
||||
const ecma_char_t *input_start_p;
|
||||
const ecma_char_t *input_end_p;
|
||||
uint32_t match_limit;
|
||||
uint32_t recursion_depth;
|
||||
uint32_t num_of_captures;
|
||||
uint32_t num_of_non_captures;
|
||||
uint32_t *num_of_iterations;
|
||||
uint8_t flags;
|
||||
} re_matcher_ctx_t;
|
||||
|
||||
extern ecma_completion_value_t
|
||||
ecma_op_create_regexp_object (ecma_string_t *pattern_p, ecma_string_t *flags_str_p);
|
||||
|
||||
extern ecma_completion_value_t
|
||||
ecma_regexp_exec_helper (ecma_object_t *obj_p, re_bytecode_t *bc_p, const ecma_char_t *str_p);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN */
|
||||
#endif /* !ECMA_REGEXP_OBJECT_H */
|
||||
Loading…
x
Reference in New Issue
Block a user