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

Side by Side Diff: test/mjsunit/strong/function-arity.js

Issue 1115263004: [strong] Check arity of functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Ports done and even more tests Created 5 years, 7 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/declaration-after-use.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/11 15:39:28 Nit: line length
arv (Not doing code reviews) 2015/05/11 16:54:02 Done. I fixed this but I guess I undid too much a
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 `'use strong'; function f(${generateParams(parameter_count)}) {}`,
41 `'use strong'; function* f(${generateParams(parameter_count)}) {}`,
42 `'use strong'; let f = (${generateParams(parameter_count)}) => {}`,
43 `function f(${generateParams(parameter_count)}) { 'use strong'; }`,
44 `function* f(${generateParams(parameter_count)}) { 'use strong'; }`,
45 `let f = (${generateParams(parameter_count)}) => { 'use strong'; }`,
46 ];
47 for (let def of defs) {
48 for (let argument_count = 0; argument_count < 3; argument_count++) {
49 let calls = [
50 `f(${generateArguments(argument_count)})`,
51 `f(${generateSpread(argument_count)})`,
52 `f.call(${generateArguments(argument_count, 'undefined')})`,
53 `f.call(undefined, ${generateSpread(argument_count)})`,
54 `f.apply(undefined, [${generateArguments(argument_count)}])`,
55 `f.bind(undefined)(${generateArguments(argument_count)})`,
56 `%_CallFunction(${generateArguments(argument_count, 'undefined')},
57 f)`,
58 `%Call(${generateArguments(argument_count, 'undefined')}, f)`,
59 `%Apply(f, undefined, [${generateArguments(argument_count)}], 0,
60 ${argument_count})`,
61 ];
62
63 for (let call of calls) {
64 let code = `'use strict'; ${def}; ${call};`;
65 if (argument_count < parameter_count) {
66 assertThrows(code, TypeError);
67 } else {
68 assertDoesNotThrow(code);
69 }
70 }
71 }
72
73 let calls = [
74 `f.call()`,
75 `f.apply()`,
76 `f.apply(undefined)`,
77 ];
78 for (let call of calls) {
79 let code = `'use strict'; ${def}; ${call};`;
80 if (parameter_count > 0) {
81 assertThrows(code, TypeError);
82 } else {
83 assertDoesNotThrow(code);
84 }
85 }
86 }
87 }
88 })();
89
90
91 (function MethodCall() {
92 for (let parameter_count = 0; parameter_count < 3; parameter_count++) {
93 let defs = [
94 `let o = new class {
95 m(${generateParams(parameter_count)}) { 'use strong'; }
96 }`,
97 `let o = new class {
98 *m(${generateParams(parameter_count)}) { 'use strong'; }
99 }`,
100 `let o = { m(${generateParams(parameter_count)}) { 'use strong'; } }`,
101 `let o = { *m(${generateParams(parameter_count)}) { 'use strong'; } }`,
102 `'use strong';
103 let o = new class { m(${generateParams(parameter_count)}) {} }`,
104 `'use strong';
105 let o = new class { *m(${generateParams(parameter_count)}) {} }`,
106 `'use strong'; let o = { m(${generateParams(parameter_count)}) {} }`,
107 `'use strong'; let o = { *m(${generateParams(parameter_count)}) {} }`,
108 ];
109 for (let def of defs) {
110 for (let argument_count = 0; argument_count < 3; argument_count++) {
111 let calls = [
112 `o.m(${generateArguments(argument_count)})`,
113 `o.m(${generateSpread(argument_count)})`,
114 `o.m.call(${generateArguments(argument_count, 'o')})`,
115 `o.m.call(o, ${generateSpread(argument_count)})`,
116 `o.m.apply(o, [${generateArguments(argument_count)}])`,
117 `o.m.bind(o)(${generateArguments(argument_count)})`,
118 `%_CallFunction(${generateArguments(argument_count, 'o')}, o.m)`,
119 `%Call(${generateArguments(argument_count, 'o')}, o.m)`,
120 `%Apply(o.m, o, [${generateArguments(argument_count)}], 0,
121 ${argument_count})`,
122 ];
123
124 for (let call of calls) {
125 let code = `'use strict'; ${def}; ${call};`;
126 if (argument_count < parameter_count) {
127 assertThrows(code, TypeError);
128 } else {
129 assertDoesNotThrow(code);
130 }
131 }
132 }
133
134 let calls = [
135 `o.m.call()`,
136 `o.m.apply()`,
137 `o.m.apply(o)`,
138 ];
139 for (let call of calls) {
140 let code = `'use strict'; ${def}; ${call};`;
141 if (parameter_count > 0) {
142 assertThrows(code, TypeError);
143 } else {
144 assertDoesNotThrow(code);
145 }
146 }
147 }
148 }
149 })();
150
151
152 (function Constructor() {
153 for (let argument_count = 0; argument_count < 3; argument_count++) {
154 for (let parameter_count = 0; parameter_count < 3; parameter_count++) {
155 let defs = [
156 `'use strong';
157 class C { constructor(${generateParams(parameter_count)}) {} }`,
158 `'use strict';
159 class C {
160 constructor(${generateParams(parameter_count)}) { 'use strong'; }
161 }`,
162 ];
163 for (let def of defs) {
164 let calls = [
165 `new C(${generateArguments(argument_count)})`,
166 `new C(${generateSpread(argument_count)})`,
167 `Reflect.construct(C, [${generateArguments(argument_count)}])`,
168 ];
169 for (let call of calls) {
170 let code = `${def}; ${call};`;
171 if (argument_count < parameter_count) {
172 assertThrows(code, TypeError);
173 } else {
174 assertDoesNotThrow(code);
175 }
176 }
177 }
178 }
179 }
180 })();
181
182
183 (function DerivedConstructor() {
184 for (let genArgs of [generateArguments, generateSpread]) {
185 for (let argument_count = 0; argument_count < 3; argument_count++) {
186 for (let parameter_count = 0; parameter_count < 3; parameter_count++) {
187 let defs = [
188 `'use strong';
189 class B {
190 constructor(${generateParams(parameter_count)}) {}
191 }
192 class C extends B {
193 constructor() {
194 super(${genArgs(argument_count)});
195 }
196 }`,
197 `'use strict';
198 class B {
199 constructor(${generateParams(parameter_count)}) { 'use strong'; }
200 }
201 class C extends B {
202 constructor() {
203 super(${genArgs(argument_count)});
204 }
205 }`,
206 ];
207 for (let def of defs) {
208 let code = `${def}; new C();`;
209 if (argument_count < parameter_count) {
210 assertThrows(code, TypeError);
211 } else {
212 assertDoesNotThrow(code);
213 }
214 }
215 }
216 }
217 }
218 })();
219
220
221 (function DerivedConstructorDefaultConstructorInDerivedClass() {
222 for (let genArgs of [generateArguments, generateSpread]) {
223 for (let argument_count = 0; argument_count < 3; argument_count++) {
224 for (let parameter_count = 0; parameter_count < 3; parameter_count++) {
225 let defs = [
226 `'use strong';
227 class B {
228 constructor(${generateParams(parameter_count)}) {}
229 }
230 class C extends B {}`,
231 `'use strict';
232 class B {
233 constructor(${generateParams(parameter_count)}) { 'use strong'; }
234 }
235 class C extends B {}`,
236 ];
237 for (let def of defs) {
238 let code = `${def}; new C(${genArgs(argument_count)})`;
239 if (argument_count < parameter_count) {
240 assertThrows(code, TypeError);
241 } else {
242 assertDoesNotThrow(code);
243 }
244 }
245 }
246 }
247 }
248 })();
249
250
251 (function TestOptimized() {
252 function f(x, y) { 'use strong'; }
253
254 assertThrows(f, TypeError);
255 %OptimizeFunctionOnNextCall(f);
256 assertThrows(f, TypeError);
257
258 function g() {
259 f(1);
260 }
261 assertThrows(g, TypeError);
262 %OptimizeFunctionOnNextCall(g);
263 assertThrows(g, TypeError);
264 })();
265
266
267 (function TestOptimized2() {
268 'use strong';
269 function f(x, y) {}
rossberg 2015/05/11 15:39:28 It's also worth testing the case where the callee
arv (Not doing code reviews) 2015/05/11 16:54:02 Done.
rossberg 2015/05/12 06:02:16 Sorry for the misunderstanding, I meant the case w
270
271 assertThrows(f, TypeError);
272 %OptimizeFunctionOnNextCall(f);
273 assertThrows(f, TypeError);
274
275 function g() {
276 f(1);
277 }
278 assertThrows(g, TypeError);
279 %OptimizeFunctionOnNextCall(g);
280 assertThrows(g, TypeError);
281 })();
282
283
284 // https://code.google.com/p/v8/issues/detail?id=4077
285 // (function NoParametersSuper() {
286 // 'use strong';
287 //
288 // class B {
289 // m() {}
290 // }
291 // class D extends B {
292 // m0() { super.m(); }
293 // m1() { super.m(1); }
294 // s0() { super.m(); }
295 // s1() { super.m(1); }
296 // }
297 //
298 // new D().m0();
299 // new D().m1();
300 //
301 // new D().s0();
302 // new D().s1();
303 // })();
304
305
306 // https://code.google.com/p/v8/issues/detail?id=4077
307 // (function OneParamentSuper() {
308 // 'use strong';
309 //
310 // class B {
311 // m(x) {}
312 // }
313 // class D extends B {
314 // m0() { super.m(); }
315 // m1() { super.m(1); }
316 // m2() { super.m(1, 2); }
317 // s0() { super.m(...[]); }
318 // s1() { super.m(...[1]); }
319 // s2() { super.m(...[1, 2]); }
320 // }
321 //
322 // assertThrows(function() { new D().m0(); }, TypeError);
323 // new D().m1();
324 // new D().m2();
325 //
326 // assertThrows(function() { new D().s0(); }, TypeError);
327 // new D().s1();
328 // new D().s2();
329 // })();
330
331
332 // https://code.google.com/p/v8/issues/detail?id=4077
333 // (function TwoParametersSuper() {
334 // 'use strong';
335 //
336 // class B {
337 // m(x, y) {}
338 // }
339 // class D extends B {
340 // m0() { super.m(); }
341 // m1() { super.m(1); }
342 // m2() { super.m(1, 2); }
343 // m3() { super.m(1, 2, 3); }
344 // s0() { super.m(...[]); }
345 // s1() { super.m(...[1]); }
346 // s2() { super.m(...[1, 2]); }
347 // s3() { super.m(...[1, 2, 3]); }
348 // }
349 //
350 // assertThrows(function() { new D().m0(); }, TypeError);
351 // assertThrows(function() { new D().m1(); }, TypeError);
352 // new D().m2();
353 // new D().m3();
354 //
355 // assertThrows(function() { new D().s0(); }, TypeError);
356 // assertThrows(function() { new D().s1(); }, TypeError);
357 // new D().s2();
358 // new D().s3();
359 // })();
OLDNEW
« no previous file with comments | « test/mjsunit/strong/declaration-after-use.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698