OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 // Flags: --allow-natives-syntax --harmony-concat-spreadable |
| 6 |
| 7 function arguments_with_length_getter(f) { |
| 8 arguments.__defineGetter__('length', f); |
| 9 return arguments; |
| 10 } |
| 11 |
| 12 var count = 0; |
| 13 function increment_count_return() { count++; return "boom"; } |
| 14 function increment_count_throw() { count++; throw "boom"; } |
| 15 |
| 16 // Do not read the length of an arguments object on the prototype chain of |
| 17 // an array. |
| 18 var a1 = []; |
| 19 %NormalizeElements(a1); |
| 20 a1.__proto__ = arguments_with_length_getter(increment_count_return); |
| 21 [].concat(a1); |
| 22 assertEquals(0, count); |
| 23 |
| 24 var a2 = []; |
| 25 %NormalizeElements(a2); |
| 26 a2.__proto__ = arguments_with_length_getter(increment_count_throw); |
| 27 [].concat(a2); |
| 28 assertEquals(0, count); |
| 29 |
| 30 // Do read the length of an arguments object if spreadable. |
| 31 var a3 = arguments_with_length_getter(increment_count_return); |
| 32 a3[Symbol.isConcatSpreadable] = true; |
| 33 [].concat(a3); |
| 34 assertEquals(1, count); |
| 35 |
| 36 var a4 = arguments_with_length_getter(increment_count_throw); |
| 37 a4[Symbol.isConcatSpreadable] = true; |
| 38 assertThrows(function() { [].concat(a4); }); |
| 39 assertEquals(2, count); |
| 40 |
| 41 // Do read the length of an arguments object on the prototype chain of |
| 42 // an object. |
| 43 var a5 = {}; |
| 44 a5.__proto__ = arguments_with_length_getter(increment_count_return); |
| 45 a5[Symbol.isConcatSpreadable] = true; |
| 46 [].concat(a5); |
| 47 assertEquals(3, count); |
| 48 |
| 49 var a6 = {}; |
| 50 a6.__proto__ = arguments_with_length_getter(increment_count_throw); |
| 51 a6[Symbol.isConcatSpreadable] = true; |
| 52 assertThrows(function() { [].concat(a6); }); |
| 53 assertEquals(4, count); |
OLD | NEW |