LibWeb: Don't check for get().is_empty() in WebAssemblyMemoryConstructor

Object.get() does not return empty values, this was causing the
constructed memory object to have a maximum of 0, which failed silently
in the constructor.
This commit is contained in:
Ali Mohammad Pur 2022-02-15 03:04:10 +03:30 committed by Ali Mohammad Pur
parent bc67264453
commit 117ca843bd
Notes: sideshowbarker 2024-07-17 18:42:38 +09:00

View file

@ -35,20 +35,23 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyMemoryConstructor::construct(Funct
auto initial_value = TRY(descriptor->get("initial"));
auto maximum_value = TRY(descriptor->get("maximum"));
if (initial_value.is_empty())
if (!initial_value.is_number())
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "Number");
auto initial = TRY(initial_value.to_u32(global_object));
u32 initial = TRY(initial_value.to_u32(global_object));
Optional<u32> maximum;
if (!maximum_value.is_empty())
if (!maximum_value.is_undefined())
maximum = TRY(maximum_value.to_u32(global_object));
auto address = WebAssemblyObject::s_abstract_machine.store().allocate(Wasm::MemoryType { Wasm::Limits { initial, maximum } });
if (!address.has_value())
return vm.throw_completion<JS::TypeError>(global_object, "Wasm Memory allocation failed");
if (!WebAssemblyObject::s_abstract_machine.store().get(*address)->grow(initial))
return vm.throw_completion<JS::TypeError>(global_object, String::formatted("Wasm Memory grow failed: {}", initial));
return vm.heap().allocate<WebAssemblyMemoryObject>(global_object, global_object, *address);
}