Browse Source

LibWasm: Execute the start function, if one exists

Ali Mohammad Pur 4 years ago
parent
commit
3402381d7a
1 changed files with 8 additions and 3 deletions
  1. 8 3
      Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp

+ 8 - 3
Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp

@@ -170,9 +170,14 @@ InstantiationResult AbstractMachine::instantiate(const Module& module, Vector<Ex
         }
     });
 
-    module.for_each_section_of_type<StartSection>([&](auto&) {
-        instantiation_result = InstantiationError { "Start section not yet implemented" };
-        // FIXME: Invoke the start function.
+    module.for_each_section_of_type<StartSection>([&](const StartSection& section) {
+        auto& functions = m_module_instance.functions();
+        auto index = section.function().index();
+        if (functions.size() <= index.value()) {
+            instantiation_result = InstantiationError { String::formatted("Start section function referenced invalid index {} of max {} entries", index.value(), functions.size()) };
+            return;
+        }
+        invoke(functions[index.value()], {});
     });
 
     return instantiation_result.value_or({});