summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authordavidot <davidot@serenityos.org>2021-12-19 20:19:15 +0100
committerLinus Groh <mail@linusgroh.de>2021-12-21 14:04:23 +0100
commit81312986fe07496e3d35e1d7d10d20d9aba8d1fb (patch)
treeecebf3e078790ef99e0a9f293373ba9559d1fd0f /Userland/Libraries
parentc8e80690a7dacc305631dcc402254238ef31dc88 (diff)
downloadserenity-81312986fe07496e3d35e1d7d10d20d9aba8d1fb.zip
LibJS: Disallow async generator functions called 'await' or 'yield'
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Parser.cpp3
-rw-r--r--Userland/Libraries/LibJS/Tests/syntax/async-await.js3
-rw-r--r--Userland/Libraries/LibJS/Tests/syntax/async-generators.js3
-rw-r--r--Userland/Libraries/LibJS/Tests/syntax/generators.js3
4 files changed, 12 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp
index 30749baa65..91e643e8fc 100644
--- a/Userland/Libraries/LibJS/Parser.cpp
+++ b/Userland/Libraries/LibJS/Parser.cpp
@@ -2476,6 +2476,9 @@ NonnullRefPtr<FunctionNodeType> Parser::parse_function_node(u8 parse_options)
check_identifier_name_for_assignment_validity(name);
+ if (function_kind == FunctionKind::AsyncGenerator && (name == "await"sv || name == "yield"sv))
+ syntax_error(String::formatted("async generator function is not allowed to be called '{}'", name));
+
if (m_state.in_class_static_init_block && name == "await"sv)
syntax_error("'await' is a reserved word");
}
diff --git a/Userland/Libraries/LibJS/Tests/syntax/async-await.js b/Userland/Libraries/LibJS/Tests/syntax/async-await.js
index 652f0e810e..d86c9eea8e 100644
--- a/Userland/Libraries/LibJS/Tests/syntax/async-await.js
+++ b/Userland/Libraries/LibJS/Tests/syntax/async-await.js
@@ -4,6 +4,9 @@ describe("parsing freestanding async functions", () => {
// Although it does not create an async function it is valid.
expect(`async
function foo() {}`).toEval();
+
+ expect(`async function await() {}`).toEval();
+ expect(`async function yield() {}`).toEval();
});
test("await expression", () => {
expect(`async function foo() { await bar(); }`).toEval();
diff --git a/Userland/Libraries/LibJS/Tests/syntax/async-generators.js b/Userland/Libraries/LibJS/Tests/syntax/async-generators.js
index 68c9550dbb..ce30721efd 100644
--- a/Userland/Libraries/LibJS/Tests/syntax/async-generators.js
+++ b/Userland/Libraries/LibJS/Tests/syntax/async-generators.js
@@ -4,6 +4,9 @@ describe("parsing freestanding generators", () => {
expect(`async function *foo() {}`).toEval();
expect(`async function
*foo() {}`).toEval();
+
+ expect(`async function *await() {}`).not.toEval();
+ expect(`async function *yield() {}`).not.toEval();
});
test("yield & await expression", () => {
expect(`async function* foo() { yield; await 1; }`).toEval();
diff --git a/Userland/Libraries/LibJS/Tests/syntax/generators.js b/Userland/Libraries/LibJS/Tests/syntax/generators.js
index c70bc6cf72..010a1c78e5 100644
--- a/Userland/Libraries/LibJS/Tests/syntax/generators.js
+++ b/Userland/Libraries/LibJS/Tests/syntax/generators.js
@@ -4,6 +4,9 @@ describe("parsing freestanding generators", () => {
expect(`function *foo() {}`).toEval();
expect(`function
*foo() {}`).toEval();
+
+ expect(`function *await() {}`).toEval();
+ expect(`function *yield() {}`).toEval();
});
test("yield expression", () => {
expect(`function* foo() { yield; }`).toEval();