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

Unified Diff: test/mjsunit/harmony/arrow-rest-params.js

Issue 1178523002: Support rest parameters in arrow functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Fix error locations for param-after-rest errors Created 5 years, 6 months 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
Index: test/mjsunit/harmony/arrow-rest-params.js
diff --git a/test/mjsunit/harmony/arrow-rest-params.js b/test/mjsunit/harmony/arrow-rest-params.js
new file mode 100644
index 0000000000000000000000000000000000000000..b1e8dcc1b99b484a9257b1f3a4c73ad5c94db0e1
--- /dev/null
+++ b/test/mjsunit/harmony/arrow-rest-params.js
@@ -0,0 +1,142 @@
+// 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-rest-parameters --harmony-arrow-functions
+
+(function testRestIndex() {
+ assertEquals(5, ((...args) => args.length)(1,2,3,4,5));
+ assertEquals(4, ((a, ...args) => args.length)(1,2,3,4,5));
+ assertEquals(3, ((a, b, ...args) => args.length)(1,2,3,4,5));
+ assertEquals(2, ((a, b, c, ...args) => args.length)(1,2,3,4,5));
+ assertEquals(1, ((a, b, c, d, ...args) => args.length)(1,2,3,4,5));
+ assertEquals(0, ((a, b, c, d, e, ...args) => args.length)(1,2,3,4,5));
+})();
+
+// strictTest and sloppyTest should be called with descending natural
+// numbers, as in:
+//
+// strictTest(6,5,4,3,2,1)
+//
+var strictTest = (a, b, ...c) => {
+ "use strict";
+ assertEquals(Array, c.constructor);
+ assertTrue(Array.isArray(c));
+
+ var expectedLength = (a === undefined) ? 0 : a - 2;
+ assertEquals(expectedLength, c.length);
+
+ for (var i = 2; i < a; ++i) {
+ assertEquals(c[i - 2], a - i);
+ }
+}
+
+var sloppyTest = (a, b, ...c) => {
+ assertEquals(Array, c.constructor);
+ assertTrue(Array.isArray(c));
+
+ var expectedLength = (a === undefined) ? 0 : a - 2;
+ assertEquals(expectedLength, c.length);
+
+ for (var i = 2; i < a; ++i) {
+ assertEquals(c[i - 2], a - i);
+ }
+}
+
+
+var O = {
+ strict: strictTest,
+ sloppy: sloppyTest
+};
+
+(function testStrictRestParamArity() {
+ assertEquals(2, strictTest.length);
+ assertEquals(2, O.strict.length);
+})();
+
+
+(function testRestParamsStrictMode() {
+ strictTest();
+ strictTest(2, 1);
+ strictTest(6, 5, 4, 3, 2, 1);
+ strictTest(3, 2, 1);
+ O.strict();
+ O.strict(2, 1);
+ O.strict(6, 5, 4, 3, 2, 1);
+ O.strict(3, 2, 1);
+})();
+
+
+(function testRestParamsStrictModeApply() {
+ strictTest.apply(null, []);
+ strictTest.apply(null, [2, 1]);
+ strictTest.apply(null, [6, 5, 4, 3, 2, 1]);
+ strictTest.apply(null, [3, 2, 1]);
+ O.strict.apply(O, []);
+ O.strict.apply(O, [2, 1]);
+ O.strict.apply(O, [6, 5, 4, 3, 2, 1]);
+ O.strict.apply(O, [3, 2, 1]);
+})();
+
+
+(function testRestParamsStrictModeCall() {
+ strictTest.call(null);
+ strictTest.call(null, 2, 1);
+ strictTest.call(null, 6, 5, 4, 3, 2, 1);
+ strictTest.call(null, 3, 2, 1);
+ O.strict.call(O);
+ O.strict.call(O, 2, 1);
+ O.strict.call(O, 6, 5, 4, 3, 2, 1);
+ O.strict.call(O, 3, 2, 1);
+})();
+
+
+(function testsloppyRestParamArity() {
+ assertEquals(2, sloppyTest.length);
+ assertEquals(2, O.sloppy.length);
+})();
+
+
+(function testRestParamssloppyMode() {
+ sloppyTest();
+ sloppyTest(2, 1);
+ sloppyTest(6, 5, 4, 3, 2, 1);
+ sloppyTest(3, 2, 1);
+ O.sloppy();
+ O.sloppy(2, 1);
+ O.sloppy(6, 5, 4, 3, 2, 1);
+ O.sloppy(3, 2, 1);
+})();
+
+
+(function testRestParamssloppyModeApply() {
+ sloppyTest.apply(null, []);
+ sloppyTest.apply(null, [2, 1]);
+ sloppyTest.apply(null, [6, 5, 4, 3, 2, 1]);
+ sloppyTest.apply(null, [3, 2, 1]);
+ O.sloppy.apply(O, []);
+ O.sloppy.apply(O, [2, 1]);
+ O.sloppy.apply(O, [6, 5, 4, 3, 2, 1]);
+ O.sloppy.apply(O, [3, 2, 1]);
+})();
+
+
+(function testRestParamssloppyModeCall() {
+ sloppyTest.call(null);
+ sloppyTest.call(null, 2, 1);
+ sloppyTest.call(null, 6, 5, 4, 3, 2, 1);
+ sloppyTest.call(null, 3, 2, 1);
+ O.sloppy.call(O);
+ O.sloppy.call(O, 2, 1);
+ O.sloppy.call(O, 6, 5, 4, 3, 2, 1);
+ O.sloppy.call(O, 3, 2, 1);
+})();
+
+
+(function testUnmappedArguments() {
+ // Normal functions make their arguments object unmapped, but arrow
+ // functions don't have an arguments object anyway. Check that the
+ // right thing happens for arguments in arrow functions with rest
+ // parameters.
+ assertSame(arguments, ((...rest) => arguments)());
+})();

Powered by Google App Engine
This is Rietveld 408576698