OLD | NEW |
(Empty) | |
| 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 // with a dictionary backing store. |
| 7 |
| 8 // Force Object.prototype into dictionary backing store by adding many |
| 9 // properties. |
| 10 for (var i = 0; i < 10*1000; i++) { |
| 11 Object.prototype['generatedProperty'+i] = true; |
| 12 } |
| 13 |
| 14 var array = [1, 2, 3]; |
| 15 var object = {length: 1, '0': 'a'}; |
| 16 |
| 17 function SetProperty(receiver, key, value) { |
| 18 receiver[key] = value; |
| 19 } |
| 20 |
| 21 // Force the Keyed Store IC in SetProperty to be generic. |
| 22 var receiver = {}; |
| 23 for (var i = 0; i < 100; i++) { |
| 24 SetProperty(receiver, 'prop'+i, 'value'); |
| 25 } |
| 26 |
| 27 function testConcatDefaults() { |
| 28 assertEquals(array, [].concat(array)); |
| 29 assertEquals(array, array.concat([])); |
| 30 assertEquals([1, 2, 3, 1, 2, 3], array.concat(array)); |
| 31 assertEquals([object], [].concat(object)); |
| 32 assertEquals([1, 2, 3, object], array.concat(object)); |
| 33 assertEquals([object], Array.prototype.concat.call(object,[])); |
| 34 assertEquals([object, 1, 2, 3], Array.prototype.concat.call(object, array)); |
| 35 assertEquals([object, object], Array.prototype.concat.call(object, object)); |
| 36 } |
| 37 |
| 38 testConcatDefaults(); |
| 39 |
| 40 // Use a generic IC to set @@isConcatSpreadable |
| 41 SetProperty(Object.prototype, Symbol.isConcatSpreadable, false); |
| 42 |
| 43 assertEquals([[], array], [].concat(array)); |
| 44 assertEquals([array, []], array.concat([])); |
| 45 assertEquals([array, array], array.concat(array)); |
| 46 assertEquals([[], object], [].concat(object)); |
| 47 assertEquals([array, object], array.concat(object)); |
| 48 assertEquals([object, []], Array.prototype.concat.call(object,[])); |
| 49 assertEquals([object, array], Array.prototype.concat.call(object, array)); |
| 50 assertEquals([object, object], Array.prototype.concat.call(object, object)); |
| 51 |
| 52 // Use a generic IC to set @@isConcatSpreadable |
| 53 SetProperty(Object.prototype, Symbol.isConcatSpreadable, true); |
| 54 |
| 55 assertEquals(array, [].concat(array)); |
| 56 assertEquals(array, array.concat([])); |
| 57 assertEquals([1, 2, 3, 1, 2, 3], array.concat(array)); |
| 58 assertEquals(['a'], [].concat(object)); |
| 59 assertEquals([1, 2, 3, 'a'], array.concat(object)); |
| 60 assertEquals(['a'], Array.prototype.concat.call(object,[])); |
| 61 assertEquals(['a', 1, 2, 3], Array.prototype.concat.call(object, array)); |
| 62 assertEquals(['a', 'a'], Array.prototype.concat.call(object, object)); |
| 63 |
| 64 delete Object.prototype[Symbol.isConcatSpreadable]; |
| 65 testConcatDefaults(); |
OLD | NEW |