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 --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) { |
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) { |
| 33 let a = []; |
| 34 let i = 0; |
| 35 for (; i < n; i++) { |
| 36 a[i] = `p${i}`; |
| 37 } |
| 38 a.push(`...p${i}`) |
| 39 return a.join(', '); |
| 40 } |
| 41 |
32 | 42 |
33 function generateSpread(n) { | 43 function generateSpread(n) { |
34 return `...[${generateArguments(n)}]`; | 44 return `...[${generateArguments(n)}]`; |
35 } | 45 } |
36 | 46 |
37 | 47 |
38 (function FunctionCall() { | 48 (function FunctionCall() { |
39 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { | 49 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { |
40 let defs = [ | 50 let defs = [ |
41 `'use strong'; function f(${generateParams(parameterCount)}) {}`, | 51 `'use strong'; function f(${generateParams(parameterCount)}) {}`, |
| 52 `'use strong'; function f(${generateParamsWithRest(parameterCount)}) {}`, |
42 `'use strong'; function* f(${generateParams(parameterCount)}) {}`, | 53 `'use strong'; function* f(${generateParams(parameterCount)}) {}`, |
| 54 `'use strong'; function* f(${generateParamsWithRest(parameterCount)}) {}`, |
43 `'use strong'; let f = (${generateParams(parameterCount)}) => {}`, | 55 `'use strong'; let f = (${generateParams(parameterCount)}) => {}`, |
44 `function f(${generateParams(parameterCount)}) { 'use strong'; }`, | 56 `function f(${generateParams(parameterCount)}) { 'use strong'; }`, |
45 `function* f(${generateParams(parameterCount)}) { 'use strong'; }`, | 57 `function* f(${generateParams(parameterCount)}) { 'use strong'; }`, |
46 `let f = (${generateParams(parameterCount)}) => { 'use strong'; }`, | 58 `let f = (${generateParams(parameterCount)}) => { 'use strong'; }`, |
47 ]; | 59 ]; |
48 for (let def of defs) { | 60 for (let def of defs) { |
49 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { | 61 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { |
50 let calls = [ | 62 let calls = [ |
51 `f(${generateArguments(argumentCount)})`, | 63 `f(${generateArguments(argumentCount)})`, |
52 `f(${generateSpread(argumentCount)})`, | 64 `f(${generateSpread(argumentCount)})`, |
(...skipping 30 matching lines...) Expand all Loading... |
83 } else { | 95 } else { |
84 assertDoesNotThrow(code); | 96 assertDoesNotThrow(code); |
85 } | 97 } |
86 } | 98 } |
87 } | 99 } |
88 } | 100 } |
89 })(); | 101 })(); |
90 | 102 |
91 | 103 |
92 (function MethodCall() { | 104 (function MethodCall() { |
93 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { | 105 for (let genParams of [generateParams, generateParamsWithRest]) { |
94 let defs = [ | 106 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { |
95 `let o = new class { | 107 let defs = [ |
96 m(${generateParams(parameterCount)}) { 'use strong'; } | 108 `let o = new class { |
97 }`, | 109 m(${genParams(parameterCount)}) { 'use strong'; } |
98 `let o = new class { | 110 }`, |
99 *m(${generateParams(parameterCount)}) { 'use strong'; } | 111 `let o = new class { |
100 }`, | 112 *m(${genParams(parameterCount)}) { 'use strong'; } |
101 `let o = { m(${generateParams(parameterCount)}) { 'use strong'; } }`, | 113 }`, |
102 `let o = { *m(${generateParams(parameterCount)}) { 'use strong'; } }`, | 114 `let o = { m(${genParams(parameterCount)}) { 'use strong'; } }`, |
103 `'use strong'; | 115 `let o = { *m(${genParams(parameterCount)}) { 'use strong'; } }`, |
104 let o = new class { m(${generateParams(parameterCount)}) {} }`, | 116 `'use strong'; |
105 `'use strong'; | 117 let o = new class { m(${genParams(parameterCount)}) {} }`, |
106 let o = new class { *m(${generateParams(parameterCount)}) {} }`, | 118 `'use strong'; |
107 `'use strong'; let o = { m(${generateParams(parameterCount)}) {} }`, | 119 let o = new class { *m(${genParams(parameterCount)}) {} }`, |
108 `'use strong'; let o = { *m(${generateParams(parameterCount)}) {} }`, | 120 `'use strong'; let o = { m(${genParams(parameterCount)}) {} }`, |
109 ]; | 121 `'use strong'; let o = { *m(${genParams(parameterCount)}) {} }`, |
110 for (let def of defs) { | 122 ]; |
111 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { | 123 for (let def of defs) { |
| 124 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { |
| 125 let calls = [ |
| 126 `o.m(${generateArguments(argumentCount)})`, |
| 127 `o.m(${generateSpread(argumentCount)})`, |
| 128 `o.m.call(${generateArguments(argumentCount, 'o')})`, |
| 129 `o.m.call(o, ${generateSpread(argumentCount)})`, |
| 130 `o.m.apply(o, [${generateArguments(argumentCount)}])`, |
| 131 `o.m.bind(o)(${generateArguments(argumentCount)})`, |
| 132 `%_CallFunction(${generateArguments(argumentCount, 'o')}, o.m)`, |
| 133 `%Call(${generateArguments(argumentCount, 'o')}, o.m)`, |
| 134 `%Apply(o.m, o, [${generateArguments(argumentCount)}], 0, |
| 135 ${argumentCount})`, |
| 136 ]; |
| 137 |
| 138 for (let call of calls) { |
| 139 let code = `'use strict'; ${def}; ${call};`; |
| 140 if (argumentCount < parameterCount) { |
| 141 assertThrows(code, TypeError); |
| 142 } else { |
| 143 assertDoesNotThrow(code); |
| 144 } |
| 145 } |
| 146 } |
| 147 |
112 let calls = [ | 148 let calls = [ |
113 `o.m(${generateArguments(argumentCount)})`, | 149 `o.m.call()`, |
114 `o.m(${generateSpread(argumentCount)})`, | 150 `o.m.apply()`, |
115 `o.m.call(${generateArguments(argumentCount, 'o')})`, | 151 `o.m.apply(o)`, |
116 `o.m.call(o, ${generateSpread(argumentCount)})`, | |
117 `o.m.apply(o, [${generateArguments(argumentCount)}])`, | |
118 `o.m.bind(o)(${generateArguments(argumentCount)})`, | |
119 `%_CallFunction(${generateArguments(argumentCount, 'o')}, o.m)`, | |
120 `%Call(${generateArguments(argumentCount, 'o')}, o.m)`, | |
121 `%Apply(o.m, o, [${generateArguments(argumentCount)}], 0, | |
122 ${argumentCount})`, | |
123 ]; | 152 ]; |
124 | |
125 for (let call of calls) { | 153 for (let call of calls) { |
126 let code = `'use strict'; ${def}; ${call};`; | 154 let code = `'use strict'; ${def}; ${call};`; |
127 if (argumentCount < parameterCount) { | 155 if (parameterCount > 0) { |
128 assertThrows(code, TypeError); | 156 assertThrows(code, TypeError); |
129 } else { | 157 } else { |
130 assertDoesNotThrow(code); | 158 assertDoesNotThrow(code); |
131 } | 159 } |
132 } | 160 } |
133 } | 161 } |
134 | |
135 let calls = [ | |
136 `o.m.call()`, | |
137 `o.m.apply()`, | |
138 `o.m.apply(o)`, | |
139 ]; | |
140 for (let call of calls) { | |
141 let code = `'use strict'; ${def}; ${call};`; | |
142 if (parameterCount > 0) { | |
143 assertThrows(code, TypeError); | |
144 } else { | |
145 assertDoesNotThrow(code); | |
146 } | |
147 } | |
148 } | 162 } |
149 } | 163 } |
150 })(); | 164 })(); |
151 | 165 |
152 | 166 |
153 (function Constructor() { | 167 (function Constructor() { |
154 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { | 168 for (let genParams of [generateParams, generateParamsWithRest]) { |
155 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { | 169 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { |
156 let defs = [ | 170 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { |
157 `'use strong'; | 171 let defs = [ |
158 class C { constructor(${generateParams(parameterCount)}) {} }`, | 172 `'use strong'; |
159 `'use strict'; | 173 class C { constructor(${genParams(parameterCount)}) {} }`, |
160 class C { | 174 `'use strict'; |
161 constructor(${generateParams(parameterCount)}) { 'use strong'; } | 175 class C { |
162 }`, | 176 constructor(${genParams(parameterCount)}) { 'use strong'; } |
163 ]; | 177 }`, |
164 for (let def of defs) { | |
165 let calls = [ | |
166 `new C(${generateArguments(argumentCount)})`, | |
167 `new C(${generateSpread(argumentCount)})`, | |
168 `Reflect.construct(C, [${generateArguments(argumentCount)}])`, | |
169 ]; | 178 ]; |
170 for (let call of calls) { | 179 for (let def of defs) { |
171 let code = `${def}; ${call};`; | 180 let calls = [ |
172 if (argumentCount < parameterCount) { | 181 `new C(${generateArguments(argumentCount)})`, |
173 assertThrows(code, TypeError); | 182 `new C(${generateSpread(argumentCount)})`, |
174 } else { | 183 `Reflect.construct(C, [${generateArguments(argumentCount)}])`, |
175 assertDoesNotThrow(code); | 184 ]; |
| 185 for (let call of calls) { |
| 186 let code = `${def}; ${call};`; |
| 187 if (argumentCount < parameterCount) { |
| 188 assertThrows(code, TypeError); |
| 189 } else { |
| 190 assertDoesNotThrow(code); |
| 191 } |
176 } | 192 } |
177 } | 193 } |
178 } | 194 } |
179 } | 195 } |
180 } | 196 } |
181 })(); | 197 })(); |
182 | 198 |
183 | 199 |
184 (function DerivedConstructor() { | 200 (function DerivedConstructor() { |
185 for (let genArgs of [generateArguments, generateSpread]) { | 201 for (let genParams of [generateParams, generateParamsWithRest]) { |
186 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { | 202 for (let genArgs of [generateArguments, generateSpread]) { |
187 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { | 203 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { |
188 let defs = [ | 204 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { |
189 `'use strong'; | 205 let defs = [ |
190 class B { | 206 `'use strong'; |
191 constructor(${generateParams(parameterCount)}) {} | 207 class B { |
192 } | 208 constructor(${genParams(parameterCount)}) {} |
193 class C extends B { | |
194 constructor() { | |
195 super(${genArgs(argumentCount)}); | |
196 } | 209 } |
197 }`, | 210 class C extends B { |
198 `'use strict'; | 211 constructor() { |
199 class B { | 212 super(${genArgs(argumentCount)}); |
200 constructor(${generateParams(parameterCount)}) { 'use strong'; } | 213 } |
201 } | 214 }`, |
202 class C extends B { | 215 `'use strict'; |
203 constructor() { | 216 class B { |
204 super(${genArgs(argumentCount)}); | 217 constructor(${genParams(parameterCount)}) { 'use strong'; } |
205 } | 218 } |
206 }`, | 219 class C extends B { |
207 ]; | 220 constructor() { |
208 for (let def of defs) { | 221 super(${genArgs(argumentCount)}); |
209 let code = `${def}; new C();`; | 222 } |
210 if (argumentCount < parameterCount) { | 223 }`, |
211 assertThrows(code, TypeError); | 224 ]; |
212 } else { | 225 for (let def of defs) { |
213 assertDoesNotThrow(code); | 226 let code = `${def}; new C();`; |
| 227 if (argumentCount < parameterCount) { |
| 228 assertThrows(code, TypeError); |
| 229 } else { |
| 230 assertDoesNotThrow(code); |
| 231 } |
214 } | 232 } |
215 } | 233 } |
216 } | 234 } |
217 } | 235 } |
218 } | 236 } |
219 })(); | 237 })(); |
220 | 238 |
221 | 239 |
222 (function DerivedConstructorDefaultConstructorInDerivedClass() { | 240 (function DerivedConstructorDefaultConstructorInDerivedClass() { |
223 for (let genArgs of [generateArguments, generateSpread]) { | 241 for (let genParams of [generateParams, generateParamsWithRest]) { |
224 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { | 242 for (let genArgs of [generateArguments, generateSpread]) { |
225 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { | 243 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { |
226 let defs = [ | 244 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { |
227 `'use strong'; | 245 let defs = [ |
228 class B { | 246 `'use strong'; |
229 constructor(${generateParams(parameterCount)}) {} | 247 class B { |
230 } | 248 constructor(${genParams(parameterCount)}) {} |
231 class C extends B {}`, | 249 } |
232 `'use strict'; | 250 class C extends B {}`, |
233 class B { | 251 `'use strict'; |
234 constructor(${generateParams(parameterCount)}) { 'use strong'; } | 252 class B { |
235 } | 253 constructor(${genParams(parameterCount)}) { 'use strong'; } |
236 class C extends B {}`, | 254 } |
237 ]; | 255 class C extends B {}`, |
238 for (let def of defs) { | 256 ]; |
239 let code = `${def}; new C(${genArgs(argumentCount)})`; | 257 for (let def of defs) { |
240 if (argumentCount < parameterCount) { | 258 let code = `${def}; new C(${genArgs(argumentCount)})`; |
241 assertThrows(code, TypeError); | 259 if (argumentCount < parameterCount) { |
242 } else { | 260 assertThrows(code, TypeError); |
243 assertDoesNotThrow(code); | 261 } else { |
| 262 assertDoesNotThrow(code); |
| 263 } |
244 } | 264 } |
245 } | 265 } |
246 } | 266 } |
247 } | 267 } |
248 } | 268 } |
249 })(); | 269 })(); |
250 | 270 |
251 | 271 |
252 (function TestOptimized() { | 272 (function TestOptimized() { |
253 function f(x, y) { 'use strong'; } | 273 function f(x, y) { 'use strong'; } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 if (argumentCount < parameterCount) { | 346 if (argumentCount < parameterCount) { |
327 assertThrows(code, TypeError); | 347 assertThrows(code, TypeError); |
328 } else { | 348 } else { |
329 assertDoesNotThrow(code); | 349 assertDoesNotThrow(code); |
330 } | 350 } |
331 } | 351 } |
332 } | 352 } |
333 } | 353 } |
334 } | 354 } |
335 })(); | 355 })(); |
OLD | NEW |