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

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: 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
6 // Flags: --harmony-spreadcalls --allow-natives-syntax
7
8 'use strict';
9
10
11 function generateArguments(n, prefix) {
12 let a = [];
13 if (prefix) {
14 a.push(prefix);
15 }
16 for (let i = 0; i < n; i++) {
17 a.push(String(i));
18 }
19
20 return a.join(', ');
21 }
22
23
24 function generateParams(n) {
25 let a = [];
26 for (let i = 0; i < n; i++) {
27 a[i] = `p${i}`;
28 }
29 return a.join(', ');
30 }
31
32
33 function generateSpread(n) {
34 return `...[${generateArguments(n)}]`;
35 }
36
37
38 (function FunctionCall() {
39 for (let parameter_count = 0; parameter_count < 3; parameter_count++) {
40 let defs = [
41 `'use strong'; function f(${generateParams(parameter_count)}) {}`,
42 `'use strong'; function* f(${generateParams(parameter_count)}) {}`,
43 `'use strong'; let f = (${generateParams(parameter_count)}) => {}`,
44 `function f(${generateParams(parameter_count)}) { 'use strong'; }`,
45 `function* f(${generateParams(parameter_count)}) { 'use strong'; }`,
46 `let f = (${generateParams(parameter_count)}) => { 'use strong'; }`,
47 ];
48 for (let def of defs) {
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 = `'use strict'; ${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 = `'use strict'; ${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 `let o = new class {
96 m(${generateParams(parameter_count)}) { 'use strong'; }
97 }`,
98 `let o = new class {
99 *m(${generateParams(parameter_count)}) { 'use strong'; }
100 }`,
101 `let o = { m(${generateParams(parameter_count)}) { 'use strong'; } }`,
102 `let o = { *m(${generateParams(parameter_count)}) { 'use strong'; } }`,
103 `'use strong';
104 let o = new class { m(${generateParams(parameter_count)}) {} }`,
105 `'use strong';
106 let o = new class { *m(${generateParams(parameter_count)}) {} }`,
107 `'use strong'; let o = { m(${generateParams(parameter_count)}) {} }`,
108 `'use strong'; let o = { *m(${generateParams(parameter_count)}) {} }`,
109 ];
110 for (let def of defs) {
111 for (let argument_count = 0; argument_count < 3; argument_count++) {
112 let calls = [
113 `o.m(${generateArguments(argument_count)})`,
114 `o.m(${generateSpread(argument_count)})`,
115 `o.m.call(${generateArguments(argument_count, 'o')})`,
116 `o.m.call(o, ${generateSpread(argument_count)})`,
117 `o.m.apply(o, [${generateArguments(argument_count)}])`,
118 `o.m.bind(o)(${generateArguments(argument_count)})`,
119 `%_CallFunction(${generateArguments(argument_count, 'o')}, o.m)`,
120 `%Call(${generateArguments(argument_count, 'o')}, o.m)`,
121 `%Apply(o.m, o, [${generateArguments(argument_count)}], 0,
122 ${argument_count})`,
123 ];
124
125 for (let call of calls) {
126 let code = `'use strict'; ${def}; ${call};`;
127 if (argument_count < parameter_count) {
128 assertThrows(code, TypeError);
129 } else {
130 assertDoesNotThrow(code);
131 }
132 }
133 }
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 (parameter_count > 0) {
143 assertThrows(code, TypeError);
144 } else {
145 assertDoesNotThrow(code);
146 }
147 }
148 }
149 }
150 })();
151
152
153 (function Constructor() {
154 for (let argument_count = 0; argument_count < 3; argument_count++) {
155 for (let parameter_count = 0; parameter_count < 3; parameter_count++) {
156 let defs = [
157 `'use strong';
158 class C { constructor(${generateParams(parameter_count)}) {} }`,
159 `'use strict';
160 class C {
161 constructor(${generateParams(parameter_count)}) { 'use strong'; }
162 }`,
163 ];
164 for (let def of defs) {
165 let calls = [
166 `new C(${generateArguments(argument_count)})`,
167 `new C(${generateSpread(argument_count)})`,
168 `Reflect.construct(C, [${generateArguments(argument_count)}])`,
169 ];
170 for (let call of calls) {
171 let code = `${def}; ${call};`;
172 if (argument_count < parameter_count) {
173 assertThrows(code, TypeError);
174 } else {
175 assertDoesNotThrow(code);
176 }
177 }
178 }
179 }
180 }
181 })();
182
183
184 (function DerivedConstructor() {
185 for (let genArgs of [generateArguments, generateSpread]) {
186 for (let argument_count = 0; argument_count < 3; argument_count++) {
187 for (let parameter_count = 0; parameter_count < 3; parameter_count++) {
188 let defs = [
189 `'use strong';
190 class B {
191 constructor(${generateParams(parameter_count)}) {}
192 }
193 class C extends B {
194 constructor() {
195 super(${genArgs(argument_count)});
196 }
197 }`,
198 `'use strict';
199 class B {
200 constructor(${generateParams(parameter_count)}) { 'use strong'; }
201 }
202 class C extends B {
203 constructor() {
204 super(${genArgs(argument_count)});
205 }
206 }`,
207 ];
208 for (let def of defs) {
209 let code = `${def}; new C();`;
210 if (argument_count < parameter_count) {
211 assertThrows(code, TypeError);
212 } else {
213 assertDoesNotThrow(code);
214 }
215 }
216 }
217 }
218 }
219 })();
220
221
222 (function DerivedConstructorDefaultConstructorInDerivedClass() {
223 for (let genArgs of [generateArguments, generateSpread]) {
224 for (let argument_count = 0; argument_count < 3; argument_count++) {
225 for (let parameter_count = 0; parameter_count < 3; parameter_count++) {
226 let defs = [
227 `'use strong';
228 class B {
229 constructor(${generateParams(parameter_count)}) {}
230 }
231 class C extends B {}`,
232 `'use strict';
233 class B {
234 constructor(${generateParams(parameter_count)}) { 'use strong'; }
235 }
236 class C extends B {}`,
237 ];
238 for (let def of defs) {
239 let code = `${def}; new C(${genArgs(argument_count)})`;
240 if (argument_count < parameter_count) {
241 assertThrows(code, TypeError);
242 } else {
243 assertDoesNotThrow(code);
244 }
245 }
246 }
247 }
248 }
249 })();
250
251
252 (function TestOptimized() {
253 function f(x, y) { 'use strong'; }
254
255 assertThrows(f, TypeError);
256 %OptimizeFunctionOnNextCall(f);
257 assertThrows(f, TypeError);
258
259 function g() {
260 f(1);
261 }
262 assertThrows(g, TypeError);
263 %OptimizeFunctionOnNextCall(g);
264 assertThrows(g, TypeError);
265
266 f(1, 2);
267 %OptimizeFunctionOnNextCall(f);
268 f(1, 2);
269 })();
270
271
272 (function TestOptimized2() {
273 'use strong';
274 function f(x, y) {}
275
276 assertThrows(f, TypeError);
277 %OptimizeFunctionOnNextCall(f);
278 assertThrows(f, TypeError);
279
280 function g() {
281 f(1);
282 }
283 assertThrows(g, TypeError);
284 %OptimizeFunctionOnNextCall(g);
285 assertThrows(g, TypeError);
286
287 f(1, 2);
288 %OptimizeFunctionOnNextCall(f);
289 f(1, 2);
290 })();
291
292
293 // https://code.google.com/p/v8/issues/detail?id=4077
294 // (function NoParametersSuper() {
295 // 'use strong';
296 //
297 // class B {
298 // m() {}
299 // }
300 // class D extends B {
301 // m0() { super.m(); }
302 // m1() { super.m(1); }
303 // s0() { super.m(); }
304 // s1() { super.m(1); }
305 // }
306 //
307 // new D().m0();
308 // new D().m1();
309 //
310 // new D().s0();
311 // new D().s1();
312 // })();
313
314
315 // https://code.google.com/p/v8/issues/detail?id=4077
316 // (function OneParamentSuper() {
317 // 'use strong';
318 //
319 // class B {
320 // m(x) {}
321 // }
322 // class D extends B {
323 // m0() { super.m(); }
324 // m1() { super.m(1); }
325 // m2() { super.m(1, 2); }
326 // s0() { super.m(...[]); }
327 // s1() { super.m(...[1]); }
328 // s2() { super.m(...[1, 2]); }
329 // }
330 //
331 // assertThrows(function() { new D().m0(); }, TypeError);
332 // new D().m1();
333 // new D().m2();
334 //
335 // assertThrows(function() { new D().s0(); }, TypeError);
336 // new D().s1();
337 // new D().s2();
338 // })();
339
340
341 // https://code.google.com/p/v8/issues/detail?id=4077
342 // (function TwoParametersSuper() {
343 // 'use strong';
344 //
345 // class B {
346 // m(x, y) {}
347 // }
348 // class D extends B {
349 // m0() { super.m(); }
350 // m1() { super.m(1); }
351 // m2() { super.m(1, 2); }
352 // m3() { super.m(1, 2, 3); }
353 // s0() { super.m(...[]); }
354 // s1() { super.m(...[1]); }
355 // s2() { super.m(...[1, 2]); }
356 // s3() { super.m(...[1, 2, 3]); }
357 // }
358 //
359 // assertThrows(function() { new D().m0(); }, TypeError);
360 // assertThrows(function() { new D().m1(); }, TypeError);
361 // new D().m2();
362 // new D().m3();
363 //
364 // assertThrows(function() { new D().s0(); }, TypeError);
365 // assertThrows(function() { new D().s1(); }, TypeError);
366 // new D().s2();
367 // new D().s3();
368 // })();
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