Skip to content

Commit fc85657

Browse files
committed
Array.prototype.reduceRight() fix
JerryScript-DCO-1.0-Signed-off-by: Laszlo Vidacs [email protected]
1 parent 3a1653e commit fc85657

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,12 +2147,10 @@ ecma_builtin_array_prototype_object_reduce_right (ecma_value_t this_arg, /**< th
21472147
}
21482148
else
21492149
{
2150-
ecma_number_t *num_p = ecma_alloc_number ();
21512150
ecma_object_t *func_object_p;
21522151

21532152
JERRY_ASSERT (ecma_is_value_object (arg1));
21542153
func_object_p = ecma_get_object_from_value (arg1);
2155-
ecma_value_t accumulator = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
21562154

21572155
/* 5 */
21582156
if (len_number == ECMA_NUMBER_ZERO && ecma_is_value_undefined (arg2))
@@ -2161,6 +2159,9 @@ ecma_builtin_array_prototype_object_reduce_right (ecma_value_t this_arg, /**< th
21612159
}
21622160
else
21632161
{
2162+
ecma_number_t *num_p = ecma_alloc_number ();
2163+
ecma_value_t accumulator = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
2164+
21642165
/* 6 */
21652166
uint32_t index = len - 1;
21662167
bool zero_reached = !len;
@@ -2236,10 +2237,10 @@ ecma_builtin_array_prototype_object_reduce_right (ecma_value_t this_arg, /**< th
22362237
{
22372238
ret_value = ecma_make_normal_completion_value (ecma_copy_value (accumulator, true));
22382239
}
2239-
}
22402240

2241-
ecma_free_value (accumulator, true);
2242-
ecma_dealloc_number (num_p);
2241+
ecma_free_value (accumulator, true);
2242+
ecma_dealloc_number (num_p);
2243+
}
22432244
}
22442245

22452246
ECMA_OP_TO_NUMBER_FINALIZE (len_number);

tests/jerry/array_prototype_reduce_right.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ try {
3333
assert(e instanceof TypeError);
3434
}
3535

36+
try {
37+
var arg2;
38+
[].reduceRight(func, arg2);
39+
assert(false);
40+
} catch(e) {
41+
assert(e instanceof TypeError);
42+
}
43+
3644
// various checks
3745
assert([].reduceRight(func, 1) === 1);
3846

0 commit comments

Comments
 (0)