diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 65b28af165..a99af164ae 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -2006,10 +2006,8 @@ Value TryStatement::execute(Interpreter& interpreter, GlobalObject& global_objec // If we previously had an exception and the finalizer didn't // throw a new one, restore the old one. - // FIXME: This will print debug output in throw_exception() for - // a second time with m_should_log_exceptions enabled. if (previous_exception && !interpreter.exception()) - interpreter.vm().throw_exception(previous_exception); + interpreter.vm().set_exception(*previous_exception); } } diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index 8b1a5c41a2..e2e5aa05af 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -290,10 +290,10 @@ Value VM::construct(Function& function, Function& new_target, Optionalvalue(); + auto value = exception.value(); if (value.is_object()) { auto& object = value.as_object(); auto name = object.get_without_side_effects(names.name).value_or(js_undefined()); @@ -317,7 +317,7 @@ void VM::throw_exception(Exception* exception) } } - m_exception = exception; + set_exception(exception); unwind(ScopeType::Try); } diff --git a/Userland/Libraries/LibJS/Runtime/VM.h b/Userland/Libraries/LibJS/Runtime/VM.h index 702ec9580a..0a870b9b5a 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.h +++ b/Userland/Libraries/LibJS/Runtime/VM.h @@ -86,11 +86,8 @@ public: void push_interpreter(Interpreter&); void pop_interpreter(Interpreter&); - Exception* exception() - { - return m_exception; - } - + Exception* exception() { return m_exception; } + void set_exception(Exception& exception) { m_exception = &exception; } void clear_exception() { m_exception = nullptr; } class InterpreterExecutionScope { @@ -207,10 +204,10 @@ public: return throw_exception(global_object, T::create(global_object, forward(args)...)); } - void throw_exception(Exception*); + void throw_exception(Exception&); void throw_exception(GlobalObject& global_object, Value value) { - return throw_exception(heap().allocate(global_object, value)); + return throw_exception(*heap().allocate(global_object, value)); } template