OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | |
5 (function testArrayConcatArity() { | 4 (function testArrayConcatArity() { |
6 "use strict"; | 5 "use strict"; |
7 assertEquals(1, Array.prototype.concat.length); | 6 assertEquals(1, Array.prototype.concat.length); |
8 })(); | 7 })(); |
9 | 8 |
10 | 9 |
11 (function testArrayConcatNoPrototype() { | 10 (function testArrayConcatNoPrototype() { |
12 "use strict"; | 11 "use strict"; |
13 assertEquals(void 0, Array.prototype.concat.prototype); | 12 assertEquals(void 0, Array.prototype.concat.prototype); |
14 })(); | 13 })(); |
15 | 14 |
16 | 15 |
17 (function testArrayConcatDescriptor() { | 16 (function testArrayConcatDescriptor() { |
18 "use strict"; | 17 "use strict"; |
19 var desc = Object.getOwnPropertyDescriptor(Array.prototype, 'concat'); | 18 var desc = Object.getOwnPropertyDescriptor(Array.prototype, 'concat'); |
20 assertEquals(false, desc.enumerable); | 19 assertEquals(false, desc.enumerable); |
21 })(); | 20 })(); |
22 | 21 |
22 (function testNonConcatSpreadableArray() { | |
23 "use strict" | |
24 var array = [1, 2, 3]; | |
25 assertEquals(array, [].concat(array)); | |
26 assertEquals(array, array.concat([])); | |
27 array[Symbol.isConcatSpreadable] = false; | |
Toon Verwaest
2016/03/31 08:09:46
Make sure to add tests for all the missing cases.
| |
28 assertEquals([[1,2,3]], [].concat(array)); | |
29 assertEquals([[1,2,3]], array.concat([])); | |
30 })(); | |
23 | 31 |
24 (function testConcatArrayLike() { | 32 (function testConcatArrayLike() { |
25 "use strict"; | 33 "use strict"; |
26 var obj = { | 34 var obj = { |
27 "length": 6, | 35 "length": 6, |
28 "1": "A", | 36 "1": "A", |
29 "3": "B", | 37 "3": "B", |
30 "5": "C" | 38 "5": "C" |
31 }; | 39 }; |
32 obj[Symbol.isConcatSpreadable] = true; | 40 obj[Symbol.isConcatSpreadable] = true; |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
857 if (key === "length") return Symbol(); | 865 if (key === "length") return Symbol(); |
858 if (key === "2") return "baz"; | 866 if (key === "2") return "baz"; |
859 if (key === "3") return "bar"; | 867 if (key === "3") return "bar"; |
860 }; | 868 }; |
861 var target = []; | 869 var target = []; |
862 var obj = new Proxy(target, {get: getTrap, has: () => true}); | 870 var obj = new Proxy(target, {get: getTrap, has: () => true}); |
863 | 871 |
864 assertThrows(() => [].concat(obj), TypeError); | 872 assertThrows(() => [].concat(obj), TypeError); |
865 assertThrows(() => Array.prototype.concat.apply(obj), TypeError); | 873 assertThrows(() => Array.prototype.concat.apply(obj), TypeError); |
866 })(); | 874 })(); |
OLD | NEW |