summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/WebAssembly/Table.h
blob: 2db1a03fe02282d8621c729f098cfda64763a73f (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
40
41
42
43
44
45
46
47
48
49
50
/*
 * 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/Runtime/Value.h>
#include <LibWasm/AbstractMachine/AbstractMachine.h>
#include <LibWeb/Bindings/ExceptionOrUtils.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Bindings/TablePrototype.h>

namespace Web::WebAssembly {

struct TableDescriptor {
    Bindings::TableKind element;
    u32 initial { 0 };
    Optional<u32> maximum;
};

class Table : public Bindings::PlatformObject {
    WEB_PLATFORM_OBJECT(Table, Bindings::PlatformObject);

public:
    static WebIDL::ExceptionOr<JS::NonnullGCPtr<Table>> construct_impl(JS::Realm&, TableDescriptor& descriptor, JS::Value value);

    WebIDL::ExceptionOr<u32> grow(u32 delta, JS::Value value);

    WebIDL::ExceptionOr<JS::Value> get(u32 index) const;
    WebIDL::ExceptionOr<void> set(u32 index, JS::Value value);

    WebIDL::ExceptionOr<u32> length() const;

    Wasm::TableAddress address() const { return m_address; }

private:
    Table(JS::Realm&, Wasm::TableAddress);

    virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;

    Wasm::TableAddress m_address;
};

}