Removed ECMA_TRY_CATCH macros from RegExp built-in (#2642)

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
This commit is contained in:
László Langó
2019-01-04 15:12:03 +01:00
committed by Akos Kiss
parent f2404ac0e1
commit 2f8c0a168f
5 changed files with 222 additions and 228 deletions
@@ -63,15 +63,12 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this argument
ecma_value_t pattern_arg, /**< pattern or RegExp object */ ecma_value_t pattern_arg, /**< pattern or RegExp object */
ecma_value_t flags_arg) /**< flags */ ecma_value_t flags_arg) /**< flags */
{ {
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
if (!ecma_is_value_object (this_arg) if (!ecma_is_value_object (this_arg)
|| !ecma_object_class_is (ecma_get_object_from_value (this_arg), LIT_MAGIC_STRING_REGEXP_UL)) || !ecma_object_class_is (ecma_get_object_from_value (this_arg), LIT_MAGIC_STRING_REGEXP_UL))
{ {
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Incomplete RegExp type")); return ecma_raise_type_error (ECMA_ERR_MSG ("Incomplete RegExp type"));
} }
else
{
uint16_t flags = 0; uint16_t flags = 0;
if (ecma_is_value_object (pattern_arg) if (ecma_is_value_object (pattern_arg)
@@ -79,10 +76,8 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this argument
{ {
if (!ecma_is_value_undefined (flags_arg)) if (!ecma_is_value_undefined (flags_arg))
{ {
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Invalid argument of RegExp compile.")); return ecma_raise_type_error (ECMA_ERR_MSG ("Invalid argument of RegExp compile."));
} }
else
{
/* Compile from existing RegExp pbject. */ /* Compile from existing RegExp pbject. */
ecma_object_t *target_p = ecma_get_object_from_value (pattern_arg); ecma_object_t *target_p = ecma_get_object_from_value (pattern_arg);
@@ -122,7 +117,11 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this argument
flags |= RE_FLAG_MULTILINE; flags |= RE_FLAG_MULTILINE;
} }
ECMA_TRY_CATCH (obj_this, ecma_op_to_object (this_arg), ret_value); ecma_value_t obj_this = ecma_op_to_object (this_arg);
if (ECMA_IS_VALUE_ERROR (obj_this))
{
return obj_this;
}
ecma_object_t *this_obj_p = ecma_get_object_from_value (obj_this); ecma_object_t *this_obj_p = ecma_get_object_from_value (obj_this);
/* Get bytecode property. */ /* Get bytecode property. */
@@ -148,45 +147,58 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this argument
ECMA_SET_INTERNAL_VALUE_POINTER (*bc_prop_p, new_bc_p); ECMA_SET_INTERNAL_VALUE_POINTER (*bc_prop_p, new_bc_p);
re_initialize_props (this_obj_p, pattern_string_p, flags); re_initialize_props (this_obj_p, pattern_string_p, flags);
ecma_free_value (obj_this);
ret_value = ECMA_VALUE_UNDEFINED; return ECMA_VALUE_UNDEFINED;
}
ECMA_FINALIZE (obj_this);
}
}
else
{
ecma_string_t *pattern_string_p = NULL; ecma_string_t *pattern_string_p = NULL;
/* Get source string. */ /* Get source string. */
ret_value = ecma_regexp_read_pattern_str_helper (pattern_arg, &pattern_string_p); ecma_value_t ret_value = ecma_regexp_read_pattern_str_helper (pattern_arg, &pattern_string_p);
if (ECMA_IS_VALUE_ERROR (ret_value))
{
JERRY_ASSERT (pattern_string_p == NULL);
return ret_value;
}
JERRY_ASSERT (ecma_is_value_empty (ret_value));
/* Parse flags. */ /* Parse flags. */
if (ecma_is_value_empty (ret_value) && !ecma_is_value_undefined (flags_arg)) if (!ecma_is_value_undefined (flags_arg))
{ {
ECMA_TRY_CATCH (flags_str_value, ecma_value_t flags_str_value = ecma_op_to_string (flags_arg);
ecma_op_to_string (flags_arg), if (ECMA_IS_VALUE_ERROR (flags_str_value))
ret_value); {
ecma_deref_ecma_string (pattern_string_p);
ECMA_TRY_CATCH (flags_dummy, return flags_str_value;
re_parse_regexp_flags (ecma_get_string_from_value (flags_str_value), &flags),
ret_value);
ECMA_FINALIZE (flags_dummy);
ECMA_FINALIZE (flags_str_value);
} }
if (ecma_is_value_empty (ret_value)) ecma_value_t parsed_flags_val = re_parse_regexp_flags (ecma_get_string_from_value (flags_str_value), &flags);
ecma_free_value (flags_str_value);
if (ECMA_IS_VALUE_ERROR (parsed_flags_val))
{ {
ECMA_TRY_CATCH (obj_this, ecma_op_to_object (this_arg), ret_value); ecma_deref_ecma_string (pattern_string_p);
ecma_object_t *this_obj_p = ecma_get_object_from_value (obj_this); return parsed_flags_val;
}
ecma_value_t *bc_prop_p = &(((ecma_extended_object_t *) this_obj_p)->u.class_prop.u.value); }
/* Try to compile bytecode from new source. */ /* Try to compile bytecode from new source. */
const re_compiled_code_t *new_bc_p = NULL; const re_compiled_code_t *new_bc_p = NULL;
ECMA_TRY_CATCH (bc_dummy, ecma_value_t bc_val = re_compile_bytecode (&new_bc_p, pattern_string_p, flags);
re_compile_bytecode (&new_bc_p, pattern_string_p, flags), if (ECMA_IS_VALUE_ERROR (bc_val))
ret_value); {
ecma_deref_ecma_string (pattern_string_p);
return bc_val;
}
ecma_value_t obj_this = ecma_op_to_object (this_arg);
if (ECMA_IS_VALUE_ERROR (obj_this))
{
ecma_deref_ecma_string (pattern_string_p);
return obj_this;
}
ecma_object_t *this_obj_p = ecma_get_object_from_value (obj_this);
ecma_value_t *bc_prop_p = &(((ecma_extended_object_t *) this_obj_p)->u.class_prop.u.value);
re_compiled_code_t *old_bc_p = ECMA_GET_INTERNAL_VALUE_ANY_POINTER (re_compiled_code_t, *bc_prop_p); re_compiled_code_t *old_bc_p = ECMA_GET_INTERNAL_VALUE_ANY_POINTER (re_compiled_code_t, *bc_prop_p);
@@ -198,21 +210,10 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this argument
ECMA_SET_INTERNAL_VALUE_POINTER (*bc_prop_p, new_bc_p); ECMA_SET_INTERNAL_VALUE_POINTER (*bc_prop_p, new_bc_p);
re_initialize_props (this_obj_p, pattern_string_p, flags); re_initialize_props (this_obj_p, pattern_string_p, flags);
ret_value = ECMA_VALUE_UNDEFINED; ecma_free_value (obj_this);
ECMA_FINALIZE (bc_dummy);
ECMA_FINALIZE (obj_this);
}
if (pattern_string_p != NULL)
{
ecma_deref_ecma_string (pattern_string_p); ecma_deref_ecma_string (pattern_string_p);
}
}
}
return ret_value; return ECMA_VALUE_UNDEFINED;
} /* ecma_builtin_regexp_prototype_compile */ } /* ecma_builtin_regexp_prototype_compile */
#endif /* !CONFIG_DISABLE_ANNEXB_BUILTIN */ #endif /* !CONFIG_DISABLE_ANNEXB_BUILTIN */
@@ -232,34 +233,36 @@ static ecma_value_t
ecma_builtin_regexp_prototype_exec (ecma_value_t this_arg, /**< this argument */ ecma_builtin_regexp_prototype_exec (ecma_value_t this_arg, /**< this argument */
ecma_value_t arg) /**< routine's argument */ ecma_value_t arg) /**< routine's argument */
{ {
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
if (!ecma_is_value_object (this_arg) if (!ecma_is_value_object (this_arg)
|| !ecma_object_class_is (ecma_get_object_from_value (this_arg), LIT_MAGIC_STRING_REGEXP_UL)) || !ecma_object_class_is (ecma_get_object_from_value (this_arg), LIT_MAGIC_STRING_REGEXP_UL))
{ {
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Incomplete RegExp type")); return ecma_raise_type_error (ECMA_ERR_MSG ("Incomplete RegExp type"));
} }
else
{
ECMA_TRY_CATCH (obj_this, ecma_op_to_object (this_arg), ret_value);
ECMA_TRY_CATCH (input_str_value, ecma_value_t obj_this = ecma_op_to_object (this_arg);
ecma_op_to_string (arg), if (ECMA_IS_VALUE_ERROR (obj_this))
ret_value); {
return obj_this;
}
ecma_value_t input_str_value = ecma_op_to_string (arg);
if (ECMA_IS_VALUE_ERROR (input_str_value))
{
ecma_free_value (obj_this);
return input_str_value;
}
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this); ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
ecma_value_t *bytecode_prop_p = &(((ecma_extended_object_t *) obj_p)->u.class_prop.u.value); ecma_value_t *bytecode_prop_p = &(((ecma_extended_object_t *) obj_p)->u.class_prop.u.value);
void *bytecode_p = ECMA_GET_INTERNAL_VALUE_ANY_POINTER (void, *bytecode_prop_p); void *bytecode_p = ECMA_GET_INTERNAL_VALUE_ANY_POINTER (void, *bytecode_prop_p);
ecma_value_t ret_value;
if (bytecode_p == NULL) if (bytecode_p == NULL)
{ {
/* Missing bytecode means empty RegExp: '/(?:)/', so always return empty string. */ /* Missing bytecode means empty RegExp: '/(?:)/', so always return empty string. */
ecma_value_t arguments_list[1]; ecma_value_t empty_str_val = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY);
arguments_list[0] = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY); ret_value = ecma_op_create_array_object (&empty_str_val, 1, false);
ret_value = ecma_op_create_array_object (arguments_list, 1, false);
re_set_result_array_properties (ecma_get_object_from_value (ret_value), re_set_result_array_properties (ecma_get_object_from_value (ret_value),
ecma_get_string_from_value (input_str_value), ecma_get_string_from_value (input_str_value),
1, 1,
@@ -270,9 +273,8 @@ ecma_builtin_regexp_prototype_exec (ecma_value_t this_arg, /**< this argument */
ret_value = ecma_regexp_exec_helper (obj_this, input_str_value, false); ret_value = ecma_regexp_exec_helper (obj_this, input_str_value, false);
} }
ECMA_FINALIZE (input_str_value); ecma_free_value (obj_this);
ECMA_FINALIZE (obj_this); ecma_free_value (input_str_value);
}
return ret_value; return ret_value;
} /* ecma_builtin_regexp_prototype_exec */ } /* ecma_builtin_regexp_prototype_exec */
@@ -64,7 +64,6 @@ ecma_value_t
ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */ ecma_length_t arguments_list_len) /**< number of arguments */
{ {
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
ecma_value_t pattern_value = ECMA_VALUE_UNDEFINED; ecma_value_t pattern_value = ECMA_VALUE_UNDEFINED;
ecma_value_t flags_value = ECMA_VALUE_UNDEFINED; ecma_value_t flags_value = ECMA_VALUE_UNDEFINED;
@@ -84,54 +83,46 @@ ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /*
{ {
if (ecma_is_value_undefined (flags_value)) if (ecma_is_value_undefined (flags_value))
{ {
ret_value = ecma_copy_value (pattern_value); return ecma_copy_value (pattern_value);
} }
else
{ return ecma_raise_type_error (ECMA_ERR_MSG ("Invalid argument of RegExp call."));
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Invalid argument of RegExp call."));
} }
}
else
{
ecma_string_t *pattern_string_p = NULL; ecma_string_t *pattern_string_p = NULL;
ecma_string_t *flags_string_p = NULL; ecma_value_t ret_value = ecma_regexp_read_pattern_str_helper (pattern_value, &pattern_string_p);
if (ECMA_IS_VALUE_ERROR (ret_value))
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))
{ {
ECMA_TRY_CATCH (flags_str_value, return ret_value;
ecma_op_to_string (flags_value),
ret_value);
flags_string_p = ecma_get_string_from_value (flags_str_value);
ecma_ref_ecma_string (flags_string_p);
ECMA_FINALIZE (flags_str_value);
} }
JERRY_ASSERT (ecma_is_value_empty (ret_value));
uint16_t flags = 0; uint16_t flags = 0;
if (ecma_is_value_empty (ret_value) && (flags_string_p != NULL)) if (!ecma_is_value_undefined (flags_value))
{ {
ret_value = re_parse_regexp_flags (flags_string_p, &flags); ecma_value_t flags_str_value = ecma_op_to_string (flags_value);
}
if (ecma_is_value_empty (ret_value)) if (ECMA_IS_VALUE_ERROR (flags_str_value))
{
ret_value = ecma_op_create_regexp_object (pattern_string_p, flags);
}
if (pattern_string_p != NULL)
{ {
ecma_deref_ecma_string (pattern_string_p); ecma_deref_ecma_string (pattern_string_p);
return flags_str_value;
} }
if (flags_string_p != NULL) ecma_string_t *flags_string_p = ecma_get_string_from_value (flags_str_value);
JERRY_ASSERT (flags_string_p != NULL);
ret_value = re_parse_regexp_flags (flags_string_p, &flags);
ecma_free_value (flags_str_value); // implicit frees flags_string_p
if (ECMA_IS_VALUE_ERROR (ret_value))
{ {
ecma_deref_ecma_string (flags_string_p); ecma_deref_ecma_string (pattern_string_p);
return ret_value;
} }
JERRY_ASSERT (ecma_is_value_empty (ret_value));
} }
ret_value = ecma_op_create_regexp_object (pattern_string_p, flags);
ecma_deref_ecma_string (pattern_string_p);
return ret_value; return ret_value;
} /* ecma_builtin_regexp_dispatch_construct */ } /* ecma_builtin_regexp_dispatch_construct */
+14 -8
View File
@@ -286,12 +286,18 @@ ecma_op_abstract_relational_compare (ecma_value_t x, /**< first operand */
ecma_value_t ret_value = ECMA_VALUE_EMPTY; ecma_value_t ret_value = ECMA_VALUE_EMPTY;
/* 1., 2. */ /* 1., 2. */
ECMA_TRY_CATCH (prim_first_converted_value, ecma_value_t prim_first_converted_value = ecma_op_to_primitive (x, ECMA_PREFERRED_TYPE_NUMBER);
ecma_op_to_primitive (x, ECMA_PREFERRED_TYPE_NUMBER), if (ECMA_IS_VALUE_ERROR (prim_first_converted_value))
ret_value); {
ECMA_TRY_CATCH (prim_second_converted_value, return prim_first_converted_value;
ecma_op_to_primitive (y, ECMA_PREFERRED_TYPE_NUMBER), }
ret_value);
ecma_value_t prim_second_converted_value = ecma_op_to_primitive (y, ECMA_PREFERRED_TYPE_NUMBER);
if (ECMA_IS_VALUE_ERROR (prim_second_converted_value))
{
ecma_free_value (prim_first_converted_value);
return prim_second_converted_value;
}
const ecma_value_t px = left_first ? prim_first_converted_value : prim_second_converted_value; const ecma_value_t px = left_first ? prim_first_converted_value : prim_second_converted_value;
const ecma_value_t py = left_first ? prim_second_converted_value : prim_first_converted_value; const ecma_value_t py = left_first ? prim_second_converted_value : prim_first_converted_value;
@@ -393,8 +399,8 @@ ecma_op_abstract_relational_compare (ecma_value_t x, /**< first operand */
ret_value = ecma_make_boolean_value (is_px_less); ret_value = ecma_make_boolean_value (is_px_less);
} }
ECMA_FINALIZE (prim_second_converted_value); ecma_free_value (prim_second_converted_value);
ECMA_FINALIZE (prim_first_converted_value); ecma_free_value (prim_first_converted_value);
return ret_value; return ret_value;
} /* ecma_op_abstract_relational_compare */ } /* ecma_op_abstract_relational_compare */
+17 -22
View File
@@ -250,7 +250,6 @@ ecma_op_create_regexp_object (ecma_string_t *pattern_p, /**< input pattern */
uint16_t flags) /**< flags */ uint16_t flags) /**< flags */
{ {
JERRY_ASSERT (pattern_p != NULL); JERRY_ASSERT (pattern_p != NULL);
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
ecma_object_t *re_prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE); ecma_object_t *re_prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE);
@@ -264,22 +263,20 @@ ecma_op_create_regexp_object (ecma_string_t *pattern_p, /**< input pattern */
/* Compile bytecode. */ /* Compile bytecode. */
const re_compiled_code_t *bc_p = NULL; const re_compiled_code_t *bc_p = NULL;
ECMA_TRY_CATCH (empty, re_compile_bytecode (&bc_p, pattern_p, flags), ret_value); ecma_value_t ret_value = re_compile_bytecode (&bc_p, pattern_p, flags);
if (ECMA_IS_VALUE_ERROR (ret_value))
{
ecma_deref_object (object_p);
return ret_value;
}
JERRY_ASSERT (ecma_is_value_empty (ret_value));
/* Set [[Class]] and bytecode internal properties. */ /* Set [[Class]] and bytecode internal properties. */
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_REGEXP_UL; ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_REGEXP_UL;
ECMA_SET_INTERNAL_VALUE_POINTER (ext_object_p->u.class_prop.u.value, bc_p); ECMA_SET_INTERNAL_VALUE_POINTER (ext_object_p->u.class_prop.u.value, bc_p);
ret_value = ecma_make_object_value (object_p); return ecma_make_object_value (object_p);
ECMA_FINALIZE (empty);
if (ECMA_IS_VALUE_ERROR (ret_value))
{
ecma_deref_object (object_p);
}
return ret_value;
} /* ecma_op_create_regexp_object */ } /* ecma_op_create_regexp_object */
/** /**
@@ -1280,7 +1277,7 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
const lit_utf8_byte_t *sub_str_p = NULL; const lit_utf8_byte_t *sub_str_p = NULL;
uint8_t *bc_start_p = (uint8_t *) (bc_p + 1); uint8_t *bc_start_p = (uint8_t *) (bc_p + 1);
while (ecma_is_value_empty (ret_value)) while (!ECMA_IS_VALUE_ERROR (ret_value))
{ {
if (index < 0 || index > (int32_t) input_str_len) if (index < 0 || index > (int32_t) input_str_len)
{ {
@@ -1297,13 +1294,13 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
} }
else else
{ {
ECMA_TRY_CATCH (match_value, re_match_regexp (&re_ctx, ret_value = re_match_regexp (&re_ctx, bc_start_p, input_curr_p, &sub_str_p);
bc_start_p, if (ECMA_IS_VALUE_ERROR (ret_value))
input_curr_p, {
&sub_str_p), break;
ret_value); }
if (ecma_is_value_true (match_value)) if (ecma_is_value_true (ret_value))
{ {
is_match = true; is_match = true;
break; break;
@@ -1314,8 +1311,6 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
lit_utf8_incr (&input_curr_p); lit_utf8_incr (&input_curr_p);
} }
index++; index++;
ECMA_FINALIZE (match_value);
} }
} }
@@ -1341,7 +1336,7 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
} }
/* 3. Fill the result array or return with 'undefiend' */ /* 3. Fill the result array or return with 'undefiend' */
if (ecma_is_value_empty (ret_value)) if (!ECMA_IS_VALUE_ERROR (ret_value))
{ {
if (is_match) if (is_match)
{ {
+1 -1
View File
@@ -262,7 +262,7 @@ re_parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context
ret_value = next_token_result; ret_value = next_token_result;
break; break;
} }
JERRY_ASSERT (next_token_result == ECMA_VALUE_EMPTY); JERRY_ASSERT (ecma_is_value_empty (next_token_result));
uint32_t new_atom_start_offset = re_get_bytecode_length (re_ctx_p->bytecode_ctx_p); uint32_t new_atom_start_offset = re_get_bytecode_length (re_ctx_p->bytecode_ctx_p);