Skip to content

Commit 9dd2671

Browse files
committed
Fix array concat function with array argument
Fix a minor typo: we need to get the length of the argument instead of the length of the `this`. One related test262 test: ch15/15.4/15.4.4/15.4.4.4/S15.4.4.4_A1_T2.js JerryScript-DCO-1.0-Signed-off-by: Peter Gal [email protected]
1 parent 13cf314 commit 9dd2671

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@ for (i = 0; i < array.length; i++) {
2323

2424
var obj = {};
2525
var arr1 = ["Apple", 6, "Peach"];
26-
var arr2 = [obj, "Cherry", "Grape"];
26+
var arr2 = [obj, "Cherry", "Grape", 88];
2727

2828
var new_array = arr1.concat(arr2, obj, 1);
2929

30-
assert(new_array.length === 8);
30+
assert(new_array.length === 9);
3131
assert(new_array[0] === "Apple");
3232
assert(new_array[1] === 6);
3333
assert(new_array[2] === "Peach");
3434
assert(new_array[3] === obj);
3535
assert(new_array[4] === "Cherry");
3636
assert(new_array[5] === "Grape");
37-
assert(new_array[6] === obj);
38-
assert(new_array[7] === 1);
37+
assert(new_array[6] === 88);
38+
assert(new_array[7] === obj);
39+
assert(new_array[8] === 1);
3940

4041
// Checking behavior when unable to get length
4142
var obj = { concat : Array.prototype.concat }

0 commit comments

Comments
 (0)