mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-28 14:02:51 +00:00
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:
parent
bc67264453
commit
117ca843bd
Notes:
sideshowbarker
2024-07-17 18:42:38 +09:00
Author: https://github.com/alimpfard
Commit: 117ca843bd
Pull-request: https://github.com/SerenityOS/serenity/pull/12548
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/linusg
1 changed files with 6 additions and 3 deletions
|
@ -35,20 +35,23 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyMemoryConstructor::construct(Funct
|
||||||
auto initial_value = TRY(descriptor->get("initial"));
|
auto initial_value = TRY(descriptor->get("initial"));
|
||||||
auto maximum_value = TRY(descriptor->get("maximum"));
|
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");
|
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;
|
Optional<u32> maximum;
|
||||||
|
|
||||||
if (!maximum_value.is_empty())
|
if (!maximum_value.is_undefined())
|
||||||
maximum = TRY(maximum_value.to_u32(global_object));
|
maximum = TRY(maximum_value.to_u32(global_object));
|
||||||
|
|
||||||
auto address = WebAssemblyObject::s_abstract_machine.store().allocate(Wasm::MemoryType { Wasm::Limits { initial, maximum } });
|
auto address = WebAssemblyObject::s_abstract_machine.store().allocate(Wasm::MemoryType { Wasm::Limits { initial, maximum } });
|
||||||
if (!address.has_value())
|
if (!address.has_value())
|
||||||
return vm.throw_completion<JS::TypeError>(global_object, "Wasm Memory allocation failed");
|
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);
|
return vm.heap().allocate<WebAssemblyMemoryObject>(global_object, global_object, *address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue