Serenity Operating System
1/*
2 * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#pragma once
8
9#include <LibJS/Runtime/GlobalObject.h>
10#include <LibJS/Runtime/Object.h>
11#include <LibJS/Runtime/VM.h>
12#include <LibWasm/AbstractMachine/AbstractMachine.h>
13#include <LibWeb/Forward.h>
14#include <LibWeb/WebAssembly/WebAssemblyObject.h>
15
16namespace Web::Bindings {
17
18class WebAssemblyInstanceObject final : public JS::Object {
19 JS_OBJECT(WebAssemblyInstanceObject, Object);
20
21public:
22 explicit WebAssemblyInstanceObject(JS::Realm&, size_t index);
23 virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
24 virtual ~WebAssemblyInstanceObject() override = default;
25
26 size_t index() const { return m_index; }
27 Wasm::ModuleInstance& instance() const { return *WebAssemblyObject::s_instantiated_modules[m_index]; }
28 auto& cache() { return WebAssemblyObject::s_module_caches.at(m_index); }
29
30 void visit_edges(Visitor&) override;
31
32 friend class WebAssemblyInstancePrototype;
33
34private:
35 size_t m_index { 0 };
36 Object* m_exports_object { nullptr };
37};
38
39}