/src/serenity/Userland/Libraries/LibWeb/WebAssembly/Table.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/Runtime/Value.h> |
14 | | #include <LibWasm/AbstractMachine/AbstractMachine.h> |
15 | | #include <LibWeb/Bindings/ExceptionOrUtils.h> |
16 | | #include <LibWeb/Bindings/PlatformObject.h> |
17 | | #include <LibWeb/Bindings/TablePrototype.h> |
18 | | |
19 | | namespace Web::WebAssembly { |
20 | | |
21 | | struct TableDescriptor { |
22 | | Bindings::TableKind element; |
23 | | u32 initial { 0 }; |
24 | | Optional<u32> maximum; |
25 | | }; |
26 | | |
27 | | class Table : public Bindings::PlatformObject { |
28 | | WEB_PLATFORM_OBJECT(Table, Bindings::PlatformObject); |
29 | | JS_DECLARE_ALLOCATOR(Table); |
30 | | |
31 | | public: |
32 | | static WebIDL::ExceptionOr<JS::NonnullGCPtr<Table>> construct_impl(JS::Realm&, TableDescriptor& descriptor, JS::Value value); |
33 | | |
34 | | WebIDL::ExceptionOr<u32> grow(u32 delta, JS::Value value); |
35 | | |
36 | | WebIDL::ExceptionOr<JS::Value> get(u32 index) const; |
37 | | WebIDL::ExceptionOr<void> set(u32 index, JS::Value value); |
38 | | |
39 | | WebIDL::ExceptionOr<u32> length() const; |
40 | | |
41 | 0 | Wasm::TableAddress address() const { return m_address; } |
42 | | |
43 | | private: |
44 | | Table(JS::Realm&, Wasm::TableAddress); |
45 | | |
46 | | virtual void initialize(JS::Realm&) override; |
47 | | |
48 | | Wasm::TableAddress m_address; |
49 | | }; |
50 | | |
51 | | } |