mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 22:38:51 +00:00
LibJS: break or continue with nonexistent label is a syntax error
This commit is contained in:
parent
67f2301150
commit
e8da5f99b1
Notes:
sideshowbarker
2024-07-19 01:57:20 +09:00
Author: https://github.com/mattco98
Commit: e8da5f99b1
Pull-request: https://github.com/SerenityOS/serenity/pull/3724
Issue: https://github.com/SerenityOS/serenity/issues/3714
Reviewed-by: https://github.com/linusg
4 changed files with 32 additions and 5 deletions
|
@ -393,6 +393,11 @@ RefPtr<FunctionExpression> Parser::try_parse_arrow_function_expression(bool expe
|
|||
if (function_length == -1)
|
||||
function_length = parameters.size();
|
||||
|
||||
auto old_labels_in_scope = move(m_parser_state.m_labels_in_scope);
|
||||
ScopeGuard guard([&]() {
|
||||
m_parser_state.m_labels_in_scope = move(old_labels_in_scope);
|
||||
});
|
||||
|
||||
bool is_strict = false;
|
||||
|
||||
auto function_body_result = [&]() -> RefPtr<BlockStatement> {
|
||||
|
@ -440,7 +445,9 @@ RefPtr<Statement> Parser::try_parse_labelled_statement()
|
|||
|
||||
if (!match_statement())
|
||||
return {};
|
||||
m_parser_state.m_labels_in_scope.set(identifier);
|
||||
auto statement = parse_statement();
|
||||
m_parser_state.m_labels_in_scope.remove(identifier);
|
||||
|
||||
statement->set_label(identifier);
|
||||
state_rollback_guard.disarm();
|
||||
|
@ -1318,8 +1325,13 @@ NonnullRefPtr<FunctionNodeType> Parser::parse_function_node(bool check_for_funct
|
|||
if (function_length == -1)
|
||||
function_length = parameters.size();
|
||||
|
||||
bool is_strict = false;
|
||||
TemporaryChange change(m_parser_state.m_in_function_context, true);
|
||||
auto old_labels_in_scope = move(m_parser_state.m_labels_in_scope);
|
||||
ScopeGuard guard([&]() {
|
||||
m_parser_state.m_labels_in_scope = move(old_labels_in_scope);
|
||||
});
|
||||
|
||||
bool is_strict = false;
|
||||
auto body = parse_block_statement(is_strict);
|
||||
body->add_variables(m_parser_state.m_var_scopes.last());
|
||||
body->add_functions(m_parser_state.m_function_scopes.last());
|
||||
|
@ -1395,8 +1407,11 @@ NonnullRefPtr<BreakStatement> Parser::parse_break_statement()
|
|||
if (match(TokenType::Semicolon)) {
|
||||
consume();
|
||||
} else {
|
||||
if (match(TokenType::Identifier) && !m_parser_state.m_current_token.trivia().contains('\n'))
|
||||
if (match(TokenType::Identifier) && !m_parser_state.m_current_token.trivia().contains('\n')) {
|
||||
target_label = consume().value();
|
||||
if (!m_parser_state.m_labels_in_scope.contains(target_label))
|
||||
syntax_error(String::formatted("Label '{}' not found", target_label));
|
||||
}
|
||||
consume_or_insert_semicolon();
|
||||
}
|
||||
|
||||
|
@ -1417,8 +1432,11 @@ NonnullRefPtr<ContinueStatement> Parser::parse_continue_statement()
|
|||
consume();
|
||||
return create_ast_node<ContinueStatement>(target_label);
|
||||
}
|
||||
if (match(TokenType::Identifier) && !m_parser_state.m_current_token.trivia().contains('\n'))
|
||||
if (match(TokenType::Identifier) && !m_parser_state.m_current_token.trivia().contains('\n')) {
|
||||
target_label = consume().value();
|
||||
if (!m_parser_state.m_labels_in_scope.contains(target_label))
|
||||
syntax_error(String::formatted("Label '{}' not found", target_label));
|
||||
}
|
||||
consume_or_insert_semicolon();
|
||||
return create_ast_node<ContinueStatement>(target_label);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue