From 25ec2bea17e5596307012844a0edbf5260cafb5f Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Wed, 24 Sep 2014 14:21:03 +0400 Subject: [PATCH] Refactoring function call operations to return 'normal' completion values instead of 'return' completion values. Removing ECMA_FUNCTION_CALL macro. --- src/libcoreint/interpreter.c | 5 +++ src/libcoreint/opcodes.c | 18 +++++----- .../ecma-builtin-global-object.c | 8 ++--- .../ecma-builtin-math-object.c | 12 +++---- .../ecma-builtin-object-object.c | 21 +++++------ src/libecmaoperations/ecma-function-object.c | 18 +++++----- src/libecmaoperations/ecma-get-put-value.c | 6 ++-- src/libecmaoperations/ecma-objects-general.c | 24 ++++++------- src/libecmaoperations/ecma-try-catch-macro.h | 35 ++----------------- 9 files changed, 58 insertions(+), 89 deletions(-) diff --git a/src/libcoreint/interpreter.c b/src/libcoreint/interpreter.c index 50cc6b6f5..48bdafad0 100644 --- a/src/libcoreint/interpreter.c +++ b/src/libcoreint/interpreter.c @@ -493,6 +493,11 @@ run_int_from_pos (opcode_counter_t start_pos, completion = run_int_loop (&int_data); + JERRY_ASSERT (ecma_is_completion_value_normal (completion) + || ecma_is_completion_value_throw (completion) + || ecma_is_completion_value_return (completion) + || ecma_is_completion_value_exit (completion)); + for (uint32_t reg_index = 0; reg_index < regs_num; reg_index++) diff --git a/src/libcoreint/opcodes.c b/src/libcoreint/opcodes.c index 88c33fb44..53581eeb0 100644 --- a/src/libcoreint/opcodes.c +++ b/src/libcoreint/opcodes.c @@ -89,9 +89,9 @@ opfunc_call_1 (opcode_t opdata __unused, int_data_t *int_data) ecma_object_t *func_obj_p = ECMA_GET_POINTER (func_value.u.value.value); ECMA_TRY_CATCH (this_value, ecma_op_implicit_this_value (int_data->lex_env_p), ret_value); - ECMA_FUNCTION_CALL (call_completion, - ecma_op_function_call (func_obj_p, this_value.u.value, &arg_value.u.value, 1), - ret_value); + ECMA_TRY_CATCH (call_completion, + ecma_op_function_call (func_obj_p, this_value.u.value, &arg_value.u.value, 1), + ret_value); ret_value = set_variable_value (int_data, lhs_var_idx, call_completion.u.value); @@ -697,9 +697,9 @@ opfunc_call_0 (opcode_t opdata, /**< operation data */ ecma_object_t *func_obj_p = ECMA_GET_POINTER (func_value.u.value.value); ECMA_TRY_CATCH (this_value, ecma_op_implicit_this_value (int_data->lex_env_p), ret_value); - ECMA_FUNCTION_CALL (call_completion, - ecma_op_function_call (func_obj_p, this_value.u.value, NULL, 0), - ret_value); + ECMA_TRY_CATCH (call_completion, + ecma_op_function_call (func_obj_p, this_value.u.value, NULL, 0), + ret_value); ret_value = set_variable_value (int_data, lhs_var_idx, call_completion.u.value); @@ -771,9 +771,9 @@ opfunc_call_n (opcode_t opdata, /**< operation data */ { ecma_object_t *func_obj_p = ECMA_GET_POINTER (func_value.u.value.value); - ECMA_FUNCTION_CALL (call_completion, - ecma_op_function_call (func_obj_p, this_value.u.value, arg_values, args_number), - ret_value); + ECMA_TRY_CATCH (call_completion, + ecma_op_function_call (func_obj_p, this_value.u.value, arg_values, args_number), + ret_value); ret_value = set_variable_value (int_data, lhs_var_idx, call_completion.u.value); diff --git a/src/libecmabuiltins/ecma-builtin-global-object.c b/src/libecmabuiltins/ecma-builtin-global-object.c index 634903602..7449b1886 100644 --- a/src/libecmabuiltins/ecma-builtin-global-object.c +++ b/src/libecmabuiltins/ecma-builtin-global-object.c @@ -144,8 +144,8 @@ ecma_builtin_global_object_is_nan (ecma_value_t arg) /**< routine's first argume bool is_nan = ecma_number_is_nan (*num_p); - ret_value = ecma_make_return_completion_value (ecma_make_simple_value (is_nan ? ECMA_SIMPLE_VALUE_TRUE - : ECMA_SIMPLE_VALUE_FALSE)); + ret_value = ecma_make_simple_completion_value (is_nan ? ECMA_SIMPLE_VALUE_TRUE + : ECMA_SIMPLE_VALUE_FALSE); ECMA_FINALIZE (num_value); @@ -173,8 +173,8 @@ ecma_builtin_global_object_is_finite (ecma_value_t arg) /**< routine's first arg bool is_finite = !(ecma_number_is_nan (*num_p) || ecma_number_is_infinity (*num_p)); - ret_value = ecma_make_return_completion_value (ecma_make_simple_value (is_finite ? ECMA_SIMPLE_VALUE_TRUE - : ECMA_SIMPLE_VALUE_FALSE)); + ret_value = ecma_make_simple_completion_value (is_finite ? ECMA_SIMPLE_VALUE_TRUE + : ECMA_SIMPLE_VALUE_FALSE); ECMA_FINALIZE (num_value); diff --git a/src/libecmabuiltins/ecma-builtin-math-object.c b/src/libecmabuiltins/ecma-builtin-math-object.c index 71bde890b..524bf94d6 100644 --- a/src/libecmabuiltins/ecma-builtin-math-object.c +++ b/src/libecmabuiltins/ecma-builtin-math-object.c @@ -190,7 +190,7 @@ ecma_builtin_math_object_abs (ecma_value_t arg) /**< routine's argument */ *num_p = ecma_number_negate (arg_num); } - ret_value = ecma_make_return_completion_value (ecma_make_number_value (num_p)); + ret_value = ecma_make_normal_completion_value (ecma_make_number_value (num_p)); ECMA_FINALIZE (arg_num_value); @@ -420,7 +420,7 @@ ecma_builtin_math_object_max (ecma_value_t args[], /**< arguments list */ ecma_number_t *num_p = ecma_alloc_number (); *num_p = ret_num; - return ecma_make_return_completion_value (ecma_make_number_value (num_p)); + return ecma_make_normal_completion_value (ecma_make_number_value (num_p)); } /* ecma_builtin_math_object_max */ /** @@ -510,7 +510,7 @@ ecma_builtin_math_object_min (ecma_value_t args[], /**< arguments list */ ecma_number_t *num_p = ecma_alloc_number (); *num_p = ret_num; - return ecma_make_return_completion_value (ecma_make_number_value (num_p)); + return ecma_make_normal_completion_value (ecma_make_number_value (num_p)); } /* ecma_builtin_math_object_min */ /** @@ -567,7 +567,7 @@ ecma_builtin_math_object_random (void) ecma_number_t *rand_p = ecma_alloc_number (); *rand_p = rand; - return ecma_make_return_completion_value (ecma_make_number_value (rand_p)); + return ecma_make_normal_completion_value (ecma_make_number_value (rand_p)); } /* ecma_builtin_math_object_random */ /** @@ -620,7 +620,7 @@ ecma_builtin_math_object_round (ecma_value_t arg) /**< routine's argument */ } } - ret_value = ecma_make_return_completion_value (ecma_make_number_value (num_p)); + ret_value = ecma_make_normal_completion_value (ecma_make_number_value (num_p)); ECMA_FINALIZE (arg_num_value); @@ -707,7 +707,7 @@ ecma_builtin_math_object_sqrt (ecma_value_t arg) /**< routine's argument */ ecma_number_t *num_p = ecma_alloc_number (); *num_p = ret_num; - ret_value = ecma_make_return_completion_value (ecma_make_number_value (num_p)); + ret_value = ecma_make_normal_completion_value (ecma_make_number_value (num_p)); ECMA_FINALIZE (arg_num_value); diff --git a/src/libecmabuiltins/ecma-builtin-object-object.c b/src/libecmabuiltins/ecma-builtin-object-object.c index 9b0dde930..b9f20a4f2 100644 --- a/src/libecmabuiltins/ecma-builtin-object-object.c +++ b/src/libecmabuiltins/ecma-builtin-object-object.c @@ -121,25 +121,20 @@ ecma_builtin_object_dispatch_call (ecma_value_t *arguments_list_p, /**< argument { JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + ecma_completion_value_t ret_value; + if (arguments_list_len == 0 || ecma_is_value_undefined (arguments_list_p[0]) || ecma_is_value_null (arguments_list_p [0])) { - return ecma_builtin_object_dispatch_construct (arguments_list_p, arguments_list_len); + ret_value = ecma_builtin_object_dispatch_construct (arguments_list_p, arguments_list_len); } else { - ecma_completion_value_t new_obj_value = ecma_op_to_object (arguments_list_p [0]); - - if (!ecma_is_completion_value_normal (new_obj_value)) - { - return new_obj_value; - } - else - { - return ecma_make_return_completion_value (new_obj_value.u.value); - } + ret_value = ecma_op_to_object (arguments_list_p [0]); } + + return ret_value; } /* ecma_builtin_object_dispatch_call */ /** @@ -157,7 +152,7 @@ ecma_builtin_object_dispatch_construct (ecma_value_t *arguments_list_p, /**< arg { ecma_object_t *obj_p = ecma_op_create_object_object_noarg (); - return ecma_make_return_completion_value (ecma_make_object_value (obj_p)); + return ecma_make_normal_completion_value (ecma_make_object_value (obj_p)); } else { @@ -169,7 +164,7 @@ ecma_builtin_object_dispatch_construct (ecma_value_t *arguments_list_p, /**< arg } else { - return ecma_make_return_completion_value (new_obj_value.u.value); + return ecma_make_normal_completion_value (new_obj_value.u.value); } } } /* ecma_builtin_object_dispatch_construct */ diff --git a/src/libecmaoperations/ecma-function-object.c b/src/libecmaoperations/ecma-function-object.c index d03bb62f6..f5e2d996a 100644 --- a/src/libecmaoperations/ecma-function-object.c +++ b/src/libecmaoperations/ecma-function-object.c @@ -532,11 +532,9 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */ local_env_p, is_strict, false); - if (ecma_is_completion_value_normal (completion)) + if (ecma_is_completion_value_return (completion)) { - JERRY_ASSERT(ecma_is_completion_value_empty (completion)); - - ret_value = ecma_make_return_completion_value (ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED)); + ret_value = ecma_make_normal_completion_value (completion.u.value); } else { @@ -622,12 +620,12 @@ ecma_op_function_construct (ecma_object_t *func_obj_p, /**< Function object */ ecma_deref_object (prototype_p); // 8. - ECMA_FUNCTION_CALL (call_completion, - ecma_op_function_call (func_obj_p, - ecma_make_object_value (obj_p), - arguments_list_p, - arguments_list_len), - ret_value); + ECMA_TRY_CATCH (call_completion, + ecma_op_function_call (func_obj_p, + ecma_make_object_value (obj_p), + arguments_list_p, + arguments_list_len), + ret_value); ecma_value_t obj_value; diff --git a/src/libecmaoperations/ecma-get-put-value.c b/src/libecmaoperations/ecma-get-put-value.c index fe6f37553..1ae64f0cb 100644 --- a/src/libecmaoperations/ecma-get-put-value.c +++ b/src/libecmaoperations/ecma-get-put-value.c @@ -240,9 +240,9 @@ ecma_op_put_value (ecma_reference_t ref, /**< ECMA-reference */ ecma_object_t *setter_p = ECMA_GET_POINTER(prop_p->u.named_accessor_property.set_p); JERRY_ASSERT (setter_p != NULL); - ECMA_FUNCTION_CALL (call_completion, - ecma_op_function_call (setter_p, base, &value, 1), - ret_value); + ECMA_TRY_CATCH (call_completion, + ecma_op_function_call (setter_p, base, &value, 1), + ret_value); ret_value = ecma_make_empty_completion_value (); diff --git a/src/libecmaoperations/ecma-objects-general.c b/src/libecmaoperations/ecma-objects-general.c index f0f8b1ef1..d01b2ae9e 100644 --- a/src/libecmaoperations/ecma-objects-general.c +++ b/src/libecmaoperations/ecma-objects-general.c @@ -159,12 +159,12 @@ ecma_op_general_object_get (ecma_object_t *obj_p, /**< the object */ { ecma_completion_value_t ret_value; - ECMA_FUNCTION_CALL (call_completion, - ecma_op_function_call (getter_p, - ecma_make_object_value (obj_p), - NULL, - 0), - ret_value); + ECMA_TRY_CATCH (call_completion, + ecma_op_function_call (getter_p, + ecma_make_object_value (obj_p), + NULL, + 0), + ret_value); ret_value = ecma_make_normal_completion_value (ecma_copy_value (call_completion.u.value, true)); @@ -308,12 +308,12 @@ ecma_op_general_object_put (ecma_object_t *obj_p, /**< the object */ ecma_completion_value_t ret_value; - ECMA_FUNCTION_CALL (call_completion, - ecma_op_function_call (setter_p, - ecma_make_object_value (obj_p), - &value, - 1), - ret_value); + ECMA_TRY_CATCH (call_completion, + ecma_op_function_call (setter_p, + ecma_make_object_value (obj_p), + &value, + 1), + ret_value); ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE); diff --git a/src/libecmaoperations/ecma-try-catch-macro.h b/src/libecmaoperations/ecma-try-catch-macro.h index fccdc9737..0625359a5 100644 --- a/src/libecmaoperations/ecma-try-catch-macro.h +++ b/src/libecmaoperations/ecma-try-catch-macro.h @@ -39,42 +39,13 @@ { \ JERRY_ASSERT(ecma_is_completion_value_normal (var)) -/** - * The macro defines function call block that executes function call 'op', - * assigns call's completion value to 'var', and checks for exceptions - * that might be thrown during initialization. - * - * If no return values is not return completion value, - * then code after the function call block is executed. - * Otherwise, completion value is just copied to return_value. - * - * Note: - * Each ECMA_FUNCTION_CALL should have it's own corresponding ECMA_FINALIZE - * statement with same argument as corresponding ECMA_FUNCTION_CALL's first argument. - */ -#define ECMA_FUNCTION_CALL(var, op, return_value) \ - ecma_completion_value_t var = op; \ - if (unlikely (!ecma_is_completion_value_return (var))) \ - { \ - return_value = ecma_copy_completion_value (var); \ - } \ - else \ - { \ - JERRY_ASSERT(!ecma_is_completion_value_normal (var)) - -/** - * The define is not used. It is just for vera++ style checker that wants to find closing pair for all opening braces - */ -#define ECMA_FUNCTION_CALL_CLOSING_BRACKET_FOR_VERA_STYLE_CHECKER } - /** * The macro marks end of code block that is defined by corresponding - * ECMA_TRY_CATCH / ECMA_FUNCTION_CALL and frees variable, initialized - * by the ECMA_TRY_CATCH / ECMA_FUNCTION_CALL. + * ECMA_TRY_CATCH and frees variable, initialized by the ECMA_TRY_CATCH. * * Note: - * Each ECMA_TRY_CATCH / ECMA_FUNCTION_CALL should be followed by ECMA_FINALIZE with same argument - * as corresponding ECMA_TRY_CATCH's / ECMA_FUNCTION_CALL's first argument. + * Each ECMA_TRY_CATCH should be followed by ECMA_FINALIZE with same argument + * as corresponding ECMA_TRY_CATCH's first argument. */ #define ECMA_FINALIZE(var) } \ ecma_free_completion_value (var)