Array.prototype.reduce() minor fixes.
JerryScript-DCO-1.0-Signed-off-by: Laszlo Vidacs lvidacs.u-szeged@partner.samsung.com
This commit is contained in:
@@ -2468,7 +2468,7 @@ ecma_builtin_array_prototype_object_reduce (ecma_value_t this_arg, /**< this arg
|
|||||||
ecma_value_t arg2) /**< initialValue */
|
ecma_value_t arg2) /**< initialValue */
|
||||||
{
|
{
|
||||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||||
ecma_completion_value_t accumulator = ecma_make_empty_completion_value ();
|
|
||||||
/* 1 */
|
/* 1 */
|
||||||
ECMA_TRY_CATCH (obj_this,
|
ECMA_TRY_CATCH (obj_this,
|
||||||
ecma_op_to_object (this_arg),
|
ecma_op_to_object (this_arg),
|
||||||
@@ -2490,10 +2490,11 @@ ecma_builtin_array_prototype_object_reduce (ecma_value_t this_arg, /**< this arg
|
|||||||
/* 4 */
|
/* 4 */
|
||||||
if (!ecma_op_is_callable (arg1))
|
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
|
else
|
||||||
{
|
{
|
||||||
|
ecma_completion_value_t accumulator = ecma_make_empty_completion_value ();
|
||||||
ecma_number_t *num_p = ecma_alloc_number ();
|
ecma_number_t *num_p = ecma_alloc_number ();
|
||||||
ecma_object_t *func_object_p;
|
ecma_object_t *func_object_p;
|
||||||
ecma_value_t current_index;
|
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_value_t call_args[] = {prev_value, current_value, current_index, obj_this};
|
||||||
|
|
||||||
ECMA_TRY_CATCH (call_value,
|
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);
|
accumulator = ecma_copy_completion_value (call_value);
|
||||||
|
|
||||||
ECMA_FINALIZE (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 */
|
/* 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_free_completion_value (to_object_comp);
|
||||||
ecma_dealloc_number (num_p);
|
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_deref_ecma_string (magic_string_length_p);
|
||||||
ECMA_FINALIZE (obj_this);
|
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;
|
return ret_value;
|
||||||
} /* ecma_builtin_array_prototype_object_reduce */
|
} /* ecma_builtin_array_prototype_object_reduce */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user