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