From e730ada07d6b68fdc4e76f1e9028a06f0c8f3c40 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 15 Jan 2022 17:07:51 +0100 Subject: [PATCH] LibJS: Consume curly braces outside of Parser::parse_function_body() The curly braces are not part of the FunctionBody production. This becomes relevant when parsing a standalone function body as per the spec in the CreateDynamicFunction AO. --- Userland/Libraries/LibJS/Parser.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 2ac76f72738..29082582893 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -777,7 +777,10 @@ RefPtr Parser::try_parse_arrow_function_expression(bool expe if (match(TokenType::CurlyOpen)) { // Parse a function body with statements - return parse_function_body(parameters, function_kind, contains_direct_call_to_eval); + consume(TokenType::CurlyOpen); + auto body = parse_function_body(parameters, function_kind, contains_direct_call_to_eval); + consume(TokenType::CurlyClose); + return body; } if (match_expression()) { // Parse a function body which returns a single expression @@ -2366,7 +2369,6 @@ NonnullRefPtr Parser::parse_function_body(Vector({ m_state.current_token.filename(), rule_start.position(), position() }); ScopePusher function_scope = ScopePusher::function_scope(*this, function_body, parameters); // FIXME <- - consume(TokenType::CurlyOpen); auto has_use_strict = parse_directive(function_body); bool previous_strict_mode = m_state.strict_mode; if (has_use_strict) { @@ -2380,6 +2382,11 @@ NonnullRefPtr Parser::parse_function_body(Vectorin_strict_mode() || function_kind != FunctionKind::Normal) { Vector parameter_names; @@ -2421,7 +2428,6 @@ NonnullRefPtr Parser::parse_function_body(Vector Parser::parse_function_node(u8 parse_options) m_state.labels_in_scope = move(old_labels_in_scope); }); + consume(TokenType::CurlyOpen); bool contains_direct_call_to_eval = false; auto body = parse_function_body(parameters, function_kind, contains_direct_call_to_eval); + consume(TokenType::CurlyClose); auto has_strict_directive = body->in_strict_mode();