mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 02:27:35 +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:
parent
efb106069b
commit
3283c8a495
5 changed files with 15 additions and 20 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue