LibWeb: Implement resizable ArrayBuffers for Wasm memories

This commit adds the toResizableBuffer() and toFixedLengthBuffer()
methods to WebAssembly.Memory. This includes the necessary hook to
HostResizeArrayBuffer. Some modifications to function signatures in
LibWeb/WebAssembly/Memory.h were also made (changing the return type
from WebIDL::ExceptionOr to JS::ThrowCompletionOr) to allow the use of
some code in the aforementioned hook.

Note: the hook for HostGrowSharedArrayBuffer isn't implemented, since
LibJS doesn't seem to have complete support for growable
SharedArrayBuffers; the relevant methods/getters don't even exist on
the prototype, let alone HostGrowSharedArrayBuffer!

This should help pass the WebAssembly.Memory WPT tests included in
Interop 2025, except those pertaining to growable SharedArrayBuffers.
This commit is contained in:
CountBleck 2025-08-17 14:14:24 -07:00 committed by Ali Mohammad Pur
commit d0d5bffb2d
Notes: github-actions[bot] 2025-08-23 06:27:40 +00:00
6 changed files with 246 additions and 6 deletions

View file

@ -50,6 +50,7 @@
#include <LibWeb/HTML/WorkletGlobalScope.h>
#include <LibWeb/Platform/EventLoopPlugin.h>
#include <LibWeb/ServiceWorker/ServiceWorkerGlobalScope.h>
#include <LibWeb/WebAssembly/WebAssembly.h>
#include <LibWeb/WebIDL/AbstractOperations.h>
namespace Web::Bindings {
@ -690,6 +691,14 @@ void initialize_main_thread_vm(AgentType type)
s_main_thread_vm->host_unrecognized_date_string = [](StringView date) {
dbgln("Unable to parse date string: \"{}\"", date);
};
s_main_thread_vm->host_resize_array_buffer = [default_host_resize_array_buffer = move(s_main_thread_vm->host_resize_array_buffer)](JS::ArrayBuffer& buffer, size_t new_byte_length) -> JS::ThrowCompletionOr<JS::HandledByHost> {
auto wasm_handled = TRY(WebAssembly::Detail::host_resize_array_buffer(*s_main_thread_vm, buffer, new_byte_length));
if (wasm_handled == JS::HandledByHost::Handled)
return JS::HandledByHost::Handled;
return default_host_resize_array_buffer(buffer, new_byte_length);
};
}
JS::VM& main_thread_vm()