summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-03-15 18:15:28 -0400
committerAndreas Kling <kling@serenityos.org>2023-03-16 13:54:16 +0100
commitde32c44762faa039c250eaa7b0cd0bacf3a7209e (patch)
treee4f4fe5000b0d0274a8f74e25b7cedcf3b9441d4 /Userland
parentfb1f15774f1b850829c2785beae9cb875ea713f8 (diff)
downloadserenity-de32c44762faa039c250eaa7b0cd0bacf3a7209e.zip
LibWeb: Port WebAssembly.Instance to IDL
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/CMakeLists.txt4
-rw-r--r--Userland/Libraries/LibWeb/Forward.h1
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/Instance.cpp98
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/Instance.h37
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/Instance.idl9
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp53
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.h28
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp83
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.h39
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.cpp31
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.h32
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp8
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.h1
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableObject.h1
-rw-r--r--Userland/Libraries/LibWeb/idl_files.cmake1
15 files changed, 151 insertions, 275 deletions
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt
index 8a0064252f..ff7b35d4ac 100644
--- a/Userland/Libraries/LibWeb/CMakeLists.txt
+++ b/Userland/Libraries/LibWeb/CMakeLists.txt
@@ -442,10 +442,8 @@ set(SOURCES
URL/URL.cpp
URL/URLSearchParams.cpp
URL/URLSearchParamsIterator.cpp
+ WebAssembly/Instance.cpp
WebAssembly/Module.cpp
- WebAssembly/WebAssemblyInstanceConstructor.cpp
- WebAssembly/WebAssemblyInstanceObject.cpp
- WebAssembly/WebAssemblyInstanceObjectPrototype.cpp
WebAssembly/WebAssemblyMemoryConstructor.cpp
WebAssembly/WebAssemblyMemoryPrototype.cpp
WebAssembly/WebAssemblyObject.cpp
diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h
index e19c5c0fc3..65dc5afff8 100644
--- a/Userland/Libraries/LibWeb/Forward.h
+++ b/Userland/Libraries/LibWeb/Forward.h
@@ -482,6 +482,7 @@ class ResourceLoader;
}
namespace Web::WebAssembly {
+class Instance;
class Module;
}
diff --git a/Userland/Libraries/LibWeb/WebAssembly/Instance.cpp b/Userland/Libraries/LibWeb/WebAssembly/Instance.cpp
new file mode 100644
index 0000000000..1d73057bc1
--- /dev/null
+++ b/Userland/Libraries/LibWeb/WebAssembly/Instance.cpp
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
+ * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibJS/Runtime/FunctionObject.h>
+#include <LibJS/Runtime/NativeFunction.h>
+#include <LibJS/Runtime/Realm.h>
+#include <LibJS/Runtime/VM.h>
+#include <LibWasm/AbstractMachine/AbstractMachine.h>
+#include <LibWeb/Bindings/InstancePrototype.h>
+#include <LibWeb/Bindings/Intrinsics.h>
+#include <LibWeb/WebAssembly/Instance.h>
+#include <LibWeb/WebAssembly/Module.h>
+#include <LibWeb/WebAssembly/WebAssemblyObject.h>
+#include <LibWeb/WebAssembly/WebAssemblyTableObject.h>
+
+namespace Web::WebAssembly {
+
+WebIDL::ExceptionOr<JS::NonnullGCPtr<Instance>> Instance::construct_impl(JS::Realm& realm, Module& module, Optional<JS::Handle<JS::Object>>& import_object)
+{
+ // FIXME: Implement the importObject parameter.
+ (void)import_object;
+
+ auto& vm = realm.vm();
+
+ auto index = TRY(Bindings::WebAssemblyObject::instantiate_module(vm, module.module()));
+ return MUST_OR_THROW_OOM(vm.heap().allocate<Instance>(realm, realm, index));
+}
+
+Instance::Instance(JS::Realm& realm, size_t index)
+ : Bindings::PlatformObject(realm)
+ , m_exports(Object::create(realm, nullptr))
+ , m_index(index)
+{
+}
+
+JS::ThrowCompletionOr<void> Instance::initialize(JS::Realm& realm)
+{
+ auto& vm = this->vm();
+
+ MUST_OR_THROW_OOM(Base::initialize(realm));
+ set_prototype(&Bindings::ensure_web_prototype<Bindings::InstancePrototype>(realm, "WebAssembly.Instance"sv));
+
+ auto& instance = *Bindings::WebAssemblyObject::s_instantiated_modules[m_index];
+ auto& cache = Bindings::WebAssemblyObject::s_module_caches.at(m_index);
+
+ for (auto& export_ : instance.exports()) {
+ TRY(export_.value().visit(
+ [&](Wasm::FunctionAddress const& address) -> JS::ThrowCompletionOr<void> {
+ Optional<JS::GCPtr<JS::FunctionObject>> object = cache.function_instances.get(address);
+ if (!object.has_value()) {
+ object = Bindings::create_native_function(vm, address, export_.name());
+ cache.function_instances.set(address, *object);
+ }
+
+ m_exports->define_direct_property(export_.name(), *object, JS::default_attributes);
+ return {};
+ },
+ [&](Wasm::MemoryAddress const& address) -> JS::ThrowCompletionOr<void> {
+ Optional<JS::GCPtr<Bindings::WebAssemblyMemoryObject>> object = cache.memory_instances.get(address);
+ if (!object.has_value()) {
+ object = MUST_OR_THROW_OOM(heap().allocate<Web::Bindings::WebAssemblyMemoryObject>(realm, realm, address));
+ cache.memory_instances.set(address, *object);
+ }
+
+ m_exports->define_direct_property(export_.name(), *object, JS::default_attributes);
+ return {};
+ },
+ [&](Wasm::TableAddress const& address) -> JS::ThrowCompletionOr<void> {
+ Optional<JS::GCPtr<Bindings::WebAssemblyTableObject>> object = cache.table_instances.get(address);
+ if (!object.has_value()) {
+ object = MUST_OR_THROW_OOM(heap().allocate<Web::Bindings::WebAssemblyTableObject>(realm, realm, address));
+ cache.table_instances.set(address, *object);
+ }
+
+ m_exports->define_direct_property(export_.name(), *object, JS::default_attributes);
+ return {};
+ },
+ [&](auto const&) -> JS::ThrowCompletionOr<void> {
+ // FIXME: Implement other exports!
+ return {};
+ }));
+ }
+
+ MUST(m_exports->set_integrity_level(IntegrityLevel::Frozen));
+ return {};
+}
+
+void Instance::visit_edges(Visitor& visitor)
+{
+ Base::visit_edges(visitor);
+ visitor.visit(m_exports);
+}
+
+}
diff --git a/Userland/Libraries/LibWeb/WebAssembly/Instance.h b/Userland/Libraries/LibWeb/WebAssembly/Instance.h
new file mode 100644
index 0000000000..c3f4380d01
--- /dev/null
+++ b/Userland/Libraries/LibWeb/WebAssembly/Instance.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
+ * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Optional.h>
+#include <LibJS/Forward.h>
+#include <LibJS/Heap/GCPtr.h>
+#include <LibJS/Heap/Handle.h>
+#include <LibWeb/Bindings/ExceptionOrUtils.h>
+#include <LibWeb/Bindings/PlatformObject.h>
+
+namespace Web::WebAssembly {
+
+class Instance : public Bindings::PlatformObject {
+ WEB_PLATFORM_OBJECT(Instance, Bindings::PlatformObject);
+
+public:
+ static WebIDL::ExceptionOr<JS::NonnullGCPtr<Instance>> construct_impl(JS::Realm&, Module& module, Optional<JS::Handle<JS::Object>>& import_object);
+
+ Object const* exports() const { return m_exports.ptr(); }
+
+private:
+ Instance(JS::Realm&, size_t index);
+
+ virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
+ virtual void visit_edges(Visitor&) override;
+
+ JS::NonnullGCPtr<Object> m_exports;
+ size_t m_index { 0 };
+};
+
+}
diff --git a/Userland/Libraries/LibWeb/WebAssembly/Instance.idl b/Userland/Libraries/LibWeb/WebAssembly/Instance.idl
new file mode 100644
index 0000000000..5a31ec18f1
--- /dev/null
+++ b/Userland/Libraries/LibWeb/WebAssembly/Instance.idl
@@ -0,0 +1,9 @@
+#import <WebAssembly/Module.idl>
+
+// https://webassembly.github.io/spec/js-api/#instances
+[LegacyNamespace=WebAssembly, Exposed=*]
+interface Instance {
+ constructor(Module module, optional object importObject);
+
+ readonly attribute object exports;
+};
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp
deleted file mode 100644
index f7b5091d4d..0000000000
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibJS/Runtime/GlobalObject.h>
-#include <LibWeb/Bindings/Intrinsics.h>
-#include <LibWeb/WebAssembly/Module.h>
-#include <LibWeb/WebAssembly/WebAssemblyInstanceConstructor.h>
-#include <LibWeb/WebAssembly/WebAssemblyInstanceObject.h>
-#include <LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.h>
-#include <LibWeb/WebAssembly/WebAssemblyObject.h>
-
-namespace Web::Bindings {
-
-WebAssemblyInstanceConstructor::WebAssemblyInstanceConstructor(JS::Realm& realm)
- : NativeFunction(*realm.intrinsics().function_prototype())
-{
-}
-
-WebAssemblyInstanceConstructor::~WebAssemblyInstanceConstructor() = default;
-
-JS::ThrowCompletionOr<JS::Value> WebAssemblyInstanceConstructor::call()
-{
- return vm().throw_completion<JS::TypeError>(JS::ErrorType::ConstructorWithoutNew, "WebAssembly.Instance");
-}
-
-JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> WebAssemblyInstanceConstructor::construct(FunctionObject&)
-{
- auto& vm = this->vm();
- auto& realm = *vm.current_realm();
-
- auto* module_argument = TRY(vm.argument(0).to_object(vm));
- if (!is<WebAssembly::Module>(module_argument))
- return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Module");
- auto& module_object = static_cast<WebAssembly::Module&>(*module_argument);
- auto result = TRY(WebAssemblyObject::instantiate_module(vm, module_object.module()));
- return MUST_OR_THROW_OOM(heap().allocate<WebAssemblyInstanceObject>(realm, realm, result));
-}
-
-JS::ThrowCompletionOr<void> WebAssemblyInstanceConstructor::initialize(JS::Realm& realm)
-{
- auto& vm = this->vm();
-
- MUST_OR_THROW_OOM(NativeFunction::initialize(realm));
- define_direct_property(vm.names.prototype, &Bindings::ensure_web_prototype<WebAssemblyInstancePrototype>(realm, "WebAssembly.Instance"), 0);
- define_direct_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable);
-
- return {};
-}
-
-}
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.h b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.h
deleted file mode 100644
index e5b7341110..0000000000
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <LibJS/Runtime/NativeFunction.h>
-
-namespace Web::Bindings {
-
-class WebAssemblyInstanceConstructor : public JS::NativeFunction {
- JS_OBJECT(WebAssemblyInstanceConstructor, JS::NativeFunction);
-
-public:
- explicit WebAssemblyInstanceConstructor(JS::Realm&);
- virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
- virtual ~WebAssemblyInstanceConstructor() override;
-
- virtual JS::ThrowCompletionOr<JS::Value> call() override;
- virtual JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> construct(JS::FunctionObject& new_target) override;
-
-private:
- virtual bool has_constructor() const override { return true; }
-};
-
-}
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp
deleted file mode 100644
index a22713884d..0000000000
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <AK/ScopeGuard.h>
-#include <LibJS/Runtime/Array.h>
-#include <LibJS/Runtime/ArrayBuffer.h>
-#include <LibJS/Runtime/BigInt.h>
-#include <LibJS/Runtime/TypedArray.h>
-#include <LibWasm/AbstractMachine/Interpreter.h>
-#include <LibWeb/Bindings/Intrinsics.h>
-#include <LibWeb/WebAssembly/WebAssemblyInstanceObject.h>
-#include <LibWeb/WebAssembly/WebAssemblyMemoryPrototype.h>
-#include <LibWeb/WebAssembly/WebAssemblyObject.h>
-#include <LibWeb/WebAssembly/WebAssemblyTableObject.h>
-
-namespace Web::Bindings {
-
-WebAssemblyInstanceObject::WebAssemblyInstanceObject(JS::Realm& realm, size_t index)
- : Object(ConstructWithPrototypeTag::Tag, Bindings::ensure_web_prototype<WebAssemblyInstancePrototype>(realm, "WebAssembly.Instance"))
- , m_index(index)
-{
-}
-
-JS::ThrowCompletionOr<void> WebAssemblyInstanceObject::initialize(JS::Realm& realm)
-{
- MUST_OR_THROW_OOM(Object::initialize(realm));
-
- auto& vm = this->vm();
-
- VERIFY(!m_exports_object);
- m_exports_object = create(realm, nullptr);
- auto& instance = this->instance();
- auto& cache = this->cache();
- for (auto& export_ : instance.exports()) {
- TRY(export_.value().visit(
- [&](Wasm::FunctionAddress const& address) -> JS::ThrowCompletionOr<void> {
- Optional<JS::GCPtr<JS::FunctionObject>> object = cache.function_instances.get(address);
- if (!object.has_value()) {
- object = create_native_function(vm, address, export_.name());
- cache.function_instances.set(address, *object);
- }
- m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes);
- return {};
- },
- [&](Wasm::MemoryAddress const& address) -> JS::ThrowCompletionOr<void> {
- Optional<JS::GCPtr<WebAssemblyMemoryObject>> object = cache.memory_instances.get(address);
- if (!object.has_value()) {
- object = MUST_OR_THROW_OOM(heap().allocate<Web::Bindings::WebAssemblyMemoryObject>(realm, realm, address));
- cache.memory_instances.set(address, *object);
- }
- m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes);
- return {};
- },
- [&](Wasm::TableAddress const& address) -> JS::ThrowCompletionOr<void> {
- Optional<JS::GCPtr<WebAssemblyTableObject>> object = cache.table_instances.get(address);
- if (!object.has_value()) {
- object = MUST_OR_THROW_OOM(heap().allocate<Web::Bindings::WebAssemblyTableObject>(realm, realm, address));
- cache.table_instances.set(address, *object);
- }
- m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes);
- return {};
- },
- [&](auto const&) -> JS::ThrowCompletionOr<void> {
- // FIXME: Implement other exports!
- return {};
- }));
- }
-
- MUST(m_exports_object->set_integrity_level(IntegrityLevel::Frozen));
-
- return {};
-}
-
-void WebAssemblyInstanceObject::visit_edges(Visitor& visitor)
-{
- Base::visit_edges(visitor);
- visitor.visit(m_exports_object);
-}
-
-}
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.h b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.h
deleted file mode 100644
index e5347e288b..0000000000
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <LibJS/Runtime/GlobalObject.h>
-#include <LibJS/Runtime/Object.h>
-#include <LibJS/Runtime/VM.h>
-#include <LibWasm/AbstractMachine/AbstractMachine.h>
-#include <LibWeb/Forward.h>
-#include <LibWeb/WebAssembly/WebAssemblyObject.h>
-
-namespace Web::Bindings {
-
-class WebAssemblyInstanceObject final : public JS::Object {
- JS_OBJECT(WebAssemblyInstanceObject, Object);
-
-public:
- explicit WebAssemblyInstanceObject(JS::Realm&, size_t index);
- virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
- virtual ~WebAssemblyInstanceObject() override = default;
-
- size_t index() const { return m_index; }
- Wasm::ModuleInstance& instance() const { return *WebAssemblyObject::s_instantiated_modules[m_index]; }
- auto& cache() { return WebAssemblyObject::s_module_caches.at(m_index); }
-
- void visit_edges(Visitor&) override;
-
- friend class WebAssemblyInstancePrototype;
-
-private:
- size_t m_index { 0 };
- JS::GCPtr<Object> m_exports_object;
-};
-
-}
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.cpp
deleted file mode 100644
index bc322e7a24..0000000000
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include "WebAssemblyInstanceObject.h"
-#include <AK/TypeCasts.h>
-#include <LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.h>
-
-namespace Web::Bindings {
-
-JS::ThrowCompletionOr<void> WebAssemblyInstancePrototype::initialize(JS::Realm& realm)
-{
- MUST_OR_THROW_OOM(Object::initialize(realm));
- define_native_accessor(realm, "exports", exports_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
-
- return {};
-}
-
-JS_DEFINE_NATIVE_FUNCTION(WebAssemblyInstancePrototype::exports_getter)
-{
- auto this_value = vm.this_value();
- auto* this_object = TRY(this_value.to_object(vm));
- if (!is<WebAssemblyInstanceObject>(this_object))
- return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebAssembly.Instance");
- auto object = static_cast<WebAssemblyInstanceObject*>(this_object);
- return object->m_exports_object;
-}
-
-}
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.h b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.h
deleted file mode 100644
index 19b9b3eb01..0000000000
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <LibJS/Runtime/GlobalObject.h>
-#include <LibJS/Runtime/Object.h>
-#include <LibJS/Runtime/VM.h>
-#include <LibWeb/Forward.h>
-
-namespace Web::Bindings {
-
-class WebAssemblyInstancePrototype final : public JS::Object {
- JS_OBJECT(WebAssemblyInstancePrototype, Object);
-
-public:
- explicit WebAssemblyInstancePrototype(JS::Realm& realm)
- : JS::Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().object_prototype())
- {
- }
-
- virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
-
-private:
- JS_DECLARE_NATIVE_FUNCTION(exports_getter);
- static JS::Handle<WebAssemblyInstancePrototype> s_instance;
-};
-
-}
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
index 55c717a66b..cf02edbc64 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
@@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include "WebAssemblyInstanceObject.h"
#include "WebAssemblyMemoryPrototype.h"
#include "WebAssemblyTableObject.h"
#include "WebAssemblyTablePrototype.h"
@@ -19,10 +18,11 @@
#include <LibJS/Runtime/TypedArray.h>
#include <LibWasm/AbstractMachine/Interpreter.h>
#include <LibWasm/AbstractMachine/Validator.h>
+#include <LibWeb/Bindings/InstancePrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/ModulePrototype.h>
+#include <LibWeb/WebAssembly/Instance.h>
#include <LibWeb/WebAssembly/Module.h>
-#include <LibWeb/WebAssembly/WebAssemblyInstanceConstructor.h>
#include <LibWeb/WebAssembly/WebAssemblyObject.h>
namespace Web::Bindings {
@@ -45,7 +45,7 @@ JS::ThrowCompletionOr<void> WebAssemblyObject::initialize(JS::Realm& realm)
auto& memory_constructor = Bindings::ensure_web_constructor<WebAssemblyMemoryPrototype>(realm, "WebAssembly.Memory"sv);
define_direct_property("Memory", &memory_constructor, JS::Attribute::Writable | JS::Attribute::Configurable);
- auto& instance_constructor = Bindings::ensure_web_constructor<WebAssemblyInstancePrototype>(realm, "WebAssembly.Instance"sv);
+ auto& instance_constructor = Bindings::ensure_web_constructor<InstancePrototype>(realm, "WebAssembly.Instance"sv);
define_direct_property("Instance", &instance_constructor, JS::Attribute::Writable | JS::Attribute::Configurable);
auto& module_constructor = Bindings::ensure_web_constructor<ModulePrototype>(realm, "WebAssembly.Module"sv);
@@ -345,7 +345,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::instantiate)
if (result.is_error()) {
promise->reject(*result.release_error().value());
} else {
- auto instance_object = MUST_OR_THROW_OOM(vm.heap().allocate<WebAssemblyInstanceObject>(realm, realm, result.release_value()));
+ auto instance_object = MUST_OR_THROW_OOM(vm.heap().allocate<WebAssembly::Instance>(realm, realm, result.release_value()));
if (should_return_module) {
auto object = JS::Object::create(realm, nullptr);
object->define_direct_property("module", MUST_OR_THROW_OOM(vm.heap().allocate<WebAssembly::Module>(realm, realm, s_compiled_modules.size() - 1)), JS::default_attributes);
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.h b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.h
index 0ce3089469..2f506de17f 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.h
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.h
@@ -9,7 +9,6 @@
#include <LibJS/Runtime/Object.h>
#include <LibWasm/AbstractMachine/AbstractMachine.h>
#include <LibWeb/Forward.h>
-#include <LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.h>
namespace Web::Bindings {
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableObject.h b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableObject.h
index 98472e72f5..2592710c41 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableObject.h
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableObject.h
@@ -9,7 +9,6 @@
#include <LibJS/Runtime/Object.h>
#include <LibWasm/AbstractMachine/AbstractMachine.h>
#include <LibWeb/Forward.h>
-#include <LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.h>
#include <LibWeb/WebAssembly/WebAssemblyObject.h>
namespace Web::Bindings {
diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake
index 45e70a2276..d4731013cf 100644
--- a/Userland/Libraries/LibWeb/idl_files.cmake
+++ b/Userland/Libraries/LibWeb/idl_files.cmake
@@ -200,6 +200,7 @@ libweb_js_bindings(UIEvents/UIEvent)
libweb_js_bindings(UIEvents/WheelEvent)
libweb_js_bindings(URL/URL)
libweb_js_bindings(URL/URLSearchParams ITERABLE)
+libweb_js_bindings(WebAssembly/Instance)
libweb_js_bindings(WebAssembly/Module)
libweb_js_bindings(WebGL/WebGLContextEvent)
libweb_js_bindings(WebGL/WebGLRenderingContext)