mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:17:44 +00:00
LibJS: Disallow async generator functions called 'await' or 'yield'
This commit is contained in:
parent
c8e80690a7
commit
81312986fe
4 changed files with 12 additions and 0 deletions
|
@ -2476,6 +2476,9 @@ NonnullRefPtr<FunctionNodeType> Parser::parse_function_node(u8 parse_options)
|
||||||
|
|
||||||
check_identifier_name_for_assignment_validity(name);
|
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)
|
if (m_state.in_class_static_init_block && name == "await"sv)
|
||||||
syntax_error("'await' is a reserved word");
|
syntax_error("'await' is a reserved word");
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,9 @@ describe("parsing freestanding async functions", () => {
|
||||||
// Although it does not create an async function it is valid.
|
// Although it does not create an async function it is valid.
|
||||||
expect(`async
|
expect(`async
|
||||||
function foo() {}`).toEval();
|
function foo() {}`).toEval();
|
||||||
|
|
||||||
|
expect(`async function await() {}`).toEval();
|
||||||
|
expect(`async function yield() {}`).toEval();
|
||||||
});
|
});
|
||||||
test("await expression", () => {
|
test("await expression", () => {
|
||||||
expect(`async function foo() { await bar(); }`).toEval();
|
expect(`async function foo() { await bar(); }`).toEval();
|
||||||
|
|
|
@ -4,6 +4,9 @@ describe("parsing freestanding generators", () => {
|
||||||
expect(`async function *foo() {}`).toEval();
|
expect(`async function *foo() {}`).toEval();
|
||||||
expect(`async function
|
expect(`async function
|
||||||
*foo() {}`).toEval();
|
*foo() {}`).toEval();
|
||||||
|
|
||||||
|
expect(`async function *await() {}`).not.toEval();
|
||||||
|
expect(`async function *yield() {}`).not.toEval();
|
||||||
});
|
});
|
||||||
test("yield & await expression", () => {
|
test("yield & await expression", () => {
|
||||||
expect(`async function* foo() { yield; await 1; }`).toEval();
|
expect(`async function* foo() { yield; await 1; }`).toEval();
|
||||||
|
|
|
@ -4,6 +4,9 @@ describe("parsing freestanding generators", () => {
|
||||||
expect(`function *foo() {}`).toEval();
|
expect(`function *foo() {}`).toEval();
|
||||||
expect(`function
|
expect(`function
|
||||||
*foo() {}`).toEval();
|
*foo() {}`).toEval();
|
||||||
|
|
||||||
|
expect(`function *await() {}`).toEval();
|
||||||
|
expect(`function *yield() {}`).toEval();
|
||||||
});
|
});
|
||||||
test("yield expression", () => {
|
test("yield expression", () => {
|
||||||
expect(`function* foo() { yield; }`).toEval();
|
expect(`function* foo() { yield; }`).toEval();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue