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

Side by Side Diff: test/mjsunit/harmony/async-destructuring.js

Issue 2229243002: Destructuring/default tests for generators and async functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add additional suggested test Created 4 years, 4 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/es6/generator-destructuring.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 2016 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: --harmony-async-await --allow-natives-syntax
6
7 function assertThrowsAsync(run, errorType, message) {
8 var actual;
9 var hadValue = false;
10 var hadError = false;
11 var promise = run();
12
13 if (typeof promise !== "object" || typeof promise.then !== "function") {
14 throw new MjsUnitAssertionError(
15 "Expected " + run.toString() +
16 " to return a Promise, but it returned " + PrettyPrint(promise));
17 }
18
19 promise.then(function(value) { hadValue = true; actual = value; },
20 function(error) { hadError = true; actual = error; });
21
22 assertFalse(hadValue || hadError);
23
24 %RunMicrotasks();
25
26 if (!hadError) {
27 throw new MjsUnitAssertionError(
28 "Expected " + run + "() to throw " + errorType.name +
29 ", but did not throw.");
30 }
31 if (!(actual instanceof errorType))
32 throw new MjsUnitAssertionError(
33 "Expected " + run + "() to throw " + errorType.name +
34 ", but threw '" + actual + "'");
35 if (message !== void 0 && actual.message !== message)
36 throw new MjsUnitAssertionError(
37 "Expected " + run + "() to throw '" + message + "', but threw '" +
38 actual.message + "'");
39 };
40
41 function assertEqualsAsync(expected, run, msg) {
42 var actual;
43 var hadValue = false;
44 var hadError = false;
45 var promise = run();
46
47 if (typeof promise !== "object" || typeof promise.then !== "function") {
48 throw new MjsUnitAssertionError(
49 "Expected " + run.toString() +
50 " to return a Promise, but it returned " + PrettyPrint(promise));
51 }
52
53 promise.then(function(value) { hadValue = true; actual = value; },
54 function(error) { hadError = true; actual = error; });
55
56 assertFalse(hadValue || hadError);
57
58 %RunMicrotasks();
59
60 if (hadError) throw actual;
61
62 assertTrue(
63 hadValue, "Expected '" + run.toString() + "' to produce a value");
64
65 assertEquals(expected, actual, msg);
66 };
67
68 (function TestDefaultEvaluationOrder() {
69 var y = 0;
70 var z = 0;
71 var w = 0;
72 async function f1(x = (y = 1)) { z = 1; await undefined; w = 1; };
73 assertEquals(0, y);
74 assertEquals(0, z);
75 assertEquals(0, w);
76 f1();
77 assertEquals(1, y);
78 assertEquals(1, z);
79 assertEquals(0, w);
80 %RunMicrotasks();
81 assertEquals(1, y);
82 assertEquals(1, z);
83 assertEquals(1, w);
84 })();
85
86 (function TestShadowingOfParameters() {
87 async function f1({x}) { var x = 2; return x }
88 assertEqualsAsync(2, () => f1({x: 1}));
89 async function f2({x}) { { var x = 2; } return x; }
90 assertEqualsAsync(2, () => f2({x: 1}));
91 async function f3({x}) { var y = x; var x = 2; return y; }
92 assertEqualsAsync(1, () => f3({x: 1}));
93 async function f4({x}) { { var y = x; var x = 2; } return y; }
94 assertEqualsAsync(1, () => f4({x: 1}));
95 async function f5({x}, g = () => x) { var x = 2; return g(); }
96 assertEqualsAsync(1, () => f5({x: 1}));
97 async function f6({x}, g = () => x) { { var x = 2; } return g(); }
98 assertEqualsAsync(1, () => f6({x: 1}));
99 async function f7({x}) { var g = () => x; var x = 2; return g(); }
100 assertEqualsAsync(2, () => f7({x: 1}));
101 async function f8({x}) { { var g = () => x; var x = 2; } return g(); }
102 assertEqualsAsync(2, () => f8({x: 1}));
103 async function f9({x}, g = () => eval("x")) { var x = 2; return g(); }
104 assertEqualsAsync(1, () => f9({x: 1}));
105
106 async function f10({x}, y) { var y; return y }
107 assertEqualsAsync(2, () => f10({x: 6}, 2));
108 async function f11({x}, y) { var z = y; var y = 2; return z; }
109 assertEqualsAsync(1, () => f11({x: 6}, 1));
110 async function f12(y, g = () => y) { var y = 2; return g(); }
111 assertEqualsAsync(1, () => f12(1));
112 async function f13({x}, y, [z], v) { var x, y, z; return x*y*z*v }
113 assertEqualsAsync(210, () => f13({x: 2}, 3, [5], 7));
114
115 async function f20({x}) { function x() { return 2 }; return x(); }
116 assertEqualsAsync(2, () => f20({x: 1}));
117 // Annex B 3.3 function hoisting is blocked by the conflicting x declaration
118 async function f21({x}) { { function x() { return 2 } } return x; }
119 assertEqualsAsync(1, () => f21({x: 1}));
120
121 var g1 = async ({x}) => { var x = 2; return x };
122 assertEqualsAsync(2, () => g1({x: 1}));
123 var g2 = async ({x}) => { { var x = 2; } return x; };
124 assertEqualsAsync(2, () => g2({x: 1}));
125 var g3 = async ({x}) => { var y = x; var x = 2; return y; };
126 assertEqualsAsync(1, () => g3({x: 1}));
127 var g4 = async ({x}) => { { var y = x; var x = 2; } return y; };
128 assertEqualsAsync(1, () => g4({x: 1}));
129 var g5 = async ({x}, g = () => x) => { var x = 2; return g(); };
130 assertEqualsAsync(1, () => g5({x: 1}));
131 var g6 = async ({x}, g = () => x) => { { var x = 2; } return g(); };
132 assertEqualsAsync(1, () => g6({x: 1}));
133 var g7 = async ({x}) => { var g = () => x; var x = 2; return g(); };
134 assertEqualsAsync(2, () => g7({x: 1}));
135 var g8 = async ({x}) => { { var g = () => x; var x = 2; } return g(); };
136 assertEqualsAsync(2, () => g8({x: 1}));
137 var g9 = async ({x}, g = () => eval("x")) => { var x = 2; return g(); };
138 assertEqualsAsync(1, () => g9({x: 1}));
139
140 var g10 = async ({x}, y) => { var y; return y };
141 assertEqualsAsync(2, () => g10({x: 6}, 2));
142 var g11 = async ({x}, y) => { var z = y; var y = 2; return z; };
143 assertEqualsAsync(1, () => g11({x: 6}, 1));
144 var g12 = async (y, g = () => y) => { var y = 2; return g(); };
145 assertEqualsAsync(1, () => g12(1));
146 var g13 = async ({x}, y, [z], v) => { var x, y, z; return x*y*z*v };
147 assertEqualsAsync(210, () => g13({x: 2}, 3, [5], 7));
148
149 var g20 = async ({x}) => { function x() { return 2 }; return x(); }
150 assertEqualsAsync(2, () => g20({x: 1}));
151 var g21 = async ({x}) => { { function x() { return 2 } } return x(); }
152 assertThrowsAsync(() => g21({x: 1}), TypeError);
153
154 assertThrows("'use strict'; async function f(x) { let x = 0; }", SyntaxError);
155 assertThrows("'use strict'; async function f({x}) { let x = 0; }", SyntaxError );
156 assertThrows("'use strict'; async function f(x) { const x = 0; }", SyntaxError );
157 assertThrows("'use strict'; async function f({x}) { const x = 0; }", SyntaxErr or);
158
159 assertThrows("'use strict'; let g = async (x) => { let x = 0; }", SyntaxError) ;
160 assertThrows("'use strict'; let g = async ({x}) => { let x = 0; }", SyntaxErro r);
161 assertThrows("'use strict'; let g = async (x) => { const x = 0; }", SyntaxErro r);
162 assertThrows("'use strict'; let g = async ({x}) => { const x = 0; }", SyntaxEr ror);
163 }());
164
165 (function TestDefaults() {
166 async function f1(x = 1) { return x }
167 assertEqualsAsync(1, () => f1());
168 assertEqualsAsync(1, () => f1(undefined));
169 assertEqualsAsync(2, () => f1(2));
170 assertEqualsAsync(null, () => f1(null));
171
172 async function f2(x, y = x) { return x + y; }
173 assertEqualsAsync(8, () => f2(4));
174 assertEqualsAsync(8, () => f2(4, undefined));
175 assertEqualsAsync(6, () => f2(4, 2));
176
177 async function f3(x = 1, y) { return x + y; }
178 assertEqualsAsync(8, () => f3(5, 3));
179 assertEqualsAsync(3, () => f3(undefined, 2));
180 assertEqualsAsync(6, () => f3(4, 2));
181
182 async function f4(x = () => 1) { return x() }
183 assertEqualsAsync(1, () => f4());
184 assertEqualsAsync(1, () => f4(undefined));
185 assertEqualsAsync(2, () => f4(() => 2));
186 assertThrowsAsync(() => f4(null), TypeError);
187
188 async function f5(x, y = () => x) { return x + y(); }
189 assertEqualsAsync(8, () => f5(4));
190 assertEqualsAsync(8, () => f5(4, undefined));
191 assertEqualsAsync(6, () => f5(4, () => 2));
192
193 async function f6(x = {a: 1, m() { return 2 }}) { return x.a + x.m(); }
194 assertEqualsAsync(3, () => f6());
195 assertEqualsAsync(3, () => f6(undefined));
196 assertEqualsAsync(5, () => f6({a: 2, m() { return 3 }}));
197
198 var g1 = async (x = 1) => { return x };
199 assertEqualsAsync(1, () => g1());
200 assertEqualsAsync(1, () => g1(undefined));
201 assertEqualsAsync(2, () => g1(2));
202 assertEqualsAsync(null, () => g1(null));
203
204 var g2 = async (x, y = x) => { return x + y; };
205 assertEqualsAsync(8, () => g2(4));
206 assertEqualsAsync(8, () => g2(4, undefined));
207 assertEqualsAsync(6, () => g2(4, 2));
208
209 var g3 = async (x = 1, y) => { return x + y; };
210 assertEqualsAsync(8, () => g3(5, 3));
211 assertEqualsAsync(3, () => g3(undefined, 2));
212 assertEqualsAsync(6, () => g3(4, 2));
213
214 var g4 = async (x = () => 1) => { return x() };
215 assertEqualsAsync(1, () => g4());
216 assertEqualsAsync(1, () => g4(undefined));
217 assertEqualsAsync(2, () => g4(() => 2));
218 assertThrowsAsync(() => g4(null), TypeError);
219
220 var g5 = async (x, y = () => x) => { return x + y(); };
221 assertEqualsAsync(8, () => g5(4));
222 assertEqualsAsync(8, () => g5(4, undefined));
223 assertEqualsAsync(6, () => g5(4, () => 2));
224
225 var g6 = async (x = {a: 1, m() { return 2 }}) => { return x.a + x.m(); };
226 assertEqualsAsync(3, () => g6());
227 assertEqualsAsync(3, () => g6(undefined));
228 assertEqualsAsync(5, () => g6({a: 2, m() { return 3 }}));
229 }());
230
231
232 (function TestEvalInParameters() {
233 async function f1(x = eval(0)) { return x }
234 assertEqualsAsync(0, f1);
235 async function f2(x = () => eval(1)) { return x() }
236 assertEqualsAsync(1, f2);
237 })();
238
239
240 (function TestParameterScopingSloppy() {
241 var x = 1;
242
243 async function f1(a = x) { var x = 2; return a; }
244 assertEqualsAsync(1, f1);
245 async function f2(a = x) { function x() {}; return a; }
246 assertEqualsAsync(1, () => f2());
247 async function f3(a = eval("x")) { var x; return a; }
248 assertEqualsAsync(1, () => f3());
249 async function f31(a = eval("'use strict'; x")) { var x; return a; }
250 assertEqualsAsync(1, () => f31());
251 async function f4(a = function() { return x }) { var x; return a(); }
252 assertEqualsAsync(1, () => f4());
253 async function f5(a = () => x) { var x; return a(); }
254 assertEqualsAsync(1, () => f5());
255 async function f6(a = () => eval("x")) { var x; return a(); }
256 assertEqualsAsync(1, () => f6());
257 async function f61(a = () => { 'use strict'; return eval("x") }) { var x; retu rn a(); }
258 assertEqualsAsync(1, () => f61());
259 async function f62(a = () => eval("'use strict'; x")) { var x; return a(); }
260 assertEqualsAsync(1, () => f62());
261
262 var g1 = async (a = x) => { var x = 2; return a; };
263 assertEqualsAsync(1, () => g1());
264 var g2 = async (a = x) => { function x() {}; return a; };
265 assertEqualsAsync(1, () => g2());
266 var g3 = async (a = eval("x")) => { var x; return a; };
267 assertEqualsAsync(1, g3);
268 var g31 = async (a = eval("'use strict'; x")) => { var x; return a; };
269 assertEqualsAsync(1, () => g31());
270 var g4 = async (a = function() { return x }) => { var x; return a(); };
271 assertEqualsAsync(1, () => g4());
272 var g5 = async (a = () => x) => { var x; return a(); };
273 assertEqualsAsync(1, () => g5());
274 var g6 = async (a = () => eval("x")) => { var x; return a(); };
275 assertEqualsAsync(1, () => g6());
276 var g61 = async (a = () => { 'use strict'; return eval("x") }) => { var x; ret urn a(); };
277 assertEqualsAsync(1, () => g61());
278 var g62 = async (a = () => eval("'use strict'; x")) => { var x; return a(); };
279 assertEqualsAsync(1, () => g62());
280
281 var f11 = async function f(x = f) { var f; return x; }
282 assertEqualsAsync(f11, f11);
283 var f12 = async function f(x = f) { function f() {}; return x; }
284 assertEqualsAsync(f12, f12);
285 var f13 = async function f(f = 7, x = f) { return x; }
286 assertEqualsAsync(7, f13);
287
288 var o1 = {f: async function(x = this) { return x; }};
289 assertEqualsAsync(o1, () => o1.f());
290 assertEqualsAsync(1, () => o1.f(1));
291 })();
292
293 (function TestParameterScopingStrict() {
294 "use strict";
295 var x = 1;
296
297 async function f1(a = x) { let x = 2; return a; }
298 assertEqualsAsync(1, () => f1());
299 async function f2(a = x) { const x = 2; return a; }
300 assertEqualsAsync(1, () => f2());
301 async function f3(a = x) { function x() {}; return a; }
302 assertEqualsAsync(1, () => f3());
303 async function f4(a = eval("x")) { var x; return a; }
304 assertEqualsAsync(1, () => f4());
305 async function f5(a = () => eval("x")) { var x; return a(); }
306 assertEqualsAsync(1, () => f5());
307
308 var g1 = async (a = x) => { let x = 2; return a; };
309 assertEqualsAsync(1, () => g1());
310 var g2 = async (a = x) => { const x = 2; return a; };
311 assertEqualsAsync(1, () => g2());
312 var g3 = async (a = x) => { function x() {}; return a; };
313 assertEqualsAsync(1, () => g3());
314 var g4 = async (a = eval("x")) => { var x; return a; };
315 assertEqualsAsync(1, () => g4());
316 var g5 = async (a = () => eval("x")) => { var x; return a(); };
317 assertEqualsAsync(1, () => g5());
318
319 var f11 = async function f(x = f) { let f; return x; }
320 assertEqualsAsync(f11, f11);
321 var f12 = async function f(x = f) { const f = 0; return x; }
322 assertEqualsAsync(f12, f12);
323 var f13 = async function f(x = f) { function f() {}; return x; }
324 assertEqualsAsync(f13, f13);
325 })();
326
327 (function TestSloppyEvalScoping() {
328 var x = 1;
329
330 async function f1(y = eval("var x = 2")) { with ({}) { return x; } }
331 assertEqualsAsync(1, () => f1());
332 async function f2(y = eval("var x = 2"), z = x) { return z; }
333 assertEqualsAsync(1, () => f2());
334 assertEqualsAsync(1, () => f2(0));
335 async function f3(y = eval("var x = 2"), z = eval("x")) { return z; }
336 assertEqualsAsync(1, () => f3());
337 assertEqualsAsync(1, () => f3(0));
338 async function f8(y = (eval("var x = 2"), x)) { return y; }
339 assertEqualsAsync(2, () => f8());
340 assertEqualsAsync(0, () => f8(0));
341
342 async function f11(z = eval("var y = 2")) { return y; }
343 assertThrowsAsync(f11, ReferenceError);
344 async function f12(z = eval("var y = 2"), b = y) {}
345 assertThrowsAsync(f12, ReferenceError);
346 async function f13(z = eval("var y = 2"), b = eval("y")) {}
347 assertThrowsAsync(f13, ReferenceError);
348
349 async function f21(f = () => x) { eval("var x = 2"); return f() }
350 assertEqualsAsync(1, () => f21());
351 assertEqualsAsync(3, () => f21(() => 3));
352 async function f22(f = () => eval("x")) { eval("var x = 2"); return f() }
353 assertEqualsAsync(1, () => f22());
354 assertEqualsAsync(3, () => f22(() => 3));
355
356 var g1 = async (y = eval("var x = 2")) => { with ({}) { return x; } };
357 assertEqualsAsync(1, () => g1());
358 var g2 = async (y = eval("var x = 2"), z = x) => { return z; };
359 assertEqualsAsync(1, () => g2());
360 assertEqualsAsync(1, () => g2(0));
361 var g3 = async (y = eval("var x = 2"), z = eval("x")) => { return z; };
362 assertEqualsAsync(1, () => g3());
363 assertEqualsAsync(1, () => g3(0));
364 var g8 = async (y = (eval("var x = 2"), x)) => { return y; };
365 assertEqualsAsync(2, () => g8());
366 assertEqualsAsync(0, () => g8(0));
367
368 var g11 = async (z = eval("var y = 2")) => { return y; };
369 assertThrowsAsync(g11, ReferenceError);
370 var g12 = async (z = eval("var y = 2"), b = y) => {};
371 assertThrowsAsync(g12, ReferenceError);
372 var g13 = async (z = eval("var y = 2"), b = eval("y")) => {};
373 assertThrowsAsync(g13, ReferenceError);
374
375 var g21 = async (f = () => x) => { eval("var x = 2"); return f() };
376 assertEqualsAsync(1, () => g21());
377 assertEqualsAsync(3, () => g21(() => 3));
378 var g22 = async (f = () => eval("x")) => { eval("var x = 2"); return f() };
379 assertEqualsAsync(1, () => g22());
380 assertEqualsAsync(3, () => g22(() => 3));
381 })();
382
383
384 (function TestStrictEvalScoping() {
385 'use strict';
386 var x = 1;
387
388 async function f1(y = eval("var x = 2")) { return x; }
389 assertEqualsAsync(1, () => f1());
390 async function f2(y = eval("var x = 2"), z = x) { return z; }
391 assertEqualsAsync(1, () => f2());
392 assertEqualsAsync(1, () => f2(0));
393 async function f3(y = eval("var x = 2"), z = eval("x")) { return z; }
394 assertEqualsAsync(1, () => f3());
395 assertEqualsAsync(1, () => f3(0));
396 async function f8(y = (eval("var x = 2"), x)) { return y; }
397 assertEqualsAsync(1, () => f8());
398 assertEqualsAsync(0, () => f8(0));
399
400 async function f11(z = eval("var y = 2")) { return y; }
401 assertThrowsAsync(f11, ReferenceError);
402 async function f12(z = eval("var y = 2"), b = y) {}
403 assertThrowsAsync(f12, ReferenceError);
404 async function f13(z = eval("var y = 2"), b = eval("y")) {}
405 assertThrowsAsync(f13, ReferenceError);
406
407 async function f21(f = () => x) { eval("var x = 2"); return f() }
408 assertEqualsAsync(1, () => f21());
409 assertEqualsAsync(3, () => f21(() => 3));
410 async function f22(f = () => eval("x")) { eval("var x = 2"); return f() }
411 assertEqualsAsync(1, () => f22());
412 assertEqualsAsync(3, () => f22(() => 3));
413 })();
414
415 (function TestParameterTDZSloppy() {
416 async function f1(a = x, x) { return a }
417 assertThrowsAsync(() => f1(undefined, 4), ReferenceError);
418 assertEqualsAsync(4, () => f1(4, 5));
419 async function f2(a = eval("x"), x) { return a }
420 assertThrowsAsync(() => f2(undefined, 4), ReferenceError);
421 assertEqualsAsync(4, () => f2(4, 5));
422 async function f3(a = eval("'use strict'; x"), x) { return a }
423 assertThrowsAsync(() => f3(undefined, 4), ReferenceError);
424 assertEqualsAsync(4, () => f3(4, 5));
425 async function f4(a = () => x, x) { return a() }
426 assertEqualsAsync(4, () => f4(() => 4, 5));
427 async function f5(a = () => eval("x"), x) { return a() }
428 assertEqualsAsync(4, () => f5(() => 4, 5));
429 async function f6(a = () => eval("'use strict'; x"), x) { return a() }
430 assertEqualsAsync(4, () => f6(() => 4, 5));
431
432 async function f11(a = x, x = 2) { return a }
433 assertThrowsAsync(() => f11(), ReferenceError);
434 assertThrowsAsync(() => f11(undefined), ReferenceError);
435 assertThrowsAsync(() => f11(undefined, 4), ReferenceError);
436 assertEqualsAsync(4, () => f1(4, 5));
437 async function f12(a = eval("x"), x = 2) { return a }
438 assertThrowsAsync(() => f12(), ReferenceError);
439 assertThrowsAsync(() => f12(undefined), ReferenceError);
440 assertThrowsAsync(() => f12(undefined, 4), ReferenceError);
441 assertEqualsAsync(4, () => f12(4, 5));
442 async function f13(a = eval("'use strict'; x"), x = 2) { return a }
443 assertThrowsAsync(() => f13(), ReferenceError);
444 assertThrowsAsync(() => f13(undefined), ReferenceError);
445 assertThrowsAsync(() => f13(undefined, 4), ReferenceError);
446 assertEqualsAsync(4, () => f13(4, 5));
447
448 async function f21(x = function() { return a }, ...a) { return x()[0] }
449 assertEqualsAsync(4, () => f21(undefined, 4));
450 async function f22(x = () => a, ...a) { return x()[0] }
451 assertEqualsAsync(4, () => f22(undefined, 4));
452 async function f23(x = () => eval("a"), ...a) { return x()[0] }
453 assertEqualsAsync(4, () => f23(undefined, 4));
454 async function f24(x = () => {'use strict'; return eval("a") }, ...a) {
455 return x()[0]
456 }
457 assertEqualsAsync(4, () => f24(undefined, 4));
458 async function f25(x = () => eval("'use strict'; a"), ...a) { return x()[0] }
459 assertEqualsAsync(4, () => f25(undefined, 4));
460
461 var g1 = async (x = function() { return a }, ...a) => { return x()[0] };
462 assertEqualsAsync(4, () => g1(undefined, 4));
463 var g2 = async (x = () => a, ...a) => { return x()[0] };
464 assertEqualsAsync(4, () => g2(undefined, 4));
465 })();
466
467 (function TestParameterTDZStrict() {
468 "use strict";
469
470 async function f1(a = eval("x"), x) { return a }
471 assertThrowsAsync(() => f1(undefined, 4), ReferenceError);
472 assertEqualsAsync(4, () => f1(4, 5));
473 async function f2(a = () => eval("x"), x) { return a() }
474 assertEqualsAsync(4, () => f2(() => 4, 5));
475
476 async function f11(a = eval("x"), x = 2) { return a }
477 assertThrowsAsync(() => f11(), ReferenceError);
478 assertThrowsAsync(() => f11(undefined), ReferenceError);
479 assertThrowsAsync(() => f11(undefined, 4), ReferenceError);
480 assertEqualsAsync(4, () => f11(4, 5));
481
482 async function f21(x = () => eval("a"), ...a) { return x()[0] }
483 assertEqualsAsync(4, () => f21(undefined, 4));
484 })();
485
486 (function TestArgumentsForNonSimpleParameters() {
487 async function f1(x = 900) { arguments[0] = 1; return x }
488 assertEqualsAsync(9, () => f1(9));
489 assertEqualsAsync(900, () => f1());
490 async function f2(x = 1001) { x = 2; return arguments[0] }
491 assertEqualsAsync(10, () => f2(10));
492 assertEqualsAsync(undefined, () => f2());
493 }());
494
495
496 (function TestFunctionLength() {
497 assertEquals(0, (async function(x = 1) {}).length);
498 assertEquals(0, (async function(x = 1, ...a) {}).length);
499 assertEquals(1, (async function(x, y = 1) {}).length);
500 assertEquals(1, (async function(x, y = 1, ...a) {}).length);
501 assertEquals(2, (async function(x, y, z = 1) {}).length);
502 assertEquals(2, (async function(x, y, z = 1, ...a) {}).length);
503 assertEquals(1, (async function(x, y = 1, z) {}).length);
504 assertEquals(1, (async function(x, y = 1, z, ...a) {}).length);
505 assertEquals(1, (async function(x, y = 1, z, v = 2) {}).length);
506 assertEquals(1, (async function(x, y = 1, z, v = 2, ...a) {}).length);
507 })();
508
509 (function TestDirectiveThrows() {
510 "use strict";
511
512 assertThrows("(async function(x=1){'use strict';})", SyntaxError);
513 assertThrows("(async function(a, x=1){'use strict';})", SyntaxError);
514 assertThrows("(async function({x}){'use strict';})", SyntaxError);
515 })();
OLDNEW
« no previous file with comments | « test/mjsunit/es6/generator-destructuring.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698