OLD | NEW |
| (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 // These errors are not recognized in lazy parsing; see mjsunit/bugs/bug-2728.
js | |
155 assertThrows("'use strict'; (async function f(x) { let x = 0; })()", SyntaxErr
or); | |
156 assertThrows("'use strict'; (async function f({x}) { let x = 0; })()", SyntaxE
rror); | |
157 assertThrows("'use strict'; (async function f(x) { const x = 0; })()", SyntaxE
rror); | |
158 assertThrows("'use strict'; (async function f({x}) { const x = 0; })()", Synta
xError); | |
159 | |
160 assertThrows("'use strict'; let g = async (x) => { let x = 0; }", SyntaxError)
; | |
161 assertThrows("'use strict'; let g = async ({x}) => { let x = 0; }", SyntaxErro
r); | |
162 assertThrows("'use strict'; let g = async (x) => { const x = 0; }", SyntaxErro
r); | |
163 assertThrows("'use strict'; let g = async ({x}) => { const x = 0; }", SyntaxEr
ror); | |
164 }()); | |
165 | |
166 (function TestDefaults() { | |
167 async function f1(x = 1) { return x } | |
168 assertEqualsAsync(1, () => f1()); | |
169 assertEqualsAsync(1, () => f1(undefined)); | |
170 assertEqualsAsync(2, () => f1(2)); | |
171 assertEqualsAsync(null, () => f1(null)); | |
172 | |
173 async function f2(x, y = x) { return x + y; } | |
174 assertEqualsAsync(8, () => f2(4)); | |
175 assertEqualsAsync(8, () => f2(4, undefined)); | |
176 assertEqualsAsync(6, () => f2(4, 2)); | |
177 | |
178 async function f3(x = 1, y) { return x + y; } | |
179 assertEqualsAsync(8, () => f3(5, 3)); | |
180 assertEqualsAsync(3, () => f3(undefined, 2)); | |
181 assertEqualsAsync(6, () => f3(4, 2)); | |
182 | |
183 async function f4(x = () => 1) { return x() } | |
184 assertEqualsAsync(1, () => f4()); | |
185 assertEqualsAsync(1, () => f4(undefined)); | |
186 assertEqualsAsync(2, () => f4(() => 2)); | |
187 assertThrowsAsync(() => f4(null), TypeError); | |
188 | |
189 async function f5(x, y = () => x) { return x + y(); } | |
190 assertEqualsAsync(8, () => f5(4)); | |
191 assertEqualsAsync(8, () => f5(4, undefined)); | |
192 assertEqualsAsync(6, () => f5(4, () => 2)); | |
193 | |
194 async function f6(x = {a: 1, m() { return 2 }}) { return x.a + x.m(); } | |
195 assertEqualsAsync(3, () => f6()); | |
196 assertEqualsAsync(3, () => f6(undefined)); | |
197 assertEqualsAsync(5, () => f6({a: 2, m() { return 3 }})); | |
198 | |
199 var g1 = async (x = 1) => { return x }; | |
200 assertEqualsAsync(1, () => g1()); | |
201 assertEqualsAsync(1, () => g1(undefined)); | |
202 assertEqualsAsync(2, () => g1(2)); | |
203 assertEqualsAsync(null, () => g1(null)); | |
204 | |
205 var g2 = async (x, y = x) => { return x + y; }; | |
206 assertEqualsAsync(8, () => g2(4)); | |
207 assertEqualsAsync(8, () => g2(4, undefined)); | |
208 assertEqualsAsync(6, () => g2(4, 2)); | |
209 | |
210 var g3 = async (x = 1, y) => { return x + y; }; | |
211 assertEqualsAsync(8, () => g3(5, 3)); | |
212 assertEqualsAsync(3, () => g3(undefined, 2)); | |
213 assertEqualsAsync(6, () => g3(4, 2)); | |
214 | |
215 var g4 = async (x = () => 1) => { return x() }; | |
216 assertEqualsAsync(1, () => g4()); | |
217 assertEqualsAsync(1, () => g4(undefined)); | |
218 assertEqualsAsync(2, () => g4(() => 2)); | |
219 assertThrowsAsync(() => g4(null), TypeError); | |
220 | |
221 var g5 = async (x, y = () => x) => { return x + y(); }; | |
222 assertEqualsAsync(8, () => g5(4)); | |
223 assertEqualsAsync(8, () => g5(4, undefined)); | |
224 assertEqualsAsync(6, () => g5(4, () => 2)); | |
225 | |
226 var g6 = async (x = {a: 1, m() { return 2 }}) => { return x.a + x.m(); }; | |
227 assertEqualsAsync(3, () => g6()); | |
228 assertEqualsAsync(3, () => g6(undefined)); | |
229 assertEqualsAsync(5, () => g6({a: 2, m() { return 3 }})); | |
230 }()); | |
231 | |
232 | |
233 (function TestEvalInParameters() { | |
234 async function f1(x = eval(0)) { return x } | |
235 assertEqualsAsync(0, f1); | |
236 async function f2(x = () => eval(1)) { return x() } | |
237 assertEqualsAsync(1, f2); | |
238 })(); | |
239 | |
240 | |
241 (function TestParameterScopingSloppy() { | |
242 var x = 1; | |
243 | |
244 async function f1(a = x) { var x = 2; return a; } | |
245 assertEqualsAsync(1, f1); | |
246 async function f2(a = x) { function x() {}; return a; } | |
247 assertEqualsAsync(1, () => f2()); | |
248 async function f3(a = eval("x")) { var x; return a; } | |
249 assertEqualsAsync(1, () => f3()); | |
250 async function f31(a = eval("'use strict'; x")) { var x; return a; } | |
251 assertEqualsAsync(1, () => f31()); | |
252 async function f4(a = function() { return x }) { var x; return a(); } | |
253 assertEqualsAsync(1, () => f4()); | |
254 async function f5(a = () => x) { var x; return a(); } | |
255 assertEqualsAsync(1, () => f5()); | |
256 async function f6(a = () => eval("x")) { var x; return a(); } | |
257 assertEqualsAsync(1, () => f6()); | |
258 async function f61(a = () => { 'use strict'; return eval("x") }) { var x; retu
rn a(); } | |
259 assertEqualsAsync(1, () => f61()); | |
260 async function f62(a = () => eval("'use strict'; x")) { var x; return a(); } | |
261 assertEqualsAsync(1, () => f62()); | |
262 | |
263 var g1 = async (a = x) => { var x = 2; return a; }; | |
264 assertEqualsAsync(1, () => g1()); | |
265 var g2 = async (a = x) => { function x() {}; return a; }; | |
266 assertEqualsAsync(1, () => g2()); | |
267 var g3 = async (a = eval("x")) => { var x; return a; }; | |
268 assertEqualsAsync(1, g3); | |
269 var g31 = async (a = eval("'use strict'; x")) => { var x; return a; }; | |
270 assertEqualsAsync(1, () => g31()); | |
271 var g4 = async (a = function() { return x }) => { var x; return a(); }; | |
272 assertEqualsAsync(1, () => g4()); | |
273 var g5 = async (a = () => x) => { var x; return a(); }; | |
274 assertEqualsAsync(1, () => g5()); | |
275 var g6 = async (a = () => eval("x")) => { var x; return a(); }; | |
276 assertEqualsAsync(1, () => g6()); | |
277 var g61 = async (a = () => { 'use strict'; return eval("x") }) => { var x; ret
urn a(); }; | |
278 assertEqualsAsync(1, () => g61()); | |
279 var g62 = async (a = () => eval("'use strict'; x")) => { var x; return a(); }; | |
280 assertEqualsAsync(1, () => g62()); | |
281 | |
282 var f11 = async function f(x = f) { var f; return x; } | |
283 assertEqualsAsync(f11, f11); | |
284 var f12 = async function f(x = f) { function f() {}; return x; } | |
285 assertEqualsAsync(f12, f12); | |
286 var f13 = async function f(f = 7, x = f) { return x; } | |
287 assertEqualsAsync(7, f13); | |
288 | |
289 var o1 = {f: async function(x = this) { return x; }}; | |
290 assertEqualsAsync(o1, () => o1.f()); | |
291 assertEqualsAsync(1, () => o1.f(1)); | |
292 })(); | |
293 | |
294 (function TestParameterScopingStrict() { | |
295 "use strict"; | |
296 var x = 1; | |
297 | |
298 async function f1(a = x) { let x = 2; return a; } | |
299 assertEqualsAsync(1, () => f1()); | |
300 async function f2(a = x) { const x = 2; return a; } | |
301 assertEqualsAsync(1, () => f2()); | |
302 async function f3(a = x) { function x() {}; return a; } | |
303 assertEqualsAsync(1, () => f3()); | |
304 async function f4(a = eval("x")) { var x; return a; } | |
305 assertEqualsAsync(1, () => f4()); | |
306 async function f5(a = () => eval("x")) { var x; return a(); } | |
307 assertEqualsAsync(1, () => f5()); | |
308 | |
309 var g1 = async (a = x) => { let x = 2; return a; }; | |
310 assertEqualsAsync(1, () => g1()); | |
311 var g2 = async (a = x) => { const x = 2; return a; }; | |
312 assertEqualsAsync(1, () => g2()); | |
313 var g3 = async (a = x) => { function x() {}; return a; }; | |
314 assertEqualsAsync(1, () => g3()); | |
315 var g4 = async (a = eval("x")) => { var x; return a; }; | |
316 assertEqualsAsync(1, () => g4()); | |
317 var g5 = async (a = () => eval("x")) => { var x; return a(); }; | |
318 assertEqualsAsync(1, () => g5()); | |
319 | |
320 var f11 = async function f(x = f) { let f; return x; } | |
321 assertEqualsAsync(f11, f11); | |
322 var f12 = async function f(x = f) { const f = 0; return x; } | |
323 assertEqualsAsync(f12, f12); | |
324 var f13 = async function f(x = f) { function f() {}; return x; } | |
325 assertEqualsAsync(f13, f13); | |
326 })(); | |
327 | |
328 (function TestSloppyEvalScoping() { | |
329 var x = 1; | |
330 | |
331 async function f1(y = eval("var x = 2")) { with ({}) { return x; } } | |
332 assertEqualsAsync(1, () => f1()); | |
333 async function f2(y = eval("var x = 2"), z = x) { return z; } | |
334 assertEqualsAsync(1, () => f2()); | |
335 assertEqualsAsync(1, () => f2(0)); | |
336 async function f3(y = eval("var x = 2"), z = eval("x")) { return z; } | |
337 assertEqualsAsync(1, () => f3()); | |
338 assertEqualsAsync(1, () => f3(0)); | |
339 async function f8(y = (eval("var x = 2"), x)) { return y; } | |
340 assertEqualsAsync(2, () => f8()); | |
341 assertEqualsAsync(0, () => f8(0)); | |
342 | |
343 async function f11(z = eval("var y = 2")) { return y; } | |
344 assertThrowsAsync(f11, ReferenceError); | |
345 async function f12(z = eval("var y = 2"), b = y) {} | |
346 assertThrowsAsync(f12, ReferenceError); | |
347 async function f13(z = eval("var y = 2"), b = eval("y")) {} | |
348 assertThrowsAsync(f13, ReferenceError); | |
349 | |
350 async function f21(f = () => x) { eval("var x = 2"); return f() } | |
351 assertEqualsAsync(1, () => f21()); | |
352 assertEqualsAsync(3, () => f21(() => 3)); | |
353 async function f22(f = () => eval("x")) { eval("var x = 2"); return f() } | |
354 assertEqualsAsync(1, () => f22()); | |
355 assertEqualsAsync(3, () => f22(() => 3)); | |
356 | |
357 var g1 = async (y = eval("var x = 2")) => { with ({}) { return x; } }; | |
358 assertEqualsAsync(1, () => g1()); | |
359 var g2 = async (y = eval("var x = 2"), z = x) => { return z; }; | |
360 assertEqualsAsync(1, () => g2()); | |
361 assertEqualsAsync(1, () => g2(0)); | |
362 var g3 = async (y = eval("var x = 2"), z = eval("x")) => { return z; }; | |
363 assertEqualsAsync(1, () => g3()); | |
364 assertEqualsAsync(1, () => g3(0)); | |
365 var g8 = async (y = (eval("var x = 2"), x)) => { return y; }; | |
366 assertEqualsAsync(2, () => g8()); | |
367 assertEqualsAsync(0, () => g8(0)); | |
368 | |
369 var g11 = async (z = eval("var y = 2")) => { return y; }; | |
370 assertThrowsAsync(g11, ReferenceError); | |
371 var g12 = async (z = eval("var y = 2"), b = y) => {}; | |
372 assertThrowsAsync(g12, ReferenceError); | |
373 var g13 = async (z = eval("var y = 2"), b = eval("y")) => {}; | |
374 assertThrowsAsync(g13, ReferenceError); | |
375 | |
376 var g21 = async (f = () => x) => { eval("var x = 2"); return f() }; | |
377 assertEqualsAsync(1, () => g21()); | |
378 assertEqualsAsync(3, () => g21(() => 3)); | |
379 var g22 = async (f = () => eval("x")) => { eval("var x = 2"); return f() }; | |
380 assertEqualsAsync(1, () => g22()); | |
381 assertEqualsAsync(3, () => g22(() => 3)); | |
382 })(); | |
383 | |
384 | |
385 (function TestStrictEvalScoping() { | |
386 'use strict'; | |
387 var x = 1; | |
388 | |
389 async function f1(y = eval("var x = 2")) { return x; } | |
390 assertEqualsAsync(1, () => f1()); | |
391 async function f2(y = eval("var x = 2"), z = x) { return z; } | |
392 assertEqualsAsync(1, () => f2()); | |
393 assertEqualsAsync(1, () => f2(0)); | |
394 async function f3(y = eval("var x = 2"), z = eval("x")) { return z; } | |
395 assertEqualsAsync(1, () => f3()); | |
396 assertEqualsAsync(1, () => f3(0)); | |
397 async function f8(y = (eval("var x = 2"), x)) { return y; } | |
398 assertEqualsAsync(1, () => f8()); | |
399 assertEqualsAsync(0, () => f8(0)); | |
400 | |
401 async function f11(z = eval("var y = 2")) { return y; } | |
402 assertThrowsAsync(f11, ReferenceError); | |
403 async function f12(z = eval("var y = 2"), b = y) {} | |
404 assertThrowsAsync(f12, ReferenceError); | |
405 async function f13(z = eval("var y = 2"), b = eval("y")) {} | |
406 assertThrowsAsync(f13, ReferenceError); | |
407 | |
408 async function f21(f = () => x) { eval("var x = 2"); return f() } | |
409 assertEqualsAsync(1, () => f21()); | |
410 assertEqualsAsync(3, () => f21(() => 3)); | |
411 async function f22(f = () => eval("x")) { eval("var x = 2"); return f() } | |
412 assertEqualsAsync(1, () => f22()); | |
413 assertEqualsAsync(3, () => f22(() => 3)); | |
414 })(); | |
415 | |
416 (function TestParameterTDZSloppy() { | |
417 async function f1(a = x, x) { return a } | |
418 assertThrowsAsync(() => f1(undefined, 4), ReferenceError); | |
419 assertEqualsAsync(4, () => f1(4, 5)); | |
420 async function f2(a = eval("x"), x) { return a } | |
421 assertThrowsAsync(() => f2(undefined, 4), ReferenceError); | |
422 assertEqualsAsync(4, () => f2(4, 5)); | |
423 async function f3(a = eval("'use strict'; x"), x) { return a } | |
424 assertThrowsAsync(() => f3(undefined, 4), ReferenceError); | |
425 assertEqualsAsync(4, () => f3(4, 5)); | |
426 async function f4(a = () => x, x) { return a() } | |
427 assertEqualsAsync(4, () => f4(() => 4, 5)); | |
428 async function f5(a = () => eval("x"), x) { return a() } | |
429 assertEqualsAsync(4, () => f5(() => 4, 5)); | |
430 async function f6(a = () => eval("'use strict'; x"), x) { return a() } | |
431 assertEqualsAsync(4, () => f6(() => 4, 5)); | |
432 | |
433 async function f11(a = x, x = 2) { return a } | |
434 assertThrowsAsync(() => f11(), ReferenceError); | |
435 assertThrowsAsync(() => f11(undefined), ReferenceError); | |
436 assertThrowsAsync(() => f11(undefined, 4), ReferenceError); | |
437 assertEqualsAsync(4, () => f1(4, 5)); | |
438 async function f12(a = eval("x"), x = 2) { return a } | |
439 assertThrowsAsync(() => f12(), ReferenceError); | |
440 assertThrowsAsync(() => f12(undefined), ReferenceError); | |
441 assertThrowsAsync(() => f12(undefined, 4), ReferenceError); | |
442 assertEqualsAsync(4, () => f12(4, 5)); | |
443 async function f13(a = eval("'use strict'; x"), x = 2) { return a } | |
444 assertThrowsAsync(() => f13(), ReferenceError); | |
445 assertThrowsAsync(() => f13(undefined), ReferenceError); | |
446 assertThrowsAsync(() => f13(undefined, 4), ReferenceError); | |
447 assertEqualsAsync(4, () => f13(4, 5)); | |
448 | |
449 async function f21(x = function() { return a }, ...a) { return x()[0] } | |
450 assertEqualsAsync(4, () => f21(undefined, 4)); | |
451 async function f22(x = () => a, ...a) { return x()[0] } | |
452 assertEqualsAsync(4, () => f22(undefined, 4)); | |
453 async function f23(x = () => eval("a"), ...a) { return x()[0] } | |
454 assertEqualsAsync(4, () => f23(undefined, 4)); | |
455 async function f24(x = () => {'use strict'; return eval("a") }, ...a) { | |
456 return x()[0] | |
457 } | |
458 assertEqualsAsync(4, () => f24(undefined, 4)); | |
459 async function f25(x = () => eval("'use strict'; a"), ...a) { return x()[0] } | |
460 assertEqualsAsync(4, () => f25(undefined, 4)); | |
461 | |
462 var g1 = async (x = function() { return a }, ...a) => { return x()[0] }; | |
463 assertEqualsAsync(4, () => g1(undefined, 4)); | |
464 var g2 = async (x = () => a, ...a) => { return x()[0] }; | |
465 assertEqualsAsync(4, () => g2(undefined, 4)); | |
466 })(); | |
467 | |
468 (function TestParameterTDZStrict() { | |
469 "use strict"; | |
470 | |
471 async function f1(a = eval("x"), x) { return a } | |
472 assertThrowsAsync(() => f1(undefined, 4), ReferenceError); | |
473 assertEqualsAsync(4, () => f1(4, 5)); | |
474 async function f2(a = () => eval("x"), x) { return a() } | |
475 assertEqualsAsync(4, () => f2(() => 4, 5)); | |
476 | |
477 async function f11(a = eval("x"), x = 2) { return a } | |
478 assertThrowsAsync(() => f11(), ReferenceError); | |
479 assertThrowsAsync(() => f11(undefined), ReferenceError); | |
480 assertThrowsAsync(() => f11(undefined, 4), ReferenceError); | |
481 assertEqualsAsync(4, () => f11(4, 5)); | |
482 | |
483 async function f21(x = () => eval("a"), ...a) { return x()[0] } | |
484 assertEqualsAsync(4, () => f21(undefined, 4)); | |
485 })(); | |
486 | |
487 (function TestArgumentsForNonSimpleParameters() { | |
488 async function f1(x = 900) { arguments[0] = 1; return x } | |
489 assertEqualsAsync(9, () => f1(9)); | |
490 assertEqualsAsync(900, () => f1()); | |
491 async function f2(x = 1001) { x = 2; return arguments[0] } | |
492 assertEqualsAsync(10, () => f2(10)); | |
493 assertEqualsAsync(undefined, () => f2()); | |
494 }()); | |
495 | |
496 | |
497 (function TestFunctionLength() { | |
498 assertEquals(0, (async function(x = 1) {}).length); | |
499 assertEquals(0, (async function(x = 1, ...a) {}).length); | |
500 assertEquals(1, (async function(x, y = 1) {}).length); | |
501 assertEquals(1, (async function(x, y = 1, ...a) {}).length); | |
502 assertEquals(2, (async function(x, y, z = 1) {}).length); | |
503 assertEquals(2, (async function(x, y, z = 1, ...a) {}).length); | |
504 assertEquals(1, (async function(x, y = 1, z) {}).length); | |
505 assertEquals(1, (async function(x, y = 1, z, ...a) {}).length); | |
506 assertEquals(1, (async function(x, y = 1, z, v = 2) {}).length); | |
507 assertEquals(1, (async function(x, y = 1, z, v = 2, ...a) {}).length); | |
508 })(); | |
509 | |
510 (function TestDirectiveThrows() { | |
511 "use strict"; | |
512 | |
513 assertThrows("(async function(x=1){'use strict';})", SyntaxError); | |
514 assertThrows("(async function(a, x=1){'use strict';})", SyntaxError); | |
515 assertThrows("(async function({x}){'use strict';})", SyntaxError); | |
516 })(); | |
OLD | NEW |