Bug 1185106 - Part 5.6: Add parser test for yield in async function declaration. r=till draft
authorTooru Fujisawa <arai_a@mac.com>
Sun, 28 Aug 2016 23:58:28 +0900
changeset 430931 bc51f7a59554539c5f2dc42715a129088949d428
parent 430930 c66eccc055fa97c8eb2d9f127618b5bfa89841af
child 430932 6bde9502ed3cbcf771b8169ff89a58922dfae87d
push id33945
push userarai_a@mac.com
push dateFri, 28 Oct 2016 11:34:02 +0000
reviewerstill
bugs1185106
milestone52.0a1
Bug 1185106 - Part 5.6: Add parser test for yield in async function declaration. r=till MozReview-Commit-ID: DsqGxUONwDr
js/src/tests/ecma_7/AsyncFunctions/yield.js
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_7/AsyncFunctions/yield.js
@@ -0,0 +1,42 @@
+var BUGNUMBER = 1185106;
+var summary = "yield handling in async function";
+
+print(BUGNUMBER + ": " + summary);
+
+function testPassArgsBody(argsbody) {
+    Reflect.parse(`async function a${argsbody}`);
+}
+
+function testErrorArgsBody(argsbody, prefix="") {
+    assertThrows(() => Reflect.parse(`${prefix} async function a${argsbody}`), SyntaxError);
+}
+
+function testErrorArgsBodyStrict(argsbody) {
+    testErrorArgsBody(argsbody);
+    testErrorArgsBody(argsbody, "'use strict'; ");
+}
+
+if (asyncFunctionsEnabled() && 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() {} }");
+    assertThrows(() => Reflect.parse("function* g() { async function yield() {} }"), SyntaxError);
+    assertThrows(() => Reflect.parse("'use strict'; async function 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);