mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Parse labels in continue and break statements
This commit is contained in:
parent
10bf4ba3dc
commit
03615a7872
Notes:
sideshowbarker
2024-07-19 05:59:34 +09:00
Author: https://github.com/mattco98 Commit: https://github.com/SerenityOS/serenity/commit/03615a78728 Pull-request: https://github.com/SerenityOS/serenity/pull/2434 Reviewed-by: https://github.com/sunverwerth
2 changed files with 32 additions and 6 deletions
|
@ -1048,22 +1048,36 @@ private:
|
|||
|
||||
class BreakStatement final : public Statement {
|
||||
public:
|
||||
BreakStatement() { }
|
||||
BreakStatement(FlyString target_label)
|
||||
: m_target_label(target_label)
|
||||
{
|
||||
}
|
||||
|
||||
virtual Value execute(Interpreter&) const override;
|
||||
|
||||
const FlyString& target_label() const { return m_target_label; }
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "BreakStatement"; }
|
||||
|
||||
FlyString m_target_label;
|
||||
};
|
||||
|
||||
class ContinueStatement final : public Statement {
|
||||
public:
|
||||
ContinueStatement() { }
|
||||
ContinueStatement(FlyString target_label)
|
||||
: m_target_label(target_label)
|
||||
{
|
||||
}
|
||||
|
||||
virtual Value execute(Interpreter&) const override;
|
||||
|
||||
const FlyString& target_label() const { return m_target_label; }
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "ContinueStatement"; }
|
||||
|
||||
FlyString m_target_label;
|
||||
};
|
||||
|
||||
class DebuggerStatement final : public Statement {
|
||||
|
|
|
@ -1112,17 +1112,29 @@ NonnullRefPtr<ThrowStatement> Parser::parse_throw_statement()
|
|||
NonnullRefPtr<BreakStatement> Parser::parse_break_statement()
|
||||
{
|
||||
consume(TokenType::Break);
|
||||
FlyString target_label;
|
||||
if (match(TokenType::Semicolon)) {
|
||||
consume();
|
||||
return create_ast_node<BreakStatement>(target_label);
|
||||
}
|
||||
if (match_identifier_name() && !m_parser_state.m_current_token.trivia().contains('\n'))
|
||||
target_label = consume().value();
|
||||
consume_or_insert_semicolon();
|
||||
// FIXME: Handle labels. When fixing this, take care to correctly implement semicolon insertion
|
||||
return create_ast_node<BreakStatement>();
|
||||
return create_ast_node<BreakStatement>(target_label);
|
||||
}
|
||||
|
||||
NonnullRefPtr<ContinueStatement> Parser::parse_continue_statement()
|
||||
{
|
||||
consume(TokenType::Continue);
|
||||
FlyString target_label;
|
||||
if (match(TokenType::Semicolon)) {
|
||||
consume();
|
||||
return create_ast_node<ContinueStatement>(target_label);
|
||||
}
|
||||
if (match_identifier_name() && !m_parser_state.m_current_token.trivia().contains('\n'))
|
||||
target_label = consume().value();
|
||||
consume_or_insert_semicolon();
|
||||
// FIXME: Handle labels. When fixing this, take care to correctly implement semicolon insertion
|
||||
return create_ast_node<ContinueStatement>();
|
||||
return create_ast_node<ContinueStatement>(target_label);
|
||||
}
|
||||
|
||||
NonnullRefPtr<ConditionalExpression> Parser::parse_conditional_expression(NonnullRefPtr<Expression> test)
|
||||
|
|
Loading…
Reference in a new issue