summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.h
blob: e5347e288b8705184debc96eb74b5630c5bf79d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
 * 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;
};

}