Array.prototype.reduce() fixes.
JerryScript-DCO-1.0-Signed-off-by: Laszlo Vidacs lvidacs.u-szeged@partner.samsung.com
This commit is contained in:
@@ -2494,21 +2494,21 @@ ecma_builtin_array_prototype_object_reduce (ecma_value_t this_arg, /**< this arg
|
||||
}
|
||||
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;
|
||||
|
||||
ecma_completion_value_t to_object_comp = ecma_op_to_object (arg1);
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal (to_object_comp));
|
||||
func_object_p = ecma_get_object_from_completion_value (to_object_comp);
|
||||
ecma_completion_value_t accumulator = ecma_make_empty_completion_value ();
|
||||
|
||||
/* 5 */
|
||||
if (len_number == ECMA_NUMBER_ZERO && ecma_is_value_undefined (arg1))
|
||||
if (len_number == ECMA_NUMBER_ZERO && ecma_is_value_undefined (arg2))
|
||||
{
|
||||
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* 6 */
|
||||
uint32_t index = 0;
|
||||
|
||||
@@ -2546,6 +2546,9 @@ ecma_builtin_array_prototype_object_reduce (ecma_value_t this_arg, /**< this arg
|
||||
}
|
||||
}
|
||||
/* 9 */
|
||||
ecma_value_t undefined_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
ecma_value_t current_index;
|
||||
|
||||
for (; index < len && ecma_is_completion_value_empty (ret_value); ++index)
|
||||
{
|
||||
/* 9a */
|
||||
@@ -2560,7 +2563,6 @@ ecma_builtin_array_prototype_object_reduce (ecma_value_t this_arg, /**< this arg
|
||||
current_index = ecma_make_number_value (num_p);
|
||||
ecma_value_t prev_value = ecma_get_completion_value_value (accumulator);
|
||||
ecma_value_t call_args[] = {prev_value, current_value, current_index, obj_this};
|
||||
ecma_value_t undefined_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
|
||||
ECMA_TRY_CATCH (call_value,
|
||||
ecma_op_function_call (func_object_p, undefined_value, call_args, 4),
|
||||
@@ -2570,7 +2572,6 @@ ecma_builtin_array_prototype_object_reduce (ecma_value_t this_arg, /**< this arg
|
||||
accumulator = ecma_copy_completion_value (call_value);
|
||||
|
||||
ECMA_FINALIZE (call_value);
|
||||
ecma_free_value (undefined_value, false);
|
||||
ECMA_FINALIZE (current_value);
|
||||
}
|
||||
ecma_deref_ecma_string (index_str_p);
|
||||
@@ -2581,6 +2582,10 @@ ecma_builtin_array_prototype_object_reduce (ecma_value_t this_arg, /**< this arg
|
||||
{
|
||||
ret_value = ecma_copy_completion_value (accumulator);
|
||||
}
|
||||
|
||||
ecma_free_value (undefined_value, false);
|
||||
}
|
||||
|
||||
ecma_free_completion_value (accumulator);
|
||||
ecma_free_completion_value (to_object_comp);
|
||||
ecma_dealloc_number (num_p);
|
||||
|
||||
@@ -28,6 +28,7 @@ try {
|
||||
// check for init value
|
||||
try {
|
||||
[].reduce(func);
|
||||
assert(false);
|
||||
}
|
||||
catch(e) {
|
||||
assert(e instanceof TypeError);
|
||||
|
||||
Reference in New Issue
Block a user