mirror of
https://github.com/RGBCube/serenity
synced 2025-07-03 05:32:13 +00:00
LibJS: Implement "throw"
You can now throw an expression to the nearest catcher! :^) To support throwing arbitrary values, I added an Exception class that sits as a wrapper around whatever is thrown. In the future it will be a logical place to store a call stack.
This commit is contained in:
parent
db024a9cb1
commit
faddf3a1db
13 changed files with 160 additions and 7 deletions
|
@ -197,6 +197,8 @@ NonnullRefPtr<Statement> Parser::parse_statement()
|
|||
return parse_for_statement();
|
||||
case TokenType::If:
|
||||
return parse_if_statement();
|
||||
case TokenType::Throw:
|
||||
return parse_throw_statement();
|
||||
case TokenType::Try:
|
||||
return parse_try_statement();
|
||||
default:
|
||||
|
@ -520,6 +522,12 @@ NonnullRefPtr<VariableDeclaration> Parser::parse_variable_declaration()
|
|||
return create_ast_node<VariableDeclaration>(create_ast_node<Identifier>(name), move(initializer), declaration_type);
|
||||
}
|
||||
|
||||
NonnullRefPtr<ThrowStatement> Parser::parse_throw_statement()
|
||||
{
|
||||
consume(TokenType::Throw);
|
||||
return create_ast_node<ThrowStatement>(parse_expression(0));
|
||||
}
|
||||
|
||||
NonnullRefPtr<TryStatement> Parser::parse_try_statement()
|
||||
{
|
||||
consume(TokenType::Try);
|
||||
|
@ -700,6 +708,7 @@ bool Parser::match_statement() const
|
|||
|| type == TokenType::Delete
|
||||
|| type == TokenType::Do
|
||||
|| type == TokenType::If
|
||||
|| type == TokenType::Throw
|
||||
|| type == TokenType::Try
|
||||
|| type == TokenType::While
|
||||
|| type == TokenType::For
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue