Truly independent web browser
LibJS: Reject yield as the parameter of an async arrow in a generator
Shannon Booth1544fd5c014b
diff --git a/Libraries/LibJS/Parser/Rust/src/expr.rs b/Libraries/LibJS/Parser/Rust/src/expr.rsindex 1502f78dfa0..a3e8a7f2237 100644--- a/Libraries/LibJS/Parser/Rust/src/expr.rs+++ b/Libraries/LibJS/Parser/Rust/src/expr.rs@@ -812,6 +812,15 @@ impl<'a: 'k, 'k, U: Unit> Parser<'a, 'k, U> {self.unexpected();return 0;}+ // 15.9 Async Arrow Function Definitions, https://tc39.es/ecma262/#sec-async-arrow-function-definitions+ // AsyncArrowBindingIdentifier[Yield] : BindingIdentifier[?Yield, +Await]+ // 13.1.1 Static Semantics: Early Errors, https://tc39.es/ecma262/#sec-identifiers-static-semantics-early-errors+ // BindingIdentifier[Yield, Await] : yield+ // It is a Syntax Error if this production has a [Yield] parameter.+ if param == N_YIELD && self.ctx & ctx::GENERATOR != 0 {+ self.fail(param_pos, "'yield' is not allowed as an identifier in this context");+ return 0;+ }return self.parse_arrow_single(start, param, param_pos, true, no_in);}}diff --git a/Tests/LibJS/Runtime/async-arrow-function-syntax.js b/Tests/LibJS/Runtime/async-arrow-function-syntax.jsnew file mode 100644index 00000000000..acb12372f6b--- /dev/null+++ b/Tests/LibJS/Runtime/async-arrow-function-syntax.js@@ -0,0 +1,8 @@+test("yield as the parameter of an async arrow function", () => {+ expect("(function* () { return async yield => 1; })").not.toEval();+ expect("(function* () { return async (yield) => 1; })").not.toEval();+ expect("(function* () { return async \\u0079ield => 1; })").not.toEval();+ expect("(function* () { return function () { return async yield => 1; }; })").toEval();+ expect("(function () { return async yield => 1; })").toEval();+ expect("'use strict'; (function () { return async yield => 1; })").not.toEval();+});