1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:38:12 +00:00

LibJS: Implement basic exception throwing

You can now throw exceptions by calling Interpreter::throw_exception().
Anyone who calls ASTNode::execute() needs to check afterwards if the
Interpreter now has an exception(), and if so, stop what they're doing
and simply return.

When catching an exception, we'll first execute the CatchClause node
if present. After that, we'll execute the finalizer block if present.

This is unlikely to be completely correct, but it's a start! :^)
This commit is contained in:
Andreas Kling 2020-03-24 14:37:39 +01:00
parent c33d4aefc3
commit 343e224aa8
11 changed files with 257 additions and 5 deletions

View file

@ -40,6 +40,7 @@ enum class ScopeType {
None,
Function,
Block,
Try,
};
struct Variable {
@ -104,6 +105,11 @@ public:
Object* string_prototype() { return m_string_prototype; }
Object* object_prototype() { return m_object_prototype; }
Object* array_prototype() { return m_array_prototype; }
Object* error_prototype() { return m_error_prototype; }
Error* exception() { return m_exception; }
void clear_exception() { m_exception = nullptr; }
Value throw_exception(Error*);
private:
Heap m_heap;
@ -115,6 +121,9 @@ private:
Object* m_string_prototype { nullptr };
Object* m_object_prototype { nullptr };
Object* m_array_prototype { nullptr };
Object* m_error_prototype { nullptr };
Error* m_exception { nullptr };
ScopeType m_unwind_until { ScopeType::None };
};