diff --git a/Userland/Libraries/LibJS/Runtime/ScriptFunction.cpp b/Userland/Libraries/LibJS/Runtime/ScriptFunction.cpp index 9447544d40..3a4e83f4cb 100644 --- a/Userland/Libraries/LibJS/Runtime/ScriptFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/ScriptFunction.cpp @@ -151,13 +151,15 @@ Value ScriptFunction::execute_function_body() if (bytecode_interpreter) { prepare_arguments(); - auto block = Bytecode::Generator::generate(m_body); - VERIFY(block); - if constexpr (JS_BYTECODE_DEBUG) { - dbgln("Compiled Bytecode::Block for function '{}':", m_name); - block->dump(); + if (!m_bytecode_block) { + m_bytecode_block = Bytecode::Generator::generate(m_body); + VERIFY(m_bytecode_block); + if constexpr (JS_BYTECODE_DEBUG) { + dbgln("Compiled Bytecode::Block for function '{}':", m_name); + m_bytecode_block->dump(); + } } - return bytecode_interpreter->run(*block); + return bytecode_interpreter->run(*m_bytecode_block); } else { OwnPtr local_interpreter; ast_interpreter = vm.interpreter_if_exists(); diff --git a/Userland/Libraries/LibJS/Runtime/ScriptFunction.h b/Userland/Libraries/LibJS/Runtime/ScriptFunction.h index 3e55cd276d..d866c78878 100644 --- a/Userland/Libraries/LibJS/Runtime/ScriptFunction.h +++ b/Userland/Libraries/LibJS/Runtime/ScriptFunction.h @@ -47,6 +47,7 @@ private: FlyString m_name; NonnullRefPtr m_body; const Vector m_parameters; + OwnPtr m_bytecode_block; ScopeObject* m_parent_scope { nullptr }; i32 m_function_length { 0 }; bool m_is_strict { false };