mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-03 08:52:54 +00:00
LibJS: Don't use null DFS for break/continue statements without a label
This commit is contained in:
parent
761d16141d
commit
78491204d9
Notes:
sideshowbarker
2024-07-17 03:14:39 +09:00
Author: https://github.com/DanShaders
Commit: 78491204d9
Pull-request: https://github.com/SerenityOS/serenity/pull/22926
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/davidot ✅
3 changed files with 17 additions and 17 deletions
|
@ -3397,21 +3397,21 @@ NonnullRefPtr<BreakStatement const> Parser::parse_break_statement()
|
|||
{
|
||||
auto rule_start = push_start();
|
||||
consume(TokenType::Break);
|
||||
DeprecatedFlyString target_label;
|
||||
Optional<DeprecatedFlyString> target_label;
|
||||
if (match(TokenType::Semicolon)) {
|
||||
consume();
|
||||
} else {
|
||||
if (!m_state.current_token.trivia_contains_line_terminator() && match_identifier()) {
|
||||
target_label = consume().value();
|
||||
|
||||
auto label = m_state.labels_in_scope.find(target_label);
|
||||
auto label = m_state.labels_in_scope.find(target_label.value());
|
||||
if (label == m_state.labels_in_scope.end())
|
||||
syntax_error(ByteString::formatted("Label '{}' not found", target_label));
|
||||
syntax_error(ByteString::formatted("Label '{}' not found", target_label.value()));
|
||||
}
|
||||
consume_or_insert_semicolon();
|
||||
}
|
||||
|
||||
if (target_label.is_null() && !m_state.in_break_context)
|
||||
if (!target_label.has_value() && !m_state.in_break_context)
|
||||
syntax_error("Unlabeled 'break' not allowed outside of a loop or switch statement");
|
||||
|
||||
return create_ast_node<BreakStatement>({ m_source_code, rule_start.position(), position() }, target_label);
|
||||
|
@ -3424,7 +3424,7 @@ NonnullRefPtr<ContinueStatement const> Parser::parse_continue_statement()
|
|||
syntax_error("'continue' not allow outside of a loop");
|
||||
|
||||
consume(TokenType::Continue);
|
||||
DeprecatedFlyString target_label;
|
||||
Optional<DeprecatedFlyString> target_label;
|
||||
if (match(TokenType::Semicolon)) {
|
||||
consume();
|
||||
return create_ast_node<ContinueStatement>({ m_source_code, rule_start.position(), position() }, target_label);
|
||||
|
@ -3433,9 +3433,9 @@ NonnullRefPtr<ContinueStatement const> Parser::parse_continue_statement()
|
|||
auto label_position = position();
|
||||
target_label = consume().value();
|
||||
|
||||
auto label = m_state.labels_in_scope.find(target_label);
|
||||
auto label = m_state.labels_in_scope.find(target_label.value());
|
||||
if (label == m_state.labels_in_scope.end())
|
||||
syntax_error(ByteString::formatted("Label '{}' not found or invalid", target_label));
|
||||
syntax_error(ByteString::formatted("Label '{}' not found or invalid", target_label.value()));
|
||||
else
|
||||
label->value = label_position;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue