mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Disallow async generator functions called 'await' or 'yield'
This commit is contained in:
parent
c8e80690a7
commit
81312986fe
Notes:
sideshowbarker
2024-07-17 22:31:20 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/81312986fe0 Pull-request: https://github.com/SerenityOS/serenity/pull/11316 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/linusg ✅
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);
|
||||
|
||||
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");
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue