LibWeb: Support WASM modules

This adds support for importing WASM modules in JavaScript and vice
versa.
This commit is contained in:
Glenn Skrzypczak 2025-09-19 22:18:28 +02:00 committed by Shannon Booth
parent 7392d2a2f4
commit e5dab9e1c7
Notes: github-actions[bot] 2026-04-03 19:22:16 +00:00
30 changed files with 759 additions and 77 deletions

View file

@ -10,6 +10,7 @@
#include <LibJS/SyntheticModule.h>
#include <LibWeb/Export.h>
#include <LibWeb/HTML/Scripting/Script.h>
#include <LibWeb/WebAssembly/WebAssemblyModule.h>
namespace JS::FFI {
@ -19,8 +20,7 @@ struct ParsedProgram;
namespace Web::HTML {
// FIXME: Support WebAssembly Module Record
using ModuleScriptRecord = Variant<Empty, GC::Ref<JS::SourceTextModule>, GC::Ref<JS::SyntheticModule>>;
using ModuleScriptRecord = Variant<Empty, GC::Ref<JS::SourceTextModule>, GC::Ref<JS::SyntheticModule>, GC::Ref<WebAssembly::WebAssemblyModule>>;
// https://html.spec.whatwg.org/multipage/webappapis.html#module-script
class WEB_API ModuleScript : public Script {
@ -35,13 +35,14 @@ public:
static WebIDL::ExceptionOr<GC::Ptr<ModuleScript>> create_a_javascript_module_script(ByteString const& filename, StringView source, JS::Realm&, URL::URL base_url);
static WebIDL::ExceptionOr<GC::Ptr<ModuleScript>> create_a_css_module_script(ByteString const& filename, StringView source, JS::Realm&);
static WebIDL::ExceptionOr<GC::Ptr<ModuleScript>> create_a_json_module_script(ByteString const& filename, StringView source, JS::Realm&);
static WebIDL::ExceptionOr<GC::Ptr<ModuleScript>> create_a_webassembly_module_script(ByteString const& filename, ByteBuffer body_bytes, JS::Realm&, URL::URL base_url);
enum class PreventErrorReporting {
Yes,
No
};
JS::Promise* run(PreventErrorReporting = PreventErrorReporting::No);
WebIDL::Promise* run(PreventErrorReporting = PreventErrorReporting::No);
ModuleScriptRecord record() const { return m_record; }