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

Side by Side Diff: test/mjsunit/strong/function-arity.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
« no previous file with comments | « test/mjsunit/strong/destructuring.js ('k') | test/mjsunit/strong/literals.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 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: --strong-mode --harmony-arrow-functions --harmony-reflect 5 // Flags: --strong-mode --harmony-arrow-functions --harmony-reflect
6 // Flags: --harmony-spreadcalls --harmony-rest-parameters --allow-natives-syntax 6 // Flags: --harmony-spreadcalls --harmony-rest-parameters --allow-natives-syntax
7 7
8 'use strict'; 8 'use strict';
9 9
10 10
11 function generateArguments(n, prefix) { 11 function generateArguments(n, prefix) {
12 let a = []; 12 let a = [];
13 if (prefix) { 13 if (prefix) {
14 a.push(prefix); 14 a.push(prefix);
15 } 15 }
16 for (let i = 0; i < n; i++) { 16 for (let i = 0; i < n; i++) {
17 a.push(String(i)); 17 a.push(String(i));
18 } 18 }
19 19
20 return a.join(', '); 20 return a.join(', ');
21 } 21 }
22 22
23 23
24 function generateParams(n) { 24 function generateParams(n, directive_in_body) {
25 let a = []; 25 let a = [];
26 for (let i = 0; i < n; i++) { 26 for (let i = 0; i < n; i++) {
27 a[i] = `p${i}`; 27 a[i] = `p${i}`;
28 } 28 }
29 return a.join(', '); 29 return a.join(', ');
30 } 30 }
31 31
32 function generateParamsWithRest(n) { 32 function generateParamsWithRest(n, directive_in_body) {
33 let a = []; 33 let a = [];
34 let i = 0; 34 let i = 0;
35 for (; i < n; i++) { 35 for (; i < n; i++) {
36 a[i] = `p${i}`; 36 a[i] = `p${i}`;
37 } 37 }
38 a.push(`...p${i}`) 38 if (!directive_in_body) {
39 // If language mode directive occurs in body, rest parameters will trigger
40 // an early error regardless of language mode.
41 a.push(`...p${i}`);
42 }
39 return a.join(', '); 43 return a.join(', ');
40 } 44 }
41 45
42 46
43 function generateSpread(n) { 47 function generateSpread(n) {
44 return `...[${generateArguments(n)}]`; 48 return `...[${generateArguments(n)}]`;
45 } 49 }
46 50
47 51
48 (function FunctionCall() { 52 (function FunctionCall() {
(...skipping 20 matching lines...) Expand all
69 `%_CallFunction(${generateArguments(argumentCount, 'undefined')}, 73 `%_CallFunction(${generateArguments(argumentCount, 'undefined')},
70 f)`, 74 f)`,
71 `%Call(${generateArguments(argumentCount, 'undefined')}, f)`, 75 `%Call(${generateArguments(argumentCount, 'undefined')}, f)`,
72 `%Apply(f, undefined, [${generateArguments(argumentCount)}], 0, 76 `%Apply(f, undefined, [${generateArguments(argumentCount)}], 0,
73 ${argumentCount})`, 77 ${argumentCount})`,
74 ]; 78 ];
75 79
76 for (let call of calls) { 80 for (let call of calls) {
77 let code = `'use strict'; ${def}; ${call};`; 81 let code = `'use strict'; ${def}; ${call};`;
78 if (argumentCount < parameterCount) { 82 if (argumentCount < parameterCount) {
83 print(code);
79 assertThrows(code, TypeError); 84 assertThrows(code, TypeError);
80 } else { 85 } else {
81 assertDoesNotThrow(code); 86 assertDoesNotThrow(code);
82 } 87 }
83 } 88 }
84 } 89 }
85 90
86 let calls = [ 91 let calls = [
87 `f.call()`, 92 `f.call()`,
88 `f.apply()`, 93 `f.apply()`,
(...skipping 10 matching lines...) Expand all
99 } 104 }
100 } 105 }
101 })(); 106 })();
102 107
103 108
104 (function MethodCall() { 109 (function MethodCall() {
105 for (let genParams of [generateParams, generateParamsWithRest]) { 110 for (let genParams of [generateParams, generateParamsWithRest]) {
106 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { 111 for (let parameterCount = 0; parameterCount < 3; parameterCount++) {
107 let defs = [ 112 let defs = [
108 `let o = new class { 113 `let o = new class {
109 m(${genParams(parameterCount)}) { 'use strong'; } 114 m(${genParams(parameterCount, true)}) { 'use strong'; }
110 }`, 115 }`,
111 `let o = new class { 116 `let o = new class {
112 *m(${genParams(parameterCount)}) { 'use strong'; } 117 *m(${genParams(parameterCount, true)}) { 'use strong'; }
113 }`, 118 }`,
114 `let o = { m(${genParams(parameterCount)}) { 'use strong'; } }`, 119 `let o = { m(${genParams(parameterCount, true)}) { 'use strong'; } }`,
115 `let o = { *m(${genParams(parameterCount)}) { 'use strong'; } }`, 120 `let o = { *m(${genParams(parameterCount, true)}) { 'use strong'; } }`,
116 `'use strong'; 121 `'use strong';
117 let o = new class { m(${genParams(parameterCount)}) {} }`, 122 let o = new class { m(${genParams(parameterCount)}) {} }`,
118 `'use strong'; 123 `'use strong';
119 let o = new class { *m(${genParams(parameterCount)}) {} }`, 124 let o = new class { *m(${genParams(parameterCount)}) {} }`,
120 `'use strong'; let o = { m(${genParams(parameterCount)}) {} }`, 125 `'use strong'; let o = { m(${genParams(parameterCount)}) {} }`,
121 `'use strong'; let o = { *m(${genParams(parameterCount)}) {} }`, 126 `'use strong'; let o = { *m(${genParams(parameterCount)}) {} }`,
122 ]; 127 ];
123 for (let def of defs) { 128 for (let def of defs) {
124 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { 129 for (let argumentCount = 0; argumentCount < 3; argumentCount++) {
125 let calls = [ 130 let calls = [
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 171
167 (function Constructor() { 172 (function Constructor() {
168 for (let genParams of [generateParams, generateParamsWithRest]) { 173 for (let genParams of [generateParams, generateParamsWithRest]) {
169 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { 174 for (let argumentCount = 0; argumentCount < 3; argumentCount++) {
170 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { 175 for (let parameterCount = 0; parameterCount < 3; parameterCount++) {
171 let defs = [ 176 let defs = [
172 `'use strong'; 177 `'use strong';
173 class C { constructor(${genParams(parameterCount)}) {} }`, 178 class C { constructor(${genParams(parameterCount)}) {} }`,
174 `'use strict'; 179 `'use strict';
175 class C { 180 class C {
176 constructor(${genParams(parameterCount)}) { 'use strong'; } 181 constructor(${genParams(parameterCount, true)}) { 'use strong'; }
177 }`, 182 }`,
178 ]; 183 ];
179 for (let def of defs) { 184 for (let def of defs) {
180 let calls = [ 185 let calls = [
181 `new C(${generateArguments(argumentCount)})`, 186 `new C(${generateArguments(argumentCount)})`,
182 `new C(${generateSpread(argumentCount)})`, 187 `new C(${generateSpread(argumentCount)})`,
183 `Reflect.construct(C, [${generateArguments(argumentCount)}])`, 188 `Reflect.construct(C, [${generateArguments(argumentCount)}])`,
184 ]; 189 ];
185 for (let call of calls) { 190 for (let call of calls) {
186 let code = `${def}; ${call};`; 191 let code = `${def}; ${call};`;
(...skipping 20 matching lines...) Expand all
207 class B { 212 class B {
208 constructor(${genParams(parameterCount)}) {} 213 constructor(${genParams(parameterCount)}) {}
209 } 214 }
210 class C extends B { 215 class C extends B {
211 constructor() { 216 constructor() {
212 super(${genArgs(argumentCount)}); 217 super(${genArgs(argumentCount)});
213 } 218 }
214 }`, 219 }`,
215 `'use strict'; 220 `'use strict';
216 class B { 221 class B {
217 constructor(${genParams(parameterCount)}) { 'use strong'; } 222 constructor(${genParams(parameterCount, true)}) { 'use strong'; }
218 } 223 }
219 class C extends B { 224 class C extends B {
220 constructor() { 225 constructor() {
221 super(${genArgs(argumentCount)}); 226 super(${genArgs(argumentCount)});
222 } 227 }
223 }`, 228 }`,
224 ]; 229 ];
225 for (let def of defs) { 230 for (let def of defs) {
226 let code = `${def}; new C();`; 231 let code = `${def}; new C();`;
227 if (argumentCount < parameterCount) { 232 if (argumentCount < parameterCount) {
(...skipping 15 matching lines...) Expand all
243 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { 248 for (let argumentCount = 0; argumentCount < 3; argumentCount++) {
244 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { 249 for (let parameterCount = 0; parameterCount < 3; parameterCount++) {
245 let defs = [ 250 let defs = [
246 `'use strong'; 251 `'use strong';
247 class B { 252 class B {
248 constructor(${genParams(parameterCount)}) {} 253 constructor(${genParams(parameterCount)}) {}
249 } 254 }
250 class C extends B {}`, 255 class C extends B {}`,
251 `'use strict'; 256 `'use strict';
252 class B { 257 class B {
253 constructor(${genParams(parameterCount)}) { 'use strong'; } 258 constructor(${genParams(parameterCount, true)}) { 'use strong'; }
254 } 259 }
255 class C extends B {}`, 260 class C extends B {}`,
256 ]; 261 ];
257 for (let def of defs) { 262 for (let def of defs) {
258 let code = `${def}; new C(${genArgs(argumentCount)})`; 263 let code = `${def}; new C(${genArgs(argumentCount)})`;
259 if (argumentCount < parameterCount) { 264 if (argumentCount < parameterCount) {
260 assertThrows(code, TypeError); 265 assertThrows(code, TypeError);
261 } else { 266 } else {
262 assertDoesNotThrow(code); 267 assertDoesNotThrow(code);
263 } 268 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 if (argumentCount < parameterCount) { 351 if (argumentCount < parameterCount) {
347 assertThrows(code, TypeError); 352 assertThrows(code, TypeError);
348 } else { 353 } else {
349 assertDoesNotThrow(code); 354 assertDoesNotThrow(code);
350 } 355 }
351 } 356 }
352 } 357 }
353 } 358 }
354 } 359 }
355 })(); 360 })();
OLDNEW
« no previous file with comments | « test/mjsunit/strong/destructuring.js ('k') | test/mjsunit/strong/literals.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698