From 71059fe346d2c152cb6f3138042165432334f2eb Mon Sep 17 00:00:00 2001 From: Laszlo Vidacs Date: Tue, 26 May 2015 13:37:25 +0200 Subject: [PATCH] Array.prototype.reduce() minor fixes. JerryScript-DCO-1.0-Signed-off-by: Laszlo Vidacs lvidacs.u-szeged@partner.samsung.com --- .../ecma-builtin-array-prototype.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.cpp b/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.cpp index c764d753e..0be427f6b 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.cpp +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.cpp @@ -2468,7 +2468,7 @@ ecma_builtin_array_prototype_object_reduce (ecma_value_t this_arg, /**< this arg ecma_value_t arg2) /**< initialValue */ { ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); - ecma_completion_value_t accumulator = ecma_make_empty_completion_value (); + /* 1 */ ECMA_TRY_CATCH (obj_this, ecma_op_to_object (this_arg), @@ -2490,10 +2490,11 @@ ecma_builtin_array_prototype_object_reduce (ecma_value_t this_arg, /**< this arg /* 4 */ if (!ecma_op_is_callable (arg1)) { - ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); + ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } else { + ecma_completion_value_t accumulator = ecma_make_empty_completion_value (); ecma_number_t *num_p = ecma_alloc_number (); ecma_object_t *func_object_p; ecma_value_t current_index; @@ -2561,7 +2562,8 @@ ecma_builtin_array_prototype_object_reduce (ecma_value_t this_arg, /**< this arg ecma_value_t call_args[] = {prev_value, current_value, current_index, obj_this}; ECMA_TRY_CATCH (call_value, - ecma_op_function_call (func_object_p, ECMA_SIMPLE_VALUE_UNDEFINED, call_args, 4), ret_value); + ecma_op_function_call (func_object_p, ECMA_SIMPLE_VALUE_UNDEFINED, call_args, 4), + ret_value); accumulator = ecma_copy_completion_value (call_value); ECMA_FINALIZE (call_value); @@ -2571,6 +2573,11 @@ ecma_builtin_array_prototype_object_reduce (ecma_value_t this_arg, /**< this arg /* 9d in for loop */ } + if (ecma_is_completion_value_empty (ret_value)) + { + ret_value = ecma_copy_completion_value (accumulator); + } + ecma_free_completion_value (accumulator); ecma_free_completion_value (to_object_comp); ecma_dealloc_number (num_p); } @@ -2580,12 +2587,6 @@ ecma_builtin_array_prototype_object_reduce (ecma_value_t this_arg, /**< this arg ecma_deref_ecma_string (magic_string_length_p); ECMA_FINALIZE (obj_this); - if (ecma_is_completion_value_empty (ret_value)) - { - ret_value = ecma_copy_completion_value (accumulator); - } - ecma_free_completion_value (accumulator); - return ret_value; } /* ecma_builtin_array_prototype_object_reduce */