Index: test/mjsunit/harmony/array-concat.js |
diff --git a/test/mjsunit/array-concat.js b/test/mjsunit/harmony/array-concat.js |
similarity index 63% |
copy from test/mjsunit/array-concat.js |
copy to test/mjsunit/harmony/array-concat.js |
index 97bd85aca2e646cd391558e0648458575d4e3c8b..548b27895f509d30a796054fa7c09d0381ae6fc6 100644 |
--- a/test/mjsunit/array-concat.js |
+++ b/test/mjsunit/harmony/array-concat.js |
@@ -1,35 +1,154 @@ |
-// Copyright 2008 the V8 project authors. All rights reserved. |
-// Redistribution and use in source and binary forms, with or without |
-// modification, are permitted provided that the following conditions are |
-// met: |
-// |
-// * Redistributions of source code must retain the above copyright |
-// notice, this list of conditions and the following disclaimer. |
-// * Redistributions in binary form must reproduce the above |
-// copyright notice, this list of conditions and the following |
-// disclaimer in the documentation and/or other materials provided |
-// with the distribution. |
-// * Neither the name of Google Inc. nor the names of its |
-// contributors may be used to endorse or promote products derived |
-// from this software without specific prior written permission. |
-// |
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
- |
-/** |
- * @fileoverview Test concat on small and large arrays |
- */ |
+// Copyright 2014 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// Flags: --harmony-arrays --harmony-classes |
Dmitry Lomov (no reviews)
2014/12/10 23:02:47
Add a test for sloppy arguments (install isConcatS
|
+ |
+"use strict"; |
+ |
+(function testArrayConcatArity() { |
+ assertEquals(1, Array.prototype.concat.length); |
+})(); |
+ |
+ |
+(function testArrayConcatNoPrototype() { |
+ assertEquals(void 0, Array.prototype.concat.prototype); |
+})(); |
+ |
+ |
+(function testArrayConcatDescriptor() { |
+ var desc = Object.getOwnPropertyDescriptor(Array.prototype, 'concat'); |
+ assertEquals(false, desc.enumerable); |
+})(); |
+ |
+ |
+(function testConcatArrayLike() { |
+ var obj = { |
+ "length": 6, |
+ "1": "A", |
+ "3": "B", |
+ "5": "C" |
+ }; |
+ obj[Symbol.isConcatSpreadable] = true; |
+ var obj2 = { length: 3, "0": "0", "1": "1", "2": "2" }; |
+ var arr = ["X", "Y", "Z"]; |
+ assertEquals([void 0, "A", void 0, "B", void 0, "C", |
+ { "length": 3, "0": "0", "1": "1", "2": "2" }, |
+ "X", "Y", "Z"], Array.prototype.concat.call(obj, obj2, arr)); |
+})(); |
+ |
+ |
+(function testConcatHoleyArray() { |
+ var arr = []; |
+ arr[4] = "Item 4"; |
+ arr[8] = "Item 8"; |
+ var arr2 = [".", "!", "?"]; |
+ assertEquals([void 0, void 0, void 0, void 0, "Item 4", void 0, void 0, |
+ void 0, "Item 8", ".", "!", "?"], arr.concat(arr2)); |
+})(); |
+ |
+ |
+(function testIsConcatSpreadableGetterThrows() { |
+ function MyError() {} |
+ var obj = {}; |
+ Object.defineProperty(obj, Symbol.isConcatSpreadable, { |
+ get: function() { throw new MyError(); } |
+ }); |
+ |
+ assertThrows(function() { |
+ [].concat(obj); |
+ }, MyError); |
+ |
+ assertThrows(function() { |
+ Array.prototype.concat.call(obj, 1, 2, 3); |
+ }, MyError); |
+})(); |
+ |
+ |
+(function testConcatLengthThrows() { |
+ function MyError() {} |
+ var obj = {}; |
+ obj[Symbol.isConcatSpreadable] = true; |
+ Object.defineProperty(obj, "length", { |
+ get: function() { throw new MyError(); } |
+ }); |
+ |
+ assertThrows(function() { |
+ [].concat(obj); |
+ }, MyError); |
+ |
+ assertThrows(function() { |
+ Array.prototype.concat.call(obj, 1, 2, 3); |
+ }, MyError); |
+})(); |
+ |
+ |
+(function testConcatArraySubclass() { |
+ // TODO(caitp): when concat is called on instances of classes which extend |
+ // Array, they should: |
+ // |
+ // - return an instance of the class, rather than an Array instance (if from |
+ // same Realm) |
+ // - always treat such classes as concat-spreadable |
+})(); |
+ |
+ |
+(function testConcatNonArray() { |
+ class NonArray { |
+ constructor() { Array.apply(this, arguments); } |
+ }; |
+ |
+ var obj = new NonArray(1,2,3); |
+ var result = Array.prototype.concat.call(obj, 4, 5, 6); |
+ assertEquals(Array, result.constructor); |
+ assertEquals([obj,4,5,6], result); |
+ assertFalse(result instanceof NonArray); |
+})(); |
+ |
+ |
+function testConcatTypedArray(type, elems, modulo) { |
+ var items = new Array(elems); |
+ for (var i = 0; i < elems; ++i) { |
+ items[i] = modulo === false ? i : elems % modulo; |
+ } |
+ var ta = new type(items); |
+ assertEquals([ta, ta], [].concat(ta, ta)); |
+ ta[Symbol.isConcatSpreadable] = true; |
+ assertEquals(items, [].concat(ta)); |
+} |
+ |
+(function testConcatSmallTypedArray() { |
+ var max = [2^8, 2^16, 2^32, false, false]; |
+ [ |
+ Uint8Array, |
+ Uint16Array, |
+ Uint32Array, |
+ Float32Array, |
+ Float64Array |
+ ].forEach(function(ctor, i) { |
+ testConcatTypedArray(ctor, 150, max[i]); |
Dmitry Lomov (no reviews)
2014/12/10 16:36:37
Make this smaller, like 2. Default value of FLAG_t
|
+ }); |
+})(); |
+ |
+ |
+(function testConcatLargeTypedArray() { |
+ var max = [2^8, 2^16, 2^32, false, false]; |
+ [ |
+ Uint8Array, |
+ Uint16Array, |
+ Uint32Array, |
+ Float32Array, |
+ Float64Array |
+ ].forEach(function(ctor, i) { |
+ testConcatTypedArray(ctor, 4000000, max[i]); |
+ }); |
+})(); |
+ |
+ |
+// ES5 tests |
var poses; |
+var pos; |
poses = [140, 4000000000]; |
while (pos = poses.shift()) { |