1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:47:34 +00:00

LibWasm: Make the instantiation process produce an OwnPtr

Managing the instantiated modules becomes a pain if they're on the
stack, since an instantiated module will eventually reference itself.
To make using this simpler, just avoid copying the instance.
This commit is contained in:
Ali Mohammad Pur 2021-05-11 04:44:59 +04:30 committed by Linus Groh
parent efb106069b
commit 3283c8a495
5 changed files with 15 additions and 20 deletions

View file

@ -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) {