OLD | NEW |
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 103 } |
100 } | 104 } |
101 })(); | 105 })(); |
102 | 106 |
103 | 107 |
104 (function MethodCall() { | 108 (function MethodCall() { |
105 for (let genParams of [generateParams, generateParamsWithRest]) { | 109 for (let genParams of [generateParams, generateParamsWithRest]) { |
106 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { | 110 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { |
107 let defs = [ | 111 let defs = [ |
108 `let o = new class { | 112 `let o = new class { |
109 m(${genParams(parameterCount)}) { 'use strong'; } | 113 m(${genParams(parameterCount, true)}) { 'use strong'; } |
110 }`, | 114 }`, |
111 `let o = new class { | 115 `let o = new class { |
112 *m(${genParams(parameterCount)}) { 'use strong'; } | 116 *m(${genParams(parameterCount, true)}) { 'use strong'; } |
113 }`, | 117 }`, |
114 `let o = { m(${genParams(parameterCount)}) { 'use strong'; } }`, | 118 `let o = { m(${genParams(parameterCount, true)}) { 'use strong'; } }`, |
115 `let o = { *m(${genParams(parameterCount)}) { 'use strong'; } }`, | 119 `let o = { *m(${genParams(parameterCount, true)}) { 'use strong'; } }`, |
116 `'use strong'; | 120 `'use strong'; |
117 let o = new class { m(${genParams(parameterCount)}) {} }`, | 121 let o = new class { m(${genParams(parameterCount)}) {} }`, |
118 `'use strong'; | 122 `'use strong'; |
119 let o = new class { *m(${genParams(parameterCount)}) {} }`, | 123 let o = new class { *m(${genParams(parameterCount)}) {} }`, |
120 `'use strong'; let o = { m(${genParams(parameterCount)}) {} }`, | 124 `'use strong'; let o = { m(${genParams(parameterCount)}) {} }`, |
121 `'use strong'; let o = { *m(${genParams(parameterCount)}) {} }`, | 125 `'use strong'; let o = { *m(${genParams(parameterCount)}) {} }`, |
122 ]; | 126 ]; |
123 for (let def of defs) { | 127 for (let def of defs) { |
124 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { | 128 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { |
125 let calls = [ | 129 let calls = [ |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 170 |
167 (function Constructor() { | 171 (function Constructor() { |
168 for (let genParams of [generateParams, generateParamsWithRest]) { | 172 for (let genParams of [generateParams, generateParamsWithRest]) { |
169 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { | 173 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { |
170 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { | 174 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { |
171 let defs = [ | 175 let defs = [ |
172 `'use strong'; | 176 `'use strong'; |
173 class C { constructor(${genParams(parameterCount)}) {} }`, | 177 class C { constructor(${genParams(parameterCount)}) {} }`, |
174 `'use strict'; | 178 `'use strict'; |
175 class C { | 179 class C { |
176 constructor(${genParams(parameterCount)}) { 'use strong'; } | 180 constructor(${genParams(parameterCount, true)}) { 'use strong'; } |
177 }`, | 181 }`, |
178 ]; | 182 ]; |
179 for (let def of defs) { | 183 for (let def of defs) { |
180 let calls = [ | 184 let calls = [ |
181 `new C(${generateArguments(argumentCount)})`, | 185 `new C(${generateArguments(argumentCount)})`, |
182 `new C(${generateSpread(argumentCount)})`, | 186 `new C(${generateSpread(argumentCount)})`, |
183 `Reflect.construct(C, [${generateArguments(argumentCount)}])`, | 187 `Reflect.construct(C, [${generateArguments(argumentCount)}])`, |
184 ]; | 188 ]; |
185 for (let call of calls) { | 189 for (let call of calls) { |
186 let code = `${def}; ${call};`; | 190 let code = `${def}; ${call};`; |
(...skipping 20 matching lines...) Expand all Loading... |
207 class B { | 211 class B { |
208 constructor(${genParams(parameterCount)}) {} | 212 constructor(${genParams(parameterCount)}) {} |
209 } | 213 } |
210 class C extends B { | 214 class C extends B { |
211 constructor() { | 215 constructor() { |
212 super(${genArgs(argumentCount)}); | 216 super(${genArgs(argumentCount)}); |
213 } | 217 } |
214 }`, | 218 }`, |
215 `'use strict'; | 219 `'use strict'; |
216 class B { | 220 class B { |
217 constructor(${genParams(parameterCount)}) { 'use strong'; } | 221 constructor(${genParams(parameterCount, true)}) { 'use strong'; } |
218 } | 222 } |
219 class C extends B { | 223 class C extends B { |
220 constructor() { | 224 constructor() { |
221 super(${genArgs(argumentCount)}); | 225 super(${genArgs(argumentCount)}); |
222 } | 226 } |
223 }`, | 227 }`, |
224 ]; | 228 ]; |
225 for (let def of defs) { | 229 for (let def of defs) { |
226 let code = `${def}; new C();`; | 230 let code = `${def}; new C();`; |
227 if (argumentCount < parameterCount) { | 231 if (argumentCount < parameterCount) { |
(...skipping 15 matching lines...) Expand all Loading... |
243 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { | 247 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { |
244 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { | 248 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { |
245 let defs = [ | 249 let defs = [ |
246 `'use strong'; | 250 `'use strong'; |
247 class B { | 251 class B { |
248 constructor(${genParams(parameterCount)}) {} | 252 constructor(${genParams(parameterCount)}) {} |
249 } | 253 } |
250 class C extends B {}`, | 254 class C extends B {}`, |
251 `'use strict'; | 255 `'use strict'; |
252 class B { | 256 class B { |
253 constructor(${genParams(parameterCount)}) { 'use strong'; } | 257 constructor(${genParams(parameterCount, true)}) { 'use strong'; } |
254 } | 258 } |
255 class C extends B {}`, | 259 class C extends B {}`, |
256 ]; | 260 ]; |
257 for (let def of defs) { | 261 for (let def of defs) { |
258 let code = `${def}; new C(${genArgs(argumentCount)})`; | 262 let code = `${def}; new C(${genArgs(argumentCount)})`; |
259 if (argumentCount < parameterCount) { | 263 if (argumentCount < parameterCount) { |
260 assertThrows(code, TypeError); | 264 assertThrows(code, TypeError); |
261 } else { | 265 } else { |
262 assertDoesNotThrow(code); | 266 assertDoesNotThrow(code); |
263 } | 267 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 if (argumentCount < parameterCount) { | 350 if (argumentCount < parameterCount) { |
347 assertThrows(code, TypeError); | 351 assertThrows(code, TypeError); |
348 } else { | 352 } else { |
349 assertDoesNotThrow(code); | 353 assertDoesNotThrow(code); |
350 } | 354 } |
351 } | 355 } |
352 } | 356 } |
353 } | 357 } |
354 } | 358 } |
355 })(); | 359 })(); |
OLD | NEW |