Skip to content

Commit b414329

Browse files
dbatyaiegavrin
authored andcommitted
Fix Array.prototype.concat() argument array length.
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai [email protected]
1 parent db9b74a commit b414329

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ ecma_builtin_array_prototype_object_concat (ecma_value_t this_arg, /**< this arg
146146
ecma_op_object_get (ecma_get_object_from_value (args[arg_index]),
147147
magic_string_length_p),
148148
ret_value);
149-
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_len_number, len_value, ret_value);
149+
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_len_number, arg_len_value, ret_value);
150150

151151
uint32_t arg_len = ecma_number_to_uint32 (arg_len_number);
152152

tests/jerry/array-prototype-concat.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ assert(new_array[5] === "Grape");
3737
assert(new_array[6] === obj);
3838
assert(new_array[7] === 1);
3939

40+
var arr1 = [1,2];
41+
var arr2 = [4,5,6,7,8];
42+
var arr3 = [,,9,10];
43+
var arr4 = [];
44+
var expected = [1,2,4,5,6,7,8,,,9,10];
45+
46+
var result = arr1.concat(arr2, arr3, arr4);
47+
48+
assert(result.length === expected.length)
49+
for (i = 0; i < result.length; i++) {
50+
assert(result[i] === expected[i]);
51+
}
52+
4053
// Checking behavior when unable to get length
4154
var obj = { concat : Array.prototype.concat }
4255
Object.defineProperty(obj, 'length', { 'get' : function () {throw new ReferenceError ("foo"); } });

0 commit comments

Comments
 (0)