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

Side by Side Diff: test/mjsunit/harmony/arrow-rest-params-lazy-parsing.js

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

Powered by Google App Engine
This is Rietveld 408576698