From 39cfb64269998e926aadc87f852c269f516614d8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 26 Sep 2023 17:14:59 +0200 Subject: [PATCH] LibJS: Return early from Interpreter on unhandled exception If we don't have a local unwind context to handle the exception, we can just return right away. This allows us to remove one check from the inner loop. --- Userland/Libraries/LibJS/Bytecode/Interpreter.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index ffee05c712..44cd8e7874 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -173,14 +173,15 @@ void Interpreter::run_bytecode() while (!pc.at_end()) { auto& instruction = *pc; + auto ran_or_error = instruction.execute(*this); if (ran_or_error.is_error()) [[unlikely]] { reg(Register::exception()) = *ran_or_error.throw_completion().value(); if (unwind_contexts().is_empty()) - break; + return; auto& unwind_context = unwind_contexts().last(); if (unwind_context.executable != m_current_executable) - break; + return; if (unwind_context.handler && !unwind_context.handler_called) { vm().running_execution_context().lexical_environment = unwind_context.lexical_environment; m_current_block = unwind_context.handler; @@ -234,9 +235,6 @@ void Interpreter::run_bytecode() if (pc.at_end()) break; - if (!reg(Register::exception()).is_empty()) - break; - if (will_return) break; }