Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 1 | // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Check that @@isConcatSpreadable is checked when set on Object.prototype |
| 6 | |
| 7 | "use strict" |
| 8 | |
| 9 | var array = [1, 2, 3]; |
| 10 | var object = {length: 1, '0': 'a'}; |
| 11 | |
| 12 | function testConcatDefaults() { |
| 13 | assertEquals(array, [].concat(array)); |
| 14 | assertEquals(array, array.concat([])); |
| 15 | assertEquals([1, 2, 3, 1, 2, 3], array.concat(array)); |
| 16 | assertEquals([object], [].concat(object)); |
| 17 | assertEquals([1, 2, 3, object], array.concat(object)); |
| 18 | assertEquals([object], Array.prototype.concat.call(object,[])); |
| 19 | assertEquals([object, 1, 2, 3], Array.prototype.concat.call(object, array)); |
| 20 | assertEquals([object, object], Array.prototype.concat.call(object, object)); |
| 21 | } |
| 22 | |
| 23 | testConcatDefaults(); |
| 24 | |
| 25 | Object.prototype[Symbol.isConcatSpreadable] = false; |
| 26 | |
| 27 | assertEquals([[], array], [].concat(array)); |
| 28 | assertEquals([array, []], array.concat([])); |
| 29 | assertEquals([array, array], array.concat(array)); |
| 30 | assertEquals([[], object], [].concat(object)); |
| 31 | assertEquals([array, object], array.concat(object)); |
| 32 | assertEquals([object, []], Array.prototype.concat.call(object,[])); |
| 33 | assertEquals([object, array], Array.prototype.concat.call(object, array)); |
| 34 | assertEquals([object, object], Array.prototype.concat.call(object, object)); |
| 35 | |
| 36 | Object.prototype[Symbol.isConcatSpreadable] = true; |
| 37 | |
| 38 | assertEquals(array, [].concat(array)); |
| 39 | assertEquals(array, array.concat([])); |
| 40 | assertEquals([1, 2, 3, 1, 2, 3], array.concat(array)); |
| 41 | assertEquals(['a'], [].concat(object)); |
| 42 | assertEquals([1, 2, 3, 'a'], array.concat(object)); |
| 43 | assertEquals(['a'], Array.prototype.concat.call(object,[])); |
| 44 | assertEquals(['a', 1, 2, 3], Array.prototype.concat.call(object, array)); |
| 45 | assertEquals(['a', 'a'], Array.prototype.concat.call(object, object)); |
| 46 | |
| 47 | delete Object.prototype[Symbol.isConcatSpreadable]; |
| 48 | testConcatDefaults(); |