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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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: --harmony-rest-parameters --harmony-arrow-functions
6
7 (function testRestIndex() {
8 assertEquals(5, ((...args) => args.length)(1,2,3,4,5));
9 assertEquals(4, ((a, ...args) => args.length)(1,2,3,4,5));
10 assertEquals(3, ((a, b, ...args) => args.length)(1,2,3,4,5));
11 assertEquals(2, ((a, b, c, ...args) => args.length)(1,2,3,4,5));
12 assertEquals(1, ((a, b, c, d, ...args) => args.length)(1,2,3,4,5));
13 assertEquals(0, ((a, b, c, d, e, ...args) => args.length)(1,2,3,4,5));
14 })();
15
16 // strictTest and sloppyTest should be called with descending natural
17 // numbers, as in:
18 //
19 // strictTest(6,5,4,3,2,1)
20 //
21 var strictTest = (a, b, ...c) => {
22 "use strict";
23 assertEquals(Array, c.constructor);
24 assertTrue(Array.isArray(c));
25
26 var expectedLength = (a === undefined) ? 0 : a - 2;
27 assertEquals(expectedLength, c.length);
28
29 for (var i = 2; i < a; ++i) {
30 assertEquals(c[i - 2], a - i);
31 }
32 }
33
34 var sloppyTest = (a, b, ...c) => {
35 assertEquals(Array, c.constructor);
36 assertTrue(Array.isArray(c));
37
38 var expectedLength = (a === undefined) ? 0 : a - 2;
39 assertEquals(expectedLength, c.length);
40
41 for (var i = 2; i < a; ++i) {
42 assertEquals(c[i - 2], a - i);
43 }
44 }
45
46
47 var O = {
48 strict: strictTest,
49 sloppy: sloppyTest
50 };
51
52 (function testStrictRestParamArity() {
53 assertEquals(2, strictTest.length);
54 assertEquals(2, O.strict.length);
55 })();
56
57
58 (function testRestParamsStrictMode() {
59 strictTest();
60 strictTest(2, 1);
61 strictTest(6, 5, 4, 3, 2, 1);
62 strictTest(3, 2, 1);
63 O.strict();
64 O.strict(2, 1);
65 O.strict(6, 5, 4, 3, 2, 1);
66 O.strict(3, 2, 1);
67 })();
68
69
70 (function testRestParamsStrictModeApply() {
71 strictTest.apply(null, []);
72 strictTest.apply(null, [2, 1]);
73 strictTest.apply(null, [6, 5, 4, 3, 2, 1]);
74 strictTest.apply(null, [3, 2, 1]);
75 O.strict.apply(O, []);
76 O.strict.apply(O, [2, 1]);
77 O.strict.apply(O, [6, 5, 4, 3, 2, 1]);
78 O.strict.apply(O, [3, 2, 1]);
79 })();
80
81
82 (function testRestParamsStrictModeCall() {
83 strictTest.call(null);
84 strictTest.call(null, 2, 1);
85 strictTest.call(null, 6, 5, 4, 3, 2, 1);
86 strictTest.call(null, 3, 2, 1);
87 O.strict.call(O);
88 O.strict.call(O, 2, 1);
89 O.strict.call(O, 6, 5, 4, 3, 2, 1);
90 O.strict.call(O, 3, 2, 1);
91 })();
92
93
94 (function testsloppyRestParamArity() {
95 assertEquals(2, sloppyTest.length);
96 assertEquals(2, O.sloppy.length);
97 })();
98
99
100 (function testRestParamssloppyMode() {
101 sloppyTest();
102 sloppyTest(2, 1);
103 sloppyTest(6, 5, 4, 3, 2, 1);
104 sloppyTest(3, 2, 1);
105 O.sloppy();
106 O.sloppy(2, 1);
107 O.sloppy(6, 5, 4, 3, 2, 1);
108 O.sloppy(3, 2, 1);
109 })();
110
111
112 (function testRestParamssloppyModeApply() {
113 sloppyTest.apply(null, []);
114 sloppyTest.apply(null, [2, 1]);
115 sloppyTest.apply(null, [6, 5, 4, 3, 2, 1]);
116 sloppyTest.apply(null, [3, 2, 1]);
117 O.sloppy.apply(O, []);
118 O.sloppy.apply(O, [2, 1]);
119 O.sloppy.apply(O, [6, 5, 4, 3, 2, 1]);
120 O.sloppy.apply(O, [3, 2, 1]);
121 })();
122
123
124 (function testRestParamssloppyModeCall() {
125 sloppyTest.call(null);
126 sloppyTest.call(null, 2, 1);
127 sloppyTest.call(null, 6, 5, 4, 3, 2, 1);
128 sloppyTest.call(null, 3, 2, 1);
129 O.sloppy.call(O);
130 O.sloppy.call(O, 2, 1);
131 O.sloppy.call(O, 6, 5, 4, 3, 2, 1);
132 O.sloppy.call(O, 3, 2, 1);
133 })();
134
135
136 (function testUnmappedArguments() {
137 // Normal functions make their arguments object unmapped, but arrow
138 // functions don't have an arguments object anyway. Check that the
139 // right thing happens for arguments in arrow functions with rest
140 // parameters.
141 assertSame(arguments, ((...rest) => arguments)());
142 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698