Bug 1185106 - Part 5.6: Add parser test for yield in async function declaration. r=till
authorTooru Fujisawa <arai_a@mac.com>
Sun, 28 Aug 2016 23:58:28 +0900
changeset 320230 ce9efeed3b8718a6a48c0d9f94b591343d5179af
parent 320229 a467817a09def09b9b9ed5fd88f905122af0d2ff
child 320231 eb5f24802ccbb0e44cf0448c9351755b93a15943
push id20754
push usercbook@mozilla.com
push dateMon, 31 Oct 2016 15:58:35 +0000
treeherderfx-team@b1b66b1780c2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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 (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);