Skip to content

Remove a few ECMA_TRY_CATCH macro usages #2246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 28 additions & 24 deletions jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,22 @@ ecma_builtin_function_prototype_object_apply (ecma_value_t this_arg, /**< this a
ecma_object_t *obj_p = ecma_get_object_from_value (arg2);

/* 4. */
ECMA_TRY_CATCH (length_value,
ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_LENGTH),
ret_value);
ecma_value_t length_value = ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_LENGTH);
if (ECMA_IS_VALUE_ERROR (length_value))
{
return length_value;
}

ecma_number_t length_number;
ecma_value_t get_result = ecma_get_number (length_value, &length_number);

ECMA_OP_TO_NUMBER_TRY_CATCH (length_number,
length_value,
ret_value);
ecma_free_value (length_value);

if (ECMA_IS_VALUE_ERROR (get_result))
{
return get_result;
}
JERRY_ASSERT (ecma_is_value_empty (get_result));

/* 5. */
const uint32_t length = ecma_number_to_uint32 (length_number);
Expand All @@ -134,45 +143,40 @@ ecma_builtin_function_prototype_object_apply (ecma_value_t this_arg, /**< this a
{
/* 6. */
JMEM_DEFINE_LOCAL_ARRAY (arguments_list_p, length, ecma_value_t);
uint32_t last_index = 0;
uint32_t index = 0;

/* 7. */
for (uint32_t index = 0;
index < length && ecma_is_value_empty (ret_value);
index++)
for (index = 0; index < length; index++)
{
ecma_string_t *curr_idx_str_p = ecma_new_ecma_string_from_uint32 (index);
ecma_value_t get_value = ecma_op_object_get (obj_p, curr_idx_str_p);
ecma_deref_ecma_string (curr_idx_str_p);

ECMA_TRY_CATCH (get_value,
ecma_op_object_get (obj_p, curr_idx_str_p),
ret_value);

arguments_list_p[index] = ecma_copy_value (get_value);
last_index = index + 1;
if (ECMA_IS_VALUE_ERROR (get_value))
{
ret_value = get_value;
break;
}

ECMA_FINALIZE (get_value);
ecma_deref_ecma_string (curr_idx_str_p);
arguments_list_p[index] = get_value;
}

if (ecma_is_value_empty (ret_value))
{
JERRY_ASSERT (last_index == length);
JERRY_ASSERT (index == length);
ret_value = ecma_op_function_call (func_obj_p,
arg1,
arguments_list_p,
length);
}

for (uint32_t index = 0; index < last_index; index++)
for (uint32_t remove_index = 0; remove_index < index; remove_index++)
{
ecma_free_value (arguments_list_p[index]);
ecma_free_value (arguments_list_p[remove_index]);
}

JMEM_FINALIZE_LOCAL_ARRAY (arguments_list_p);
}

ECMA_OP_TO_NUMBER_FINALIZE (length_number);
ECMA_FINALIZE (length_value);
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions jerry-core/ecma/operations/ecma-get-put-value.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,14 @@ ecma_op_get_value_object_base (ecma_value_t base_value, /**< base value */
|| ecma_is_value_number (base_value)
|| ecma_is_value_string (base_value));

ecma_value_t ret_value = ECMA_VALUE_EMPTY;

ECMA_TRY_CATCH (object_base, ecma_op_to_object (base_value), ret_value);
ecma_value_t object_base = ecma_op_to_object (base_value);
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (object_base));

ecma_object_t *object_p = ecma_get_object_from_value (object_base);
JERRY_ASSERT (object_p != NULL
&& !ecma_is_lexical_environment (object_p));

ret_value = ECMA_VALUE_UNDEFINED;
ecma_value_t ret_value = ECMA_VALUE_UNDEFINED;

/* Circular reference is possible in JavaScript and testing it is complicated. */
int max_depth = ECMA_PROPERTY_SEARCH_DEPTH_LIMIT;
Expand All @@ -130,7 +129,7 @@ ecma_op_get_value_object_base (ecma_value_t base_value, /**< base value */
}
while (object_p != NULL);

ECMA_FINALIZE (object_base);
ecma_free_value (object_base);

return ret_value;
} /* ecma_op_get_value_object_base */
Expand Down
27 changes: 16 additions & 11 deletions jerry-core/parser/regexp/re-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,14 @@ re_parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context

while (ecma_is_value_empty (ret_value) && should_loop)
{
ECMA_TRY_CATCH (empty,
re_parse_next_token (re_ctx_p->parser_ctx_p,
&(re_ctx_p->current_token)),
ret_value);
ecma_value_t next_token_result = re_parse_next_token (re_ctx_p->parser_ctx_p,
&(re_ctx_p->current_token));
if (ECMA_IS_VALUE_ERROR (next_token_result))
{
ret_value = next_token_result;
break;
}
JERRY_ASSERT (next_token_result == ECMA_VALUE_EMPTY);

uint32_t new_atom_start_offset = re_get_bytecode_length (re_ctx_p->bytecode_ctx_p);

Expand Down Expand Up @@ -444,7 +448,6 @@ re_parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context
break;
}
}
ECMA_FINALIZE (empty);
}

return ret_value;
Expand Down Expand Up @@ -561,10 +564,16 @@ re_compile_bytecode (const re_compiled_code_t **out_bytecode_p, /**< [out] point
re_ctx.num_of_captures = 1;
re_append_opcode (&bc_ctx, RE_OP_SAVE_AT_START);

ECMA_TRY_CATCH (empty, re_parse_alternative (&re_ctx, true), ret_value);
ecma_value_t parse_alt_result = re_parse_alternative (&re_ctx, true);

ECMA_FINALIZE_UTF8_STRING (pattern_start_p, pattern_start_size);

if (ECMA_IS_VALUE_ERROR (parse_alt_result))
{
ret_value = parse_alt_result;
}
/* 2. Check for invalid backreference */
if (re_ctx.highest_backref >= re_ctx.num_of_captures)
else if (re_ctx.highest_backref >= re_ctx.num_of_captures)
{
ret_value = ecma_raise_syntax_error ("Invalid backreference.\n");
}
Expand All @@ -589,10 +598,6 @@ re_compile_bytecode (const re_compiled_code_t **out_bytecode_p, /**< [out] point
sizeof (re_compiled_code_t));
}

ECMA_FINALIZE (empty);

ECMA_FINALIZE_UTF8_STRING (pattern_start_p, pattern_start_size);

size_t byte_code_size = (size_t) (bc_ctx.block_end_p - bc_ctx.block_start_p);

if (!ecma_is_value_empty (ret_value))
Expand Down
41 changes: 13 additions & 28 deletions jerry-core/vm/opcodes-ecma-relational-equality.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,13 @@ ecma_value_t
opfunc_instanceof (ecma_value_t left_value, /**< left value */
ecma_value_t right_value) /**< right value */
{
ecma_value_t ret_value = ECMA_VALUE_EMPTY;

if (!ecma_is_value_object (right_value))
{
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Expected an object in 'instanceof' check."));
}
else
{
ecma_object_t *right_value_obj_p = ecma_get_object_from_value (right_value);

ECMA_TRY_CATCH (is_instance_of,
ecma_op_object_has_instance (right_value_obj_p, left_value),
ret_value);

ret_value = is_instance_of;

ECMA_FINALIZE (is_instance_of);
return ecma_raise_type_error (ECMA_ERR_MSG ("Expected an object in 'instanceof' check."));
}

return ret_value;
ecma_object_t *right_value_obj_p = ecma_get_object_from_value (right_value);
return ecma_op_object_has_instance (right_value_obj_p, left_value);
} /* opfunc_instanceof */

/**
Expand All @@ -138,25 +125,23 @@ ecma_value_t
opfunc_in (ecma_value_t left_value, /**< left value */
ecma_value_t right_value) /**< right value */
{
ecma_value_t ret_value = ECMA_VALUE_EMPTY;

if (!ecma_is_value_object (right_value))
{
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Expected an object in 'in' check."));
return ecma_raise_type_error (ECMA_ERR_MSG ("Expected an object in 'in' check."));
}
else
{
ECMA_TRY_CATCH (str_left_value, ecma_op_to_string (left_value), ret_value);

ecma_string_t *left_value_prop_name_p = ecma_get_string_from_value (str_left_value);
ecma_object_t *right_value_obj_p = ecma_get_object_from_value (right_value);
ecma_value_t left_string_value = ecma_op_to_string (left_value);
if (ECMA_IS_VALUE_ERROR (left_string_value))
{
return left_string_value;
}

ret_value = ecma_make_boolean_value (ecma_op_object_has_property (right_value_obj_p, left_value_prop_name_p));
ecma_string_t *left_value_prop_name_p = ecma_get_string_from_value (left_string_value);
ecma_object_t *right_value_obj_p = ecma_get_object_from_value (right_value);

ECMA_FINALIZE (str_left_value);
}
ecma_free_value (left_string_value);

return ret_value;
return ecma_make_boolean_value (ecma_op_object_has_property (right_value_obj_p, left_value_prop_name_p));
} /* opfunc_in */

/**
Expand Down
94 changes: 43 additions & 51 deletions jerry-core/vm/opcodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,45 +168,40 @@ vm_op_delete_prop (ecma_value_t object, /**< base object */
ecma_value_t property, /**< property name */
bool is_strict) /**< strict mode */
{
ecma_value_t completion_value = ECMA_VALUE_EMPTY;

if (ecma_is_value_undefined (object))
{
completion_value = ECMA_VALUE_TRUE;
return ECMA_VALUE_TRUE;
}
else
{
completion_value = ECMA_VALUE_EMPTY;

ECMA_TRY_CATCH (check_coercible_ret,
ecma_op_check_object_coercible (object),
completion_value);
ECMA_TRY_CATCH (str_name_value,
ecma_op_to_string (property),
completion_value);

JERRY_ASSERT (ecma_is_value_string (str_name_value));
ecma_string_t *name_string_p = ecma_get_string_from_value (str_name_value);

ECMA_TRY_CATCH (obj_value, ecma_op_to_object (object), completion_value);
ecma_value_t check_coercible = ecma_op_check_object_coercible (object);
if (ECMA_IS_VALUE_ERROR (check_coercible))
{
return check_coercible;
}
JERRY_ASSERT (check_coercible == ECMA_VALUE_EMPTY);

JERRY_ASSERT (ecma_is_value_object (obj_value));
ecma_object_t *obj_p = ecma_get_object_from_value (obj_value);
JERRY_ASSERT (!ecma_is_lexical_environment (obj_p));
ecma_value_t str_name_value = ecma_op_to_string (property);
if (ECMA_IS_VALUE_ERROR (str_name_value))
{
return str_name_value;
}

ECMA_TRY_CATCH (delete_op_ret_val,
ecma_op_object_delete (obj_p, name_string_p, is_strict),
completion_value);
JERRY_ASSERT (ecma_is_value_string (str_name_value));
ecma_string_t *name_string_p = ecma_get_string_from_value (str_name_value);

completion_value = delete_op_ret_val;
ecma_value_t obj_value = ecma_op_to_object (object);
/* The ecma_op_check_object_coercible call already checked the op_to_object error cases. */
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (obj_value));
JERRY_ASSERT (ecma_is_value_object (obj_value));
ecma_object_t *obj_p = ecma_get_object_from_value (obj_value);
JERRY_ASSERT (!ecma_is_lexical_environment (obj_p));

ECMA_FINALIZE (delete_op_ret_val);
ECMA_FINALIZE (obj_value);
ECMA_FINALIZE (str_name_value);
ECMA_FINALIZE (check_coercible_ret);
}
ecma_value_t delete_op_ret = ecma_op_object_delete (obj_p, name_string_p, is_strict);
JERRY_ASSERT (ecma_is_value_boolean (delete_op_ret) || (is_strict == true && ECMA_IS_VALUE_ERROR (delete_op_ret)));
ecma_free_value (obj_value);
ecma_free_value (str_name_value);

return completion_value;
return delete_op_ret;
} /* vm_op_delete_prop */

/**
Expand Down Expand Up @@ -251,36 +246,33 @@ ecma_collection_chunk_t *
opfunc_for_in (ecma_value_t left_value, /**< left value */
ecma_value_t *result_obj_p) /**< expression object */
{
ecma_value_t compl_val = ECMA_VALUE_EMPTY;
ecma_collection_chunk_t *prop_names_p = NULL;

/* 3. */
if (!ecma_is_value_undefined (left_value)
&& !ecma_is_value_null (left_value))
if (ecma_is_value_undefined (left_value)
|| ecma_is_value_null (left_value))
{
/* 4. */
ECMA_TRY_CATCH (obj_expr_value,
ecma_op_to_object (left_value),
compl_val);

ecma_object_t *obj_p = ecma_get_object_from_value (obj_expr_value);
ecma_collection_header_t *prop_names_coll_p = ecma_op_object_get_property_names (obj_p, false, true, true);

if (prop_names_coll_p->item_count != 0)
{
prop_names_p = ECMA_GET_POINTER (ecma_collection_chunk_t,
prop_names_coll_p->first_chunk_cp);
return prop_names_p;
}

ecma_ref_object (obj_p);
*result_obj_p = ecma_make_object_value (obj_p);
}
/* 4. */
ecma_value_t obj_expr_value = ecma_op_to_object (left_value);
/* ecma_op_to_object will only raise error on null/undefined values but those are handled above. */
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (obj_expr_value));
ecma_object_t *obj_p = ecma_get_object_from_value (obj_expr_value);
ecma_collection_header_t *prop_names_coll_p = ecma_op_object_get_property_names (obj_p, false, true, true);

jmem_heap_free_block (prop_names_coll_p, sizeof (ecma_collection_header_t));
if (prop_names_coll_p->item_count != 0)
{
prop_names_p = ECMA_GET_POINTER (ecma_collection_chunk_t,
prop_names_coll_p->first_chunk_cp);

ECMA_FINALIZE (obj_expr_value);
ecma_ref_object (obj_p);
*result_obj_p = ecma_make_object_value (obj_p);
}

JERRY_ASSERT (ecma_is_value_empty (compl_val));
jmem_heap_free_block (prop_names_coll_p, sizeof (ecma_collection_header_t));
ecma_free_value (obj_expr_value);

return prop_names_p;
} /* opfunc_for_in */
Expand Down