mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-28 20:29:42 +00:00
LibJS: Allow try statement with only finally clause
This was a regression introduced by 9ffe45b - a TryStatement without 'catch' clause *is* allowed, if it has a 'finally' clause. It is now checked properly that at least one of both is present.
This commit is contained in:
committed by
Andreas Kling
parent
aa115fe27b
commit
d6f8c52245
@@ -1443,7 +1443,10 @@ NonnullRefPtr<TryStatement> Parser::parse_try_statement()
|
||||
consume(TokenType::Try);
|
||||
|
||||
auto block = parse_block_statement();
|
||||
auto handler = parse_catch_clause();
|
||||
|
||||
RefPtr<CatchClause> handler;
|
||||
if (match(TokenType::Catch))
|
||||
handler = parse_catch_clause();
|
||||
|
||||
RefPtr<BlockStatement> finalizer;
|
||||
if (match(TokenType::Finally)) {
|
||||
@@ -1451,6 +1454,9 @@ NonnullRefPtr<TryStatement> Parser::parse_try_statement()
|
||||
finalizer = parse_block_statement();
|
||||
}
|
||||
|
||||
if (!handler && !finalizer)
|
||||
syntax_error("try statement must have a 'catch' or 'finally' clause");
|
||||
|
||||
return create_ast_node<TryStatement>(move(block), move(handler), move(finalizer));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user