diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp index 027c138919..153e0433c9 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp @@ -317,18 +317,19 @@ Optional to_webassembly_value(JS::Value value, const Wasm::ValueTyp JS::NativeFunction* create_native_function(Wasm::FunctionAddress address, String name, JS::GlobalObject& global_object) { + Optional type; + WebAssemblyObject::s_abstract_machine.store().get(address)->visit([&](const auto& value) { type = value.type(); }); // FIXME: Cache these. return JS::NativeFunction::create( global_object, name, - [address](JS::VM& vm, JS::GlobalObject& global_object) -> JS::Value { + [address, type = type.release_value()](JS::VM& vm, JS::GlobalObject& global_object) -> JS::Value { Vector values; - Optional type; - WebAssemblyObject::s_abstract_machine.store().get(address)->visit([&](const auto& value) { type = value.type(); }); + values.ensure_capacity(type.parameters().size()); // Grab as many values as needed and convert them. size_t index = 0; - for (auto& type : type.value().parameters()) { + for (auto& type : type.parameters()) { auto result = to_webassembly_value(vm.argument(index++), type, global_object); if (result.has_value()) values.append(result.release_value());