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 9var array = [1, 2, 3]; 10var object = {length: 1, '0': 'a'}; 11 12function 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 23testConcatDefaults(); 24 25Array.prototype[Symbol.isConcatSpreadable] = false; 26 27assertEquals([[], array], [].concat(array)); 28assertEquals([array, []], array.concat([])); 29assertEquals([array, array], array.concat(array)); 30assertEquals([[], object], [].concat(object)); 31assertEquals([array, object], array.concat(object)); 32assertEquals([object, []], Array.prototype.concat.call(object,[])); 33assertEquals([object, array], Array.prototype.concat.call(object, array)); 34assertEquals([object, object], Array.prototype.concat.call(object, object)); 35 36Array.prototype[Symbol.isConcatSpreadable] = true; 37 38assertEquals(array, [].concat(array)); 39assertEquals(array, array.concat([])); 40assertEquals([1, 2, 3, 1, 2, 3], array.concat(array)); 41assertEquals([object], [].concat(object)); 42assertEquals([1, 2, 3, object], array.concat(object)); 43assertEquals([object], Array.prototype.concat.call(object,[])); 44assertEquals([object, 1, 2, 3], Array.prototype.concat.call(object, array)); 45assertEquals([object, object], Array.prototype.concat.call(object, object)); 46 47delete Array.prototype[Symbol.isConcatSpreadable]; 48testConcatDefaults(); 49