1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
var BUGNUMBER = 1185106;
var summary = "yield handling in async function";
print(BUGNUMBER + ": " + summary);
function testPassArgsBody(argsbody) {
Reflect.parse(`async function a${argsbody}`);
Reflect.parse(`(async function a${argsbody})`);
Reflect.parse(`(async function ${argsbody})`);
Reflect.parse(`({ async m${argsbody} })`);
}
function testErrorArgsBody(argsbody, prefix="") {
assertThrowsInstanceOf(() => Reflect.parse(`${prefix} async function a${argsbody}`), SyntaxError);
assertThrowsInstanceOf(() => Reflect.parse(`${prefix} (async function a${argsbody})`), SyntaxError);
assertThrowsInstanceOf(() => Reflect.parse(`${prefix} (async function ${argsbody})`), SyntaxError);
assertThrowsInstanceOf(() => Reflect.parse(`${prefix} ({ async m${argsbody} })`), SyntaxError);
}
function testErrorArgsBodyStrict(argsbody) {
testErrorArgsBody(argsbody);
testErrorArgsBody(argsbody, "'use strict'; ");
assertThrowsInstanceOf(() => Reflect.parse(`class X { async m${argsbody} }`), SyntaxError);
assertThrowsInstanceOf(() => Reflect.parse(`class X { static async m${argsbody} }`), SyntaxError);
assertThrowsInstanceOf(() => Reflect.parse(`export default async function ${argsbody}`, { target: "module" }), SyntaxError);
}
if (typeof Reflect !== "undefined" && Reflect.parse) {
// `yield` handling is inherited in async function declaration name.
Reflect.parse("async function yield() {}");
Reflect.parse("function f() { async function yield() {} }");
assertThrowsInstanceOf(() => Reflect.parse("function* g() { async function yield() {} }"), SyntaxError);
assertThrowsInstanceOf(() => Reflect.parse("'use strict'; async function yield() {}"), SyntaxError);
// `yield` is treated as an identifier in an async function expression name.
// `yield` is not allowed as an identifier in strict code.
Reflect.parse("(async function yield() {});");
Reflect.parse("function f() { (async function yield() {}); }");
Reflect.parse("function* g() { (async function yield() {}); }");
assertThrowsInstanceOf(() => Reflect.parse("'use strict'; (async function yield() {});"), SyntaxError);
// `yield` handling is inherited in async method name.
Reflect.parse("({ async yield() {} });");
Reflect.parse("function f() { ({ async yield() {} }); }");
Reflect.parse("function* g() { ({ async yield() {} }); }");
Reflect.parse("'use strict'; ({ async yield() {} });");
Reflect.parse("class X { async yield() {} }");
Reflect.parse("({ async [yield]() {} });");
Reflect.parse("function f() { ({ async [yield]() {} }); }");
Reflect.parse("function* g() { ({ async [yield]() {} }); }");
assertThrowsInstanceOf(() => Reflect.parse("'use strict'; ({ async [yield]() {} });"), SyntaxError);
assertThrowsInstanceOf(() => Reflect.parse("class X { async [yield]() {} }"), SyntaxError);
// `yield` is treated as an identifier in an async function parameter
// `yield` is not allowed as an identifier in strict code.
testPassArgsBody("(yield) {}");
testPassArgsBody("(yield = 1) {}");
testPassArgsBody("(a = yield) {}");
testErrorArgsBodyStrict("(yield 3) {}");
testErrorArgsBodyStrict("(a = yield 3) {}");
// `yield` is treated as an identifier in an async function body
// `yield` is not allowed as an identifier in strict code.
testPassArgsBody("() { yield; }");
testPassArgsBody("() { yield = 1; }");
testErrorArgsBodyStrict("() { yield 3; }");
}
if (typeof reportCompare === "function")
reportCompare(true, true);
|