OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // Flags: --strong-mode --harmony-arrow-functions --harmony-reflect --harmony-sp readcalls --allow-natives-syntax | |
rossberg
2015/05/07 08:29:16
Nit: line length (note that you can have multiple
| |
6 | |
7 'use strict'; | |
8 | |
9 | |
10 function generateArguments(n, prefix) { | |
11 let a = []; | |
12 if (prefix) { | |
13 a.push(prefix); | |
14 } | |
15 for (let i = 0; i < n; i++) { | |
16 a.push(String(i)); | |
17 } | |
18 | |
19 return a.join(', '); | |
20 } | |
21 | |
22 | |
23 function generateParams(n) { | |
24 let a = []; | |
25 for (let i = 0; i < n; i++) { | |
26 a[i] = `p${i}`; | |
27 } | |
28 return a.join(', '); | |
29 } | |
30 | |
31 | |
32 function generateSpread(n) { | |
33 return `...[${generateArguments(n)}]`; | |
34 } | |
35 | |
36 | |
37 (function FunctionCall() { | |
38 for (let parameter_count = 0; parameter_count < 3; parameter_count++) { | |
39 let defs = [ | |
40 `function f(${generateParams(parameter_count)}) {}`, | |
41 `function* f(${generateParams(parameter_count)}) {}`, | |
42 `let f = (${generateParams(parameter_count)}) => {}`, | |
43 ]; | |
44 for (let def of defs) { | |
45 def = ` | |
46 'use strong'; | |
rossberg
2015/05/07 08:29:17
Instead of having the directive outside the functi
| |
47 ${def};`; | |
48 | |
49 for (let argument_count = 0; argument_count < 3; argument_count++) { | |
50 let calls = [ | |
51 `f(${generateArguments(argument_count)})`, | |
52 `f(${generateSpread(argument_count)})`, | |
53 `f.call(${generateArguments(argument_count, 'undefined')})`, | |
54 `f.call(undefined, ${generateSpread(argument_count)})`, | |
55 `f.apply(undefined, [${generateArguments(argument_count)}])`, | |
56 `f.bind(undefined)(${generateArguments(argument_count)})`, | |
57 `%_CallFunction(${generateArguments(argument_count, 'undefined')}, | |
58 f)`, | |
59 `%Call(${generateArguments(argument_count, 'undefined')}, f)`, | |
60 `%Apply(f, undefined, [${generateArguments(argument_count)}], 0, | |
61 ${argument_count})`, | |
62 ]; | |
63 | |
64 for (let call of calls) { | |
65 let code = `${def}${call}`; | |
66 if (argument_count < parameter_count) { | |
67 assertThrows(code, TypeError); | |
68 } else { | |
69 assertDoesNotThrow(code); | |
70 } | |
71 } | |
72 } | |
73 | |
74 let calls = [ | |
75 `f.call()`, | |
76 `f.apply()`, | |
77 `f.apply(undefined)`, | |
78 ]; | |
79 for (let call of calls) { | |
80 let code = `${def}${call}`; | |
81 if (parameter_count > 0) { | |
82 assertThrows(code, TypeError); | |
83 } else { | |
84 assertDoesNotThrow(code); | |
85 } | |
86 } | |
87 } | |
88 } | |
89 })(); | |
90 | |
91 | |
92 (function MethodCall() { | |
93 for (let parameter_count = 0; parameter_count < 3; parameter_count++) { | |
94 let defs = [ | |
95 `new class { m(${generateParams(parameter_count)}) {} }`, | |
96 `new class { *m(${generateParams(parameter_count)}) {} }`, | |
97 `{ m(${generateParams(parameter_count)}) {} }`, | |
98 `{ *m(${generateParams(parameter_count)}) {} }`, | |
99 ]; | |
100 for (let def of defs) { | |
101 def = ` | |
102 'use strong'; | |
103 let o = ${def};`; | |
104 | |
105 for (let argument_count = 0; argument_count < 3; argument_count++) { | |
106 let calls = [ | |
107 `o.m(${generateArguments(argument_count)})`, | |
108 `o.m(${generateSpread(argument_count)})`, | |
109 `o.m.call(${generateArguments(argument_count, 'o')})`, | |
110 `o.m.call(o, ${generateSpread(argument_count)})`, | |
111 `o.m.apply(o, [${generateArguments(argument_count)}])`, | |
112 `o.m.bind(o)(${generateArguments(argument_count)})`, | |
113 `%_CallFunction(${generateArguments(argument_count, 'o')}, o.m)`, | |
114 `%Call(${generateArguments(argument_count, 'o')}, o.m)`, | |
115 `%Apply(o.m, o, [${generateArguments(argument_count)}], 0, | |
116 ${argument_count})`, | |
117 ]; | |
118 | |
119 for (let call of calls) { | |
120 let code = `${def}${call}`; | |
121 if (argument_count < parameter_count) { | |
122 assertThrows(code, TypeError); | |
123 } else { | |
124 assertDoesNotThrow(code); | |
125 } | |
126 } | |
127 } | |
128 | |
129 let calls = [ | |
130 `o.m.call()`, | |
131 `o.m.apply()`, | |
132 `o.m.apply(o)`, | |
133 ]; | |
134 for (let call of calls) { | |
135 let code = `${def}${call}`; | |
136 if (parameter_count > 0) { | |
137 assertThrows(code, TypeError); | |
138 } else { | |
139 assertDoesNotThrow(code); | |
140 } | |
141 } | |
142 } | |
143 } | |
144 })(); | |
145 | |
146 | |
147 (function Constructor() { | |
148 for (let argument_count = 0; argument_count < 3; argument_count++) { | |
149 for (let parameter_count = 0; parameter_count < 3; parameter_count++) { | |
150 let def = ` | |
151 'use strong'; | |
152 class C { | |
153 constructor(${generateParams(parameter_count)}) {} | |
154 }`; | |
155 let calls = [ | |
156 `new C(${generateArguments(argument_count)})`, | |
157 `new C(${generateSpread(argument_count)})`, | |
158 `Reflect.construct(C, [${generateArguments(argument_count)}])`, | |
159 ]; | |
160 for (let call of calls) { | |
161 let code = `${def}${call}`; | |
162 if (argument_count < parameter_count) { | |
163 assertThrows(code, TypeError); | |
164 } else { | |
165 assertDoesNotThrow(code); | |
166 } | |
167 } | |
168 } | |
169 } | |
170 })(); | |
171 | |
172 | |
173 (function DerivedConstructor() { | |
174 for (let genArgs of [generateArguments, generateSpread]) { | |
175 for (let argument_count = 0; argument_count < 3; argument_count++) { | |
176 for (let parameter_count = 0; parameter_count < 3; parameter_count++) { | |
177 let code = ` | |
178 'use strong'; | |
179 class B { | |
180 constructor(${generateParams(parameter_count)}) {} | |
181 } | |
182 class C extends B { | |
183 constructor() { | |
184 super(${genArgs(argument_count)}); | |
185 } | |
186 } | |
187 new C()`; | |
188 if (argument_count < parameter_count) { | |
189 assertThrows(code, TypeError); | |
190 } else { | |
191 assertDoesNotThrow(code); | |
192 } | |
193 } | |
194 } | |
195 } | |
196 })(); | |
197 | |
198 | |
199 (function DerivedConstructorDefaultConstructorInDerivedClass() { | |
200 for (let genArgs of [generateArguments, generateSpread]) { | |
201 for (let argument_count = 0; argument_count < 3; argument_count++) { | |
202 for (let parameter_count = 0; parameter_count < 3; parameter_count++) { | |
203 let code = ` | |
204 'use strong'; | |
205 class B { | |
206 constructor(${generateParams(parameter_count)}) {} | |
207 } | |
208 class C extends B {} | |
209 new C(${genArgs(argument_count)})`; | |
210 if (argument_count < parameter_count) { | |
211 assertThrows(code, TypeError); | |
212 } else { | |
213 assertDoesNotThrow(code); | |
214 } | |
215 } | |
216 } | |
217 } | |
218 })(); | |
219 | |
220 | |
221 // https://code.google.com/p/v8/issues/detail?id=4077 | |
222 // (function NoParametersSuper() { | |
223 // 'use strong'; | |
224 // | |
225 // class B { | |
226 // m() {} | |
227 // } | |
228 // class D extends B { | |
229 // m0() { super.m(); } | |
230 // m1() { super.m(1); } | |
231 // s0() { super.m(); } | |
232 // s1() { super.m(1); } | |
233 // } | |
234 // | |
235 // new D().m0(); | |
236 // new D().m1(); | |
237 // | |
238 // new D().s0(); | |
239 // new D().s1(); | |
240 // })(); | |
241 | |
242 | |
243 // https://code.google.com/p/v8/issues/detail?id=4077 | |
244 // (function OneParamentSuper() { | |
245 // 'use strong'; | |
246 // | |
247 // class B { | |
248 // m(x) {} | |
249 // } | |
250 // class D extends B { | |
251 // m0() { super.m(); } | |
252 // m1() { super.m(1); } | |
253 // m2() { super.m(1, 2); } | |
254 // s0() { super.m(...[]); } | |
255 // s1() { super.m(...[1]); } | |
256 // s2() { super.m(...[1, 2]); } | |
257 // } | |
258 // | |
259 // assertThrows(function() { new D().m0(); }, TypeError); | |
260 // new D().m1(); | |
261 // new D().m2(); | |
262 // | |
263 // assertThrows(function() { new D().s0(); }, TypeError); | |
264 // new D().s1(); | |
265 // new D().s2(); | |
266 // })(); | |
267 | |
268 | |
269 // https://code.google.com/p/v8/issues/detail?id=4077 | |
270 // (function TwoParametersSuper() { | |
271 // 'use strong'; | |
272 // | |
273 // class B { | |
274 // m(x, y) {} | |
275 // } | |
276 // class D extends B { | |
277 // m0() { super.m(); } | |
278 // m1() { super.m(1); } | |
279 // m2() { super.m(1, 2); } | |
280 // m3() { super.m(1, 2, 3); } | |
281 // s0() { super.m(...[]); } | |
282 // s1() { super.m(...[1]); } | |
283 // s2() { super.m(...[1, 2]); } | |
284 // s3() { super.m(...[1, 2, 3]); } | |
285 // } | |
286 // | |
287 // assertThrows(function() { new D().m0(); }, TypeError); | |
288 // assertThrows(function() { new D().m1(); }, TypeError); | |
289 // new D().m2(); | |
290 // new D().m3(); | |
291 // | |
292 // assertThrows(function() { new D().s0(); }, TypeError); | |
293 // assertThrows(function() { new D().s1(); }, TypeError); | |
294 // new D().s2(); | |
295 // new D().s3(); | |
296 // })(); | |
OLD | NEW |