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

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

Issue 1300103005: [parser] disallow language mode directive in body of function with non-simple parameters (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: flag implications don't work in test suite? Created 5 years, 3 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
1 // Copyright 2014 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --harmony-rest-parameters 5 // Flags: --harmony-rest-parameters
6 6
7 (function testRestIndex() { 7 (function testRestIndex() {
8 assertEquals(5, (function(...args) { return args.length; })(1,2,3,4,5)); 8 assertEquals(5, (function(...args) { return args.length; })(1,2,3,4,5));
9 assertEquals(4, (function(a, ...args) { return args.length; })(1,2,3,4,5)); 9 assertEquals(4, (function(a, ...args) { return args.length; })(1,2,3,4,5));
10 assertEquals(3, (function(a, b, ...args) { return args.length; })(1,2,3,4,5)); 10 assertEquals(3, (function(a, b, ...args) { return args.length; })(1,2,3,4,5));
11 assertEquals(2, (function(a, b, c, ...args) { 11 assertEquals(2, (function(a, b, c, ...args) {
12 return args.length; })(1,2,3,4,5)); 12 return args.length; })(1,2,3,4,5));
13 assertEquals(1, (function(a, b, c, d, ...args) { 13 assertEquals(1, (function(a, b, c, d, ...args) {
14 return args.length; })(1,2,3,4,5)); 14 return args.length; })(1,2,3,4,5));
15 assertEquals(0, (function(a, b, c, d, e, ...args) { 15 assertEquals(0, (function(a, b, c, d, e, ...args) {
16 return args.length; })(1,2,3,4,5)); 16 return args.length; })(1,2,3,4,5));
17 })(); 17 })();
18 18
19 function strictTest(a, b, ...c) { 19 var strictTest = (function() {
20 "use strict"; 20 "use strict";
21 assertEquals(Array, c.constructor); 21 return function strictTest(a, b, ...c) {
22 assertTrue(Array.isArray(c)); 22 assertEquals(Array, c.constructor);
23 assertTrue(Array.isArray(c));
23 24
24 var expectedLength = arguments.length >= 3 ? arguments.length - 2 : 0; 25 var expectedLength = arguments.length >= 3 ? arguments.length - 2 : 0;
25 assertEquals(expectedLength, c.length); 26 assertEquals(expectedLength, c.length);
26 27
27 for (var i = 2, j = 0; i < arguments.length; ++i) { 28 for (var i = 2, j = 0; i < arguments.length; ++i) {
28 assertEquals(c[j++], arguments[i]); 29 assertEquals(c[j++], arguments[i]);
29 } 30 }
30 } 31 };
32 })();
31 33
32 function sloppyTest(a, b, ...c) { 34 function sloppyTest(a, b, ...c) {
33 assertEquals(Array, c.constructor); 35 assertEquals(Array, c.constructor);
34 assertTrue(Array.isArray(c)); 36 assertTrue(Array.isArray(c));
35 37
36 var expectedLength = arguments.length >= 3 ? arguments.length - 2 : 0; 38 var expectedLength = arguments.length >= 3 ? arguments.length - 2 : 0;
37 assertEquals(expectedLength, c.length); 39 assertEquals(expectedLength, c.length);
38 40
39 for (var i = 2, j = 0; i < arguments.length; ++i) { 41 for (var i = 2, j = 0; i < arguments.length; ++i) {
40 assertEquals(c[j++], arguments[i]); 42 assertEquals(c[j++], arguments[i]);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 assertThrows(function(...rest) { return arguments.caller; }, TypeError); 139 assertThrows(function(...rest) { return arguments.caller; }, TypeError);
138 assertThrows(function(...rest) { return arguments.callee; }, TypeError); 140 assertThrows(function(...rest) { return arguments.callee; }, TypeError);
139 // TODO(caitp): figure out why this doesn't throw sometimes, even though the 141 // TODO(caitp): figure out why this doesn't throw sometimes, even though the
140 // getter always does =) 142 // getter always does =)
141 // assertThrows(function(...rest) { arguments.caller = 1; }, TypeError); 143 // assertThrows(function(...rest) { arguments.caller = 1; }, TypeError);
142 // assertThrows(function(...rest) { arguments.callee = 1; }, TypeError); 144 // assertThrows(function(...rest) { arguments.callee = 1; }, TypeError);
143 })(); 145 })();
144 146
145 147
146 (function testNoAliasArgumentsStrict() { 148 (function testNoAliasArgumentsStrict() {
147 function strictF(a, ...rest) { 149 ((function() {
148 "use strict"; 150 "use strict";
149 arguments[0] = 1; 151 return (function strictF(a, ...rest) {
150 assertEquals(3, a); 152 arguments[0] = 1;
151 arguments[1] = 2; 153 assertEquals(3, a);
152 assertArrayEquals([4, 5], rest); 154 arguments[1] = 2;
153 } 155 assertArrayEquals([4, 5], rest);
154 strictF(3, 4, 5); 156 });
157 })())(3, 4, 5);
155 })(); 158 })();
156 159
157 160
158 (function testNoAliasArgumentsSloppy() { 161 (function testNoAliasArgumentsSloppy() {
159 function sloppyF(a, ...rest) { 162 function sloppyF(a, ...rest) {
160 arguments[0] = 1; 163 arguments[0] = 1;
161 assertEquals(3, a); 164 assertEquals(3, a);
162 arguments[1] = 2; 165 arguments[1] = 2;
163 assertArrayEquals([4, 5], rest); 166 assertArrayEquals([4, 5], rest);
164 } 167 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 args.push(arguments[i]); 208 args.push(arguments[i]);
206 } 209 }
207 assertEquals(args, b); 210 assertEquals(args, b);
208 } 211 }
209 } 212 }
210 213
211 var c = new Child(1, 2, 3); 214 var c = new Child(1, 2, 3);
212 assertEquals([1, 2, 3], c.child); 215 assertEquals([1, 2, 3], c.child);
213 assertEquals([1, 2, 3], c.base); 216 assertEquals([1, 2, 3], c.base);
214 })(); 217 })();
218
219 (function TestDirectiveThrows() {
220 "use strict";
221
222 assertThrows(
223 function(){ eval("function(...rest){'use strict';}") }, SyntaxError);
224 assertThrows(function(){ eval("(...rest) => {'use strict';}") }, SyntaxError);
225 assertThrows(
226 function(){ eval("(class{foo(...rest) {'use strict';}});") }, SyntaxError);
227
228 assertThrows(
229 function(){ eval("function(a, ...rest){'use strict';}") }, SyntaxError);
230 assertThrows(
231 function(){ eval("(a, ...rest) => {'use strict';}") }, SyntaxError);
232 assertThrows(
233 function(){ eval("(class{foo(a, ...rest) {'use strict';}});") },
234 SyntaxError);
235 })();
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/destructuring.js ('k') | test/mjsunit/harmony/spread-call-super-property.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698