mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Allow 'yield' and 'await' as function expression names
The spec says so, and test262 checks for this too.
This commit is contained in:
parent
a6fe27423a
commit
2e00731ddb
Notes:
sideshowbarker
2024-07-18 11:07:33 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/2e00731ddb6 Pull-request: https://github.com/SerenityOS/serenity/pull/8384
2 changed files with 8 additions and 0 deletions
|
@ -1417,6 +1417,7 @@ NonnullRefPtr<FunctionNodeType> Parser::parse_function_node(u8 parse_options)
|
|||
|
||||
ScopePusher scope(*this, ScopePusher::Var | ScopePusher::Function);
|
||||
|
||||
constexpr auto is_function_expression = IsSame<FunctionNodeType, FunctionExpression>;
|
||||
auto is_generator = (parse_options & FunctionNodeParseOptions::IsGeneratorFunction) != 0;
|
||||
String name;
|
||||
if (parse_options & FunctionNodeParseOptions::CheckForFunctionAndName) {
|
||||
|
@ -1431,6 +1432,8 @@ NonnullRefPtr<FunctionNodeType> Parser::parse_function_node(u8 parse_options)
|
|||
|
||||
if (FunctionNodeType::must_have_name() || match(TokenType::Identifier))
|
||||
name = consume(TokenType::Identifier).value();
|
||||
else if (is_function_expression && (match(TokenType::Yield) || match(TokenType::Await)))
|
||||
name = consume().value();
|
||||
}
|
||||
consume(TokenType::ParenOpen);
|
||||
i32 function_length = -1;
|
||||
|
|
|
@ -49,3 +49,8 @@ describe("parsing classes with generator methods", () => {
|
|||
expect(`class Foo { *constructor() { yield 42; } }`).not.toEval();
|
||||
});
|
||||
});
|
||||
|
||||
test("function expression names equal to 'yield'", () => {
|
||||
expect(`function *foo() { (function yield() {}); }`).toEval();
|
||||
expect(`function *foo() { function yield() {} }`).not.toEval();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue