Skip to content

Commit 9c07b83

Browse files
committed
Returned array of Array.prototype.map() should have same length as original.
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai.u-szeged@partner.samsung.com
1 parent 6038173 commit 9c07b83

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2527,7 +2527,11 @@ ecma_builtin_array_prototype_object_map (ecma_value_t this_arg, /**< this argume
25272527

25282528
if (ecma_is_completion_value_empty (ret_value))
25292529
{
2530-
ret_value = new_array;
2530+
ECMA_TRY_CATCH (set_length_value,
2531+
ecma_builtin_array_prototype_helper_set_length (new_array_p, len),
2532+
ret_value);
2533+
ret_value = new_array;
2534+
ECMA_FINALIZE (set_length_value);
25312535
}
25322536
else
25332537
{

tests/jerry/array-prototype-map.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ assert ([1, 4, 9].map(func).equals([1,5,11]));
5252

5353
assert ([1, "X", 10].map(func).equals([1, "X1", 12]));
5454

55+
var arr = [1,2,3];
56+
arr.length = 5;
57+
assert(arr.map(func).length === arr.length);
58+
5559
var long_array = [0, 1];
5660
assert (long_array.map(func).equals([0,2]));
5761

0 commit comments

Comments
 (0)