mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:47:36 +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
|
@ -675,4 +675,22 @@ private:
|
|||
RefPtr<BlockStatement> m_finalizer;
|
||||
};
|
||||
|
||||
class ThrowStatement final : public Statement {
|
||||
public:
|
||||
explicit ThrowStatement(NonnullRefPtr<Expression> argument)
|
||||
: m_argument(move(argument))
|
||||
{
|
||||
}
|
||||
|
||||
const Expression& argument() const { return m_argument; }
|
||||
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Value execute(Interpreter&) const override;
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "ThrowStatement"; }
|
||||
|
||||
NonnullRefPtr<Expression> m_argument;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue