Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: test/mjsunit/harmony/array-concat.js

Issue 771483002: Implement ES6 @@isConcatSpreadable (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime/runtime-array.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/array-concat.js
diff --git a/test/mjsunit/array-concat.js b/test/mjsunit/harmony/array-concat.js
similarity index 69%
copy from test/mjsunit/array-concat.js
copy to test/mjsunit/harmony/array-concat.js
index 97bd85aca2e646cd391558e0648458575d4e3c8b..a443215d424a23bdb1f4a8c330941ab8e7a63750 100644
--- a/test/mjsunit/array-concat.js
+++ b/test/mjsunit/harmony/array-concat.js
@@ -1,35 +1,115 @@
-// 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
+
+"use strict";
+
+(function testArrayConcatArity() {
Dmitry Lomov (no reviews) 2014/12/10 14:41:59 Please add a test that sets isConcatSpreadable on
caitp (gmail) 2014/12/10 15:29:20 Acknowledged --- but reading the draft, I am not s
+ 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);
+})();
+
+
+// ES5 tests
var poses;
+var pos;
poses = [140, 4000000000];
while (pos = poses.shift()) {
« no previous file with comments | « src/runtime/runtime-array.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698