From 845f2826aa0f558116bf57ade4ec29cded1fd185 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 7 Jun 2021 13:57:02 +0200 Subject: [PATCH] LibJS: Reset Bytecode::Interpreter's m_return_value when leaving run() Otherwise it will cause complete unwind since all parent run() loops will see the same m_return_value being non-empty and break out. --- Userland/Libraries/LibJS/Bytecode/Interpreter.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index 4d63cafeb7b..ad09cc4fd39 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -77,16 +77,17 @@ Value Interpreter::run(Bytecode::Block const& block) m_register_windows.take_last(); - m_return_value = m_return_value.value_or(js_undefined()); + auto return_value = m_return_value.value_or(js_undefined()); + m_return_value = {}; // NOTE: The return value from a called function is put into $0 in the caller context. if (!m_register_windows.is_empty()) - m_register_windows.last()[0] = m_return_value; + m_register_windows.last()[0] = return_value; if (vm().call_stack().size() == 1) vm().pop_call_frame(); - return m_return_value; + return return_value; } }