LibJS: Disallow async generator functions called 'await' or 'yield'

This commit is contained in:
davidot 2021-12-19 20:19:15 +01:00 committed by Linus Groh
parent c8e80690a7
commit 81312986fe
Notes: sideshowbarker 2024-07-17 22:31:20 +09:00
4 changed files with 12 additions and 0 deletions

View file

@ -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");
}

View file

@ -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();

View file

@ -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();

View file

@ -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();