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 --allow-natives-syntax |
7 | 7 |
8 'use strict'; | 8 'use strict'; |
9 | 9 |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 return a.join(', '); | 29 return a.join(', '); |
30 } | 30 } |
31 | 31 |
32 | 32 |
33 function generateSpread(n) { | 33 function generateSpread(n) { |
34 return `...[${generateArguments(n)}]`; | 34 return `...[${generateArguments(n)}]`; |
35 } | 35 } |
36 | 36 |
37 | 37 |
38 (function FunctionCall() { | 38 (function FunctionCall() { |
39 for (let parameter_count = 0; parameter_count < 3; parameter_count++) { | 39 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { |
40 let defs = [ | 40 let defs = [ |
41 `'use strong'; function f(${generateParams(parameter_count)}) {}`, | 41 `'use strong'; function f(${generateParams(parameterCount)}) {}`, |
42 `'use strong'; function* f(${generateParams(parameter_count)}) {}`, | 42 `'use strong'; function* f(${generateParams(parameterCount)}) {}`, |
43 `'use strong'; let f = (${generateParams(parameter_count)}) => {}`, | 43 `'use strong'; let f = (${generateParams(parameterCount)}) => {}`, |
44 `function f(${generateParams(parameter_count)}) { 'use strong'; }`, | 44 `function f(${generateParams(parameterCount)}) { 'use strong'; }`, |
45 `function* f(${generateParams(parameter_count)}) { 'use strong'; }`, | 45 `function* f(${generateParams(parameterCount)}) { 'use strong'; }`, |
46 `let f = (${generateParams(parameter_count)}) => { 'use strong'; }`, | 46 `let f = (${generateParams(parameterCount)}) => { 'use strong'; }`, |
47 ]; | 47 ]; |
48 for (let def of defs) { | 48 for (let def of defs) { |
49 for (let argument_count = 0; argument_count < 3; argument_count++) { | 49 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { |
50 let calls = [ | 50 let calls = [ |
51 `f(${generateArguments(argument_count)})`, | 51 `f(${generateArguments(argumentCount)})`, |
52 `f(${generateSpread(argument_count)})`, | 52 `f(${generateSpread(argumentCount)})`, |
53 `f.call(${generateArguments(argument_count, 'undefined')})`, | 53 `f.call(${generateArguments(argumentCount, 'undefined')})`, |
54 `f.call(undefined, ${generateSpread(argument_count)})`, | 54 `f.call(undefined, ${generateSpread(argumentCount)})`, |
55 `f.apply(undefined, [${generateArguments(argument_count)}])`, | 55 `f.apply(undefined, [${generateArguments(argumentCount)}])`, |
56 `f.bind(undefined)(${generateArguments(argument_count)})`, | 56 `f.bind(undefined)(${generateArguments(argumentCount)})`, |
57 `%_CallFunction(${generateArguments(argument_count, 'undefined')}, | 57 `%_CallFunction(${generateArguments(argumentCount, 'undefined')}, |
58 f)`, | 58 f)`, |
59 `%Call(${generateArguments(argument_count, 'undefined')}, f)`, | 59 `%Call(${generateArguments(argumentCount, 'undefined')}, f)`, |
60 `%Apply(f, undefined, [${generateArguments(argument_count)}], 0, | 60 `%Apply(f, undefined, [${generateArguments(argumentCount)}], 0, |
61 ${argument_count})`, | 61 ${argumentCount})`, |
62 ]; | 62 ]; |
63 | 63 |
64 for (let call of calls) { | 64 for (let call of calls) { |
65 let code = `'use strict'; ${def}; ${call};`; | 65 let code = `'use strict'; ${def}; ${call};`; |
66 if (argument_count < parameter_count) { | 66 if (argumentCount < parameterCount) { |
67 assertThrows(code, TypeError); | 67 assertThrows(code, TypeError); |
68 } else { | 68 } else { |
69 assertDoesNotThrow(code); | 69 assertDoesNotThrow(code); |
70 } | 70 } |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 let calls = [ | 74 let calls = [ |
75 `f.call()`, | 75 `f.call()`, |
76 `f.apply()`, | 76 `f.apply()`, |
77 `f.apply(undefined)`, | 77 `f.apply(undefined)`, |
78 ]; | 78 ]; |
79 for (let call of calls) { | 79 for (let call of calls) { |
80 let code = `'use strict'; ${def}; ${call};`; | 80 let code = `'use strict'; ${def}; ${call};`; |
81 if (parameter_count > 0) { | 81 if (parameterCount > 0) { |
82 assertThrows(code, TypeError); | 82 assertThrows(code, TypeError); |
83 } else { | 83 } else { |
84 assertDoesNotThrow(code); | 84 assertDoesNotThrow(code); |
85 } | 85 } |
86 } | 86 } |
87 } | 87 } |
88 } | 88 } |
89 })(); | 89 })(); |
90 | 90 |
91 | 91 |
92 (function MethodCall() { | 92 (function MethodCall() { |
93 for (let parameter_count = 0; parameter_count < 3; parameter_count++) { | 93 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { |
94 let defs = [ | 94 let defs = [ |
95 `let o = new class { | 95 `let o = new class { |
96 m(${generateParams(parameter_count)}) { 'use strong'; } | 96 m(${generateParams(parameterCount)}) { 'use strong'; } |
97 }`, | 97 }`, |
98 `let o = new class { | 98 `let o = new class { |
99 *m(${generateParams(parameter_count)}) { 'use strong'; } | 99 *m(${generateParams(parameterCount)}) { 'use strong'; } |
100 }`, | 100 }`, |
101 `let o = { m(${generateParams(parameter_count)}) { 'use strong'; } }`, | 101 `let o = { m(${generateParams(parameterCount)}) { 'use strong'; } }`, |
102 `let o = { *m(${generateParams(parameter_count)}) { 'use strong'; } }`, | 102 `let o = { *m(${generateParams(parameterCount)}) { 'use strong'; } }`, |
103 `'use strong'; | 103 `'use strong'; |
104 let o = new class { m(${generateParams(parameter_count)}) {} }`, | 104 let o = new class { m(${generateParams(parameterCount)}) {} }`, |
105 `'use strong'; | 105 `'use strong'; |
106 let o = new class { *m(${generateParams(parameter_count)}) {} }`, | 106 let o = new class { *m(${generateParams(parameterCount)}) {} }`, |
107 `'use strong'; let o = { m(${generateParams(parameter_count)}) {} }`, | 107 `'use strong'; let o = { m(${generateParams(parameterCount)}) {} }`, |
108 `'use strong'; let o = { *m(${generateParams(parameter_count)}) {} }`, | 108 `'use strong'; let o = { *m(${generateParams(parameterCount)}) {} }`, |
109 ]; | 109 ]; |
110 for (let def of defs) { | 110 for (let def of defs) { |
111 for (let argument_count = 0; argument_count < 3; argument_count++) { | 111 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { |
112 let calls = [ | 112 let calls = [ |
113 `o.m(${generateArguments(argument_count)})`, | 113 `o.m(${generateArguments(argumentCount)})`, |
114 `o.m(${generateSpread(argument_count)})`, | 114 `o.m(${generateSpread(argumentCount)})`, |
115 `o.m.call(${generateArguments(argument_count, 'o')})`, | 115 `o.m.call(${generateArguments(argumentCount, 'o')})`, |
116 `o.m.call(o, ${generateSpread(argument_count)})`, | 116 `o.m.call(o, ${generateSpread(argumentCount)})`, |
117 `o.m.apply(o, [${generateArguments(argument_count)}])`, | 117 `o.m.apply(o, [${generateArguments(argumentCount)}])`, |
118 `o.m.bind(o)(${generateArguments(argument_count)})`, | 118 `o.m.bind(o)(${generateArguments(argumentCount)})`, |
119 `%_CallFunction(${generateArguments(argument_count, 'o')}, o.m)`, | 119 `%_CallFunction(${generateArguments(argumentCount, 'o')}, o.m)`, |
120 `%Call(${generateArguments(argument_count, 'o')}, o.m)`, | 120 `%Call(${generateArguments(argumentCount, 'o')}, o.m)`, |
121 `%Apply(o.m, o, [${generateArguments(argument_count)}], 0, | 121 `%Apply(o.m, o, [${generateArguments(argumentCount)}], 0, |
122 ${argument_count})`, | 122 ${argumentCount})`, |
123 ]; | 123 ]; |
124 | 124 |
125 for (let call of calls) { | 125 for (let call of calls) { |
126 let code = `'use strict'; ${def}; ${call};`; | 126 let code = `'use strict'; ${def}; ${call};`; |
127 if (argument_count < parameter_count) { | 127 if (argumentCount < parameterCount) { |
128 assertThrows(code, TypeError); | 128 assertThrows(code, TypeError); |
129 } else { | 129 } else { |
130 assertDoesNotThrow(code); | 130 assertDoesNotThrow(code); |
131 } | 131 } |
132 } | 132 } |
133 } | 133 } |
134 | 134 |
135 let calls = [ | 135 let calls = [ |
136 `o.m.call()`, | 136 `o.m.call()`, |
137 `o.m.apply()`, | 137 `o.m.apply()`, |
138 `o.m.apply(o)`, | 138 `o.m.apply(o)`, |
139 ]; | 139 ]; |
140 for (let call of calls) { | 140 for (let call of calls) { |
141 let code = `'use strict'; ${def}; ${call};`; | 141 let code = `'use strict'; ${def}; ${call};`; |
142 if (parameter_count > 0) { | 142 if (parameterCount > 0) { |
143 assertThrows(code, TypeError); | 143 assertThrows(code, TypeError); |
144 } else { | 144 } else { |
145 assertDoesNotThrow(code); | 145 assertDoesNotThrow(code); |
146 } | 146 } |
147 } | 147 } |
148 } | 148 } |
149 } | 149 } |
150 })(); | 150 })(); |
151 | 151 |
152 | 152 |
153 (function Constructor() { | 153 (function Constructor() { |
154 for (let argument_count = 0; argument_count < 3; argument_count++) { | 154 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { |
155 for (let parameter_count = 0; parameter_count < 3; parameter_count++) { | 155 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { |
156 let defs = [ | 156 let defs = [ |
157 `'use strong'; | 157 `'use strong'; |
158 class C { constructor(${generateParams(parameter_count)}) {} }`, | 158 class C { constructor(${generateParams(parameterCount)}) {} }`, |
159 `'use strict'; | 159 `'use strict'; |
160 class C { | 160 class C { |
161 constructor(${generateParams(parameter_count)}) { 'use strong'; } | 161 constructor(${generateParams(parameterCount)}) { 'use strong'; } |
162 }`, | 162 }`, |
163 ]; | 163 ]; |
164 for (let def of defs) { | 164 for (let def of defs) { |
165 let calls = [ | 165 let calls = [ |
166 `new C(${generateArguments(argument_count)})`, | 166 `new C(${generateArguments(argumentCount)})`, |
167 `new C(${generateSpread(argument_count)})`, | 167 `new C(${generateSpread(argumentCount)})`, |
168 `Reflect.construct(C, [${generateArguments(argument_count)}])`, | 168 `Reflect.construct(C, [${generateArguments(argumentCount)}])`, |
169 ]; | 169 ]; |
170 for (let call of calls) { | 170 for (let call of calls) { |
171 let code = `${def}; ${call};`; | 171 let code = `${def}; ${call};`; |
172 if (argument_count < parameter_count) { | 172 if (argumentCount < parameterCount) { |
173 assertThrows(code, TypeError); | 173 assertThrows(code, TypeError); |
174 } else { | 174 } else { |
175 assertDoesNotThrow(code); | 175 assertDoesNotThrow(code); |
176 } | 176 } |
177 } | 177 } |
178 } | 178 } |
179 } | 179 } |
180 } | 180 } |
181 })(); | 181 })(); |
182 | 182 |
183 | 183 |
184 (function DerivedConstructor() { | 184 (function DerivedConstructor() { |
185 for (let genArgs of [generateArguments, generateSpread]) { | 185 for (let genArgs of [generateArguments, generateSpread]) { |
186 for (let argument_count = 0; argument_count < 3; argument_count++) { | 186 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { |
187 for (let parameter_count = 0; parameter_count < 3; parameter_count++) { | 187 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { |
188 let defs = [ | 188 let defs = [ |
189 `'use strong'; | 189 `'use strong'; |
190 class B { | 190 class B { |
191 constructor(${generateParams(parameter_count)}) {} | 191 constructor(${generateParams(parameterCount)}) {} |
192 } | 192 } |
193 class C extends B { | 193 class C extends B { |
194 constructor() { | 194 constructor() { |
195 super(${genArgs(argument_count)}); | 195 super(${genArgs(argumentCount)}); |
196 } | 196 } |
197 }`, | 197 }`, |
198 `'use strict'; | 198 `'use strict'; |
199 class B { | 199 class B { |
200 constructor(${generateParams(parameter_count)}) { 'use strong'; } | 200 constructor(${generateParams(parameterCount)}) { 'use strong'; } |
201 } | 201 } |
202 class C extends B { | 202 class C extends B { |
203 constructor() { | 203 constructor() { |
204 super(${genArgs(argument_count)}); | 204 super(${genArgs(argumentCount)}); |
205 } | 205 } |
206 }`, | 206 }`, |
207 ]; | 207 ]; |
208 for (let def of defs) { | 208 for (let def of defs) { |
209 let code = `${def}; new C();`; | 209 let code = `${def}; new C();`; |
210 if (argument_count < parameter_count) { | 210 if (argumentCount < parameterCount) { |
211 assertThrows(code, TypeError); | 211 assertThrows(code, TypeError); |
212 } else { | 212 } else { |
213 assertDoesNotThrow(code); | 213 assertDoesNotThrow(code); |
214 } | 214 } |
215 } | 215 } |
216 } | 216 } |
217 } | 217 } |
218 } | 218 } |
219 })(); | 219 })(); |
220 | 220 |
221 | 221 |
222 (function DerivedConstructorDefaultConstructorInDerivedClass() { | 222 (function DerivedConstructorDefaultConstructorInDerivedClass() { |
223 for (let genArgs of [generateArguments, generateSpread]) { | 223 for (let genArgs of [generateArguments, generateSpread]) { |
224 for (let argument_count = 0; argument_count < 3; argument_count++) { | 224 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { |
225 for (let parameter_count = 0; parameter_count < 3; parameter_count++) { | 225 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { |
226 let defs = [ | 226 let defs = [ |
227 `'use strong'; | 227 `'use strong'; |
228 class B { | 228 class B { |
229 constructor(${generateParams(parameter_count)}) {} | 229 constructor(${generateParams(parameterCount)}) {} |
230 } | 230 } |
231 class C extends B {}`, | 231 class C extends B {}`, |
232 `'use strict'; | 232 `'use strict'; |
233 class B { | 233 class B { |
234 constructor(${generateParams(parameter_count)}) { 'use strong'; } | 234 constructor(${generateParams(parameterCount)}) { 'use strong'; } |
235 } | 235 } |
236 class C extends B {}`, | 236 class C extends B {}`, |
237 ]; | 237 ]; |
238 for (let def of defs) { | 238 for (let def of defs) { |
239 let code = `${def}; new C(${genArgs(argument_count)})`; | 239 let code = `${def}; new C(${genArgs(argumentCount)})`; |
240 if (argument_count < parameter_count) { | 240 if (argumentCount < parameterCount) { |
241 assertThrows(code, TypeError); | 241 assertThrows(code, TypeError); |
242 } else { | 242 } else { |
243 assertDoesNotThrow(code); | 243 assertDoesNotThrow(code); |
244 } | 244 } |
245 } | 245 } |
246 } | 246 } |
247 } | 247 } |
248 } | 248 } |
249 })(); | 249 })(); |
250 | 250 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 'use strong'; | 296 'use strong'; |
297 f(1); | 297 f(1); |
298 } | 298 } |
299 | 299 |
300 g(); | 300 g(); |
301 %OptimizeFunctionOnNextCall(f); | 301 %OptimizeFunctionOnNextCall(f); |
302 g(); | 302 g(); |
303 })(); | 303 })(); |
304 | 304 |
305 | 305 |
306 // https://code.google.com/p/v8/issues/detail?id=4077 | 306 (function ParametersSuper() { |
307 // (function NoParametersSuper() { | 307 for (let genArgs of [generateArguments, generateSpread]) { |
308 // 'use strong'; | 308 for (let argumentCount = 0; argumentCount < 3; argumentCount++) { |
309 // | 309 for (let parameterCount = 0; parameterCount < 3; parameterCount++) { |
310 // class B { | 310 let defs = [ |
311 // m() {} | 311 `'use strict'; |
312 // } | 312 class B { |
313 // class D extends B { | 313 m(${generateParams(parameterCount)} ){ 'use strong' } |
314 // m0() { super.m(); } | 314 }`, |
315 // m1() { super.m(1); } | 315 `'use strong'; class B { m(${generateParams(parameterCount)}) {} }`, |
316 // s0() { super.m(); } | 316 ]; |
317 // s1() { super.m(1); } | 317 for (let def of defs) { |
318 // } | 318 let code = `${def}; |
319 // | 319 class D extends B { |
320 // new D().m0(); | 320 m() { |
321 // new D().m1(); | 321 super.m(${genArgs(argumentCount)}); |
322 // | 322 } |
323 // new D().s0(); | 323 } |
324 // new D().s1(); | 324 new D().m()`; |
325 // })(); | 325 print('\n\n' + code); |
326 | 326 if (argumentCount < parameterCount) { |
327 | 327 assertThrows(code, TypeError); |
328 // https://code.google.com/p/v8/issues/detail?id=4077 | 328 } else { |
329 // (function OneParamentSuper() { | 329 assertDoesNotThrow(code); |
330 // 'use strong'; | 330 } |
331 // | 331 } |
332 // class B { | 332 } |
333 // m(x) {} | 333 } |
334 // } | 334 } |
335 // class D extends B { | 335 })(); |
336 // m0() { super.m(); } | |
337 // m1() { super.m(1); } | |
338 // m2() { super.m(1, 2); } | |
339 // s0() { super.m(...[]); } | |
340 // s1() { super.m(...[1]); } | |
341 // s2() { super.m(...[1, 2]); } | |
342 // } | |
343 // | |
344 // assertThrows(function() { new D().m0(); }, TypeError); | |
345 // new D().m1(); | |
346 // new D().m2(); | |
347 // | |
348 // assertThrows(function() { new D().s0(); }, TypeError); | |
349 // new D().s1(); | |
350 // new D().s2(); | |
351 // })(); | |
352 | |
353 | |
354 // https://code.google.com/p/v8/issues/detail?id=4077 | |
355 // (function TwoParametersSuper() { | |
356 // 'use strong'; | |
357 // | |
358 // class B { | |
359 // m(x, y) {} | |
360 // } | |
361 // class D extends B { | |
362 // m0() { super.m(); } | |
363 // m1() { super.m(1); } | |
364 // m2() { super.m(1, 2); } | |
365 // m3() { super.m(1, 2, 3); } | |
366 // s0() { super.m(...[]); } | |
367 // s1() { super.m(...[1]); } | |
368 // s2() { super.m(...[1, 2]); } | |
369 // s3() { super.m(...[1, 2, 3]); } | |
370 // } | |
371 // | |
372 // assertThrows(function() { new D().m0(); }, TypeError); | |
373 // assertThrows(function() { new D().m1(); }, TypeError); | |
374 // new D().m2(); | |
375 // new D().m3(); | |
376 // | |
377 // assertThrows(function() { new D().s0(); }, TypeError); | |
378 // assertThrows(function() { new D().s1(); }, TypeError); | |
379 // new D().s2(); | |
380 // new D().s3(); | |
381 // })(); | |
OLD | NEW |