diff --git a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp index f11b0277dc..fb00605619 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp @@ -162,11 +162,14 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector module_functions; + module_functions.ensure_capacity(module.functions().size()); + for (auto& func : module.functions()) { auto address = m_store.allocate(main_module_instance, func); VERIFY(address.has_value()); auxiliary_instance.functions().append(*address); - main_module_instance.functions().append(*address); + module_functions.append(*address); } BytecodeInterpreter interpreter(m_stack_info); @@ -193,7 +196,7 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector([&](ElementSection const& section) { @@ -393,7 +396,7 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector AbstractMachine::allocate_all_initial_phase(Module const& module, ModuleInstance& module_instance, Vector& externs, Vector& global_values) +Optional AbstractMachine::allocate_all_initial_phase(Module const& module, ModuleInstance& module_instance, Vector& externs, Vector& global_values, Vector& own_functions) { Optional result; @@ -405,6 +408,8 @@ Optional AbstractMachine::allocate_all_initial_phase(Module [&](GlobalAddress const& address) { module_instance.globals().append(address); }); } + module_instance.functions().extend(own_functions); + // FIXME: What if this fails? module.for_each_section_of_type([&](TableSection const& section) { diff --git a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h index bc1166bd42..f6ac5f93ad 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h +++ b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h @@ -623,7 +623,7 @@ public: void enable_instruction_count_limit() { m_should_limit_instruction_count = true; } private: - Optional allocate_all_initial_phase(Module const&, ModuleInstance&, Vector&, Vector& global_values); + Optional allocate_all_initial_phase(Module const&, ModuleInstance&, Vector&, Vector& global_values, Vector& own_functions); Optional allocate_all_final_phase(Module const&, ModuleInstance&, Vector>& elements); Store m_store; StackInfo m_stack_info;