/src/serenity/Userland/Libraries/LibWeb/WebAssembly/Instance.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org> |
3 | | * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org> |
4 | | * |
5 | | * SPDX-License-Identifier: BSD-2-Clause |
6 | | */ |
7 | | |
8 | | #pragma once |
9 | | |
10 | | #include <AK/Optional.h> |
11 | | #include <LibJS/Forward.h> |
12 | | #include <LibJS/Heap/GCPtr.h> |
13 | | #include <LibJS/Heap/Handle.h> |
14 | | #include <LibWasm/AbstractMachine/AbstractMachine.h> |
15 | | #include <LibWeb/Bindings/ExceptionOrUtils.h> |
16 | | #include <LibWeb/Bindings/PlatformObject.h> |
17 | | #include <LibWeb/WebAssembly/WebAssembly.h> |
18 | | |
19 | | namespace Web::WebAssembly { |
20 | | |
21 | | class Instance : public Bindings::PlatformObject { |
22 | | WEB_PLATFORM_OBJECT(Instance, Bindings::PlatformObject); |
23 | | JS_DECLARE_ALLOCATOR(Instance); |
24 | | |
25 | | public: |
26 | | static WebIDL::ExceptionOr<JS::NonnullGCPtr<Instance>> construct_impl(JS::Realm&, Module& module, Optional<JS::Handle<JS::Object>>& import_object); |
27 | | |
28 | 0 | Object const* exports() const { return m_exports.ptr(); } |
29 | | |
30 | | private: |
31 | | Instance(JS::Realm&, NonnullOwnPtr<Wasm::ModuleInstance>); |
32 | | |
33 | | virtual void initialize(JS::Realm&) override; |
34 | | virtual void visit_edges(Visitor&) override; |
35 | | |
36 | | JS::NonnullGCPtr<Object> m_exports; |
37 | | NonnullOwnPtr<Wasm::ModuleInstance> m_module_instance; |
38 | | HashMap<Wasm::FunctionAddress, JS::GCPtr<JS::FunctionObject>> m_function_instances; |
39 | | HashMap<Wasm::MemoryAddress, JS::GCPtr<WebAssembly::Memory>> m_memory_instances; |
40 | | HashMap<Wasm::TableAddress, JS::GCPtr<WebAssembly::Table>> m_table_instances; |
41 | | }; |
42 | | |
43 | | } |