diff options
-rw-r--r-- | Tests/LibWasm/test-wasm.cpp | 11 | ||||
-rw-r--r-- | Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibWasm/Types.h | 6 | ||||
-rw-r--r-- | Userland/Utilities/wasm.cpp | 4 |
5 files changed, 15 insertions, 20 deletions
diff --git a/Tests/LibWasm/test-wasm.cpp b/Tests/LibWasm/test-wasm.cpp index 14fff623f2..0ecd294ec6 100644 --- a/Tests/LibWasm/test-wasm.cpp +++ b/Tests/LibWasm/test-wasm.cpp @@ -60,7 +60,7 @@ private: static Wasm::AbstractMachine m_machine; Optional<Wasm::Module> m_module; - Optional<Wasm::ModuleInstance> m_module_instance; + OwnPtr<Wasm::ModuleInstance> m_module_instance; }; Wasm::AbstractMachine WebAssemblyModule::m_machine; @@ -149,15 +149,6 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::wasm_invoke) auto address = static_cast<unsigned long>(vm.argument(0).to_double(global_object)); if (vm.exception()) return {}; - auto this_value = vm.this_value(global_object); - auto object = this_value.to_object(global_object); - if (vm.exception()) - return {}; - if (!object || !is<WebAssemblyModule>(object)) { - vm.throw_exception<JS::TypeError>(global_object, "Not a WebAssemblyModule"); - return {}; - } - auto instance = static_cast<WebAssemblyModule*>(object); Wasm::FunctionAddress function_address { address }; auto function_instance = WebAssemblyModule::machine().store().get(function_address); if (!function_instance) { diff --git a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp index 9383927c9a..6179e1b3b2 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp @@ -85,7 +85,8 @@ GlobalInstance* Store::get(GlobalAddress address) InstantiationResult AbstractMachine::instantiate(const Module& module, Vector<ExternValue> externs) { - ModuleInstance main_module_instance; + auto main_module_instance_pointer = make<ModuleInstance>(); + auto& main_module_instance = *main_module_instance_pointer; Optional<InstantiationResult> instantiation_result; module.for_each_section_of_type<TypeSection>([&](const TypeSection& section) { @@ -181,7 +182,10 @@ InstantiationResult AbstractMachine::instantiate(const Module& module, Vector<Ex invoke(functions[index.value()], {}); }); - return instantiation_result.value_or(move(main_module_instance)); + if (instantiation_result.has_value()) + return instantiation_result.release_value(); + + return InstantiationResult { move(main_module_instance_pointer) }; } Optional<InstantiationError> AbstractMachine::allocate_all(const Module& module, ModuleInstance& module_instance, Vector<ExternValue>& externs, Vector<Value>& global_values) diff --git a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h index 1f06b76f79..aa480ae70d 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h +++ b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h @@ -219,7 +219,7 @@ public: auto& code() const { return m_code; } private: - const FunctionType& m_type; + FunctionType m_type; const ModuleInstance& m_module; const Module::Function& m_code; }; @@ -237,7 +237,7 @@ public: private: FlatPtr m_ptr { 0 }; - const FunctionType& m_type; + FunctionType m_type; }; using FunctionInstance = Variant<WasmFunction, HostFunction>; @@ -418,7 +418,7 @@ private: Vector<EntryType> m_data; }; -using InstantiationResult = AK::Result<ModuleInstance, InstantiationError>; +using InstantiationResult = AK::Result<NonnullOwnPtr<ModuleInstance>, InstantiationError>; class AbstractMachine { public: diff --git a/Userland/Libraries/LibWasm/Types.h b/Userland/Libraries/LibWasm/Types.h index 4b834d7465..9906035715 100644 --- a/Userland/Libraries/LibWasm/Types.h +++ b/Userland/Libraries/LibWasm/Types.h @@ -955,10 +955,10 @@ class Module { public: class Function { public: - explicit Function(TypeIndex type, Vector<ValueType> local_types, const Expression& body) + explicit Function(TypeIndex type, Vector<ValueType> local_types, Expression body) : m_type(type) , m_local_types(move(local_types)) - , m_body(body) + , m_body(move(body)) { } @@ -969,7 +969,7 @@ public: private: TypeIndex m_type; Vector<ValueType> m_local_types; - const Expression& m_body; + Expression m_body; }; using AnySection = Variant< diff --git a/Userland/Utilities/wasm.cpp b/Userland/Utilities/wasm.cpp index eed9f3ccd0..2100be47a8 100644 --- a/Userland/Utilities/wasm.cpp +++ b/Userland/Utilities/wasm.cpp @@ -91,7 +91,7 @@ int main(int argc, char* argv[]) }; if (print) { // Now, let's dump the functions! - for (auto& address : module_instance.functions()) { + for (auto& address : module_instance->functions()) { print_func(address); } } @@ -99,7 +99,7 @@ int main(int argc, char* argv[]) if (!exported_function_to_execute.is_empty()) { Optional<Wasm::FunctionAddress> run_address; Vector<Wasm::Value> values; - for (auto& entry : module_instance.exports()) { + for (auto& entry : module_instance->exports()) { if (entry.name() == exported_function_to_execute) { if (auto addr = entry.value().get_pointer<Wasm::FunctionAddress>()) run_address = *addr; |