Table.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #pragma once
  8. #include <AK/Optional.h>
  9. #include <LibJS/Forward.h>
  10. #include <LibJS/Heap/GCPtr.h>
  11. #include <LibJS/Runtime/Value.h>
  12. #include <LibWasm/AbstractMachine/AbstractMachine.h>
  13. #include <LibWeb/Bindings/ExceptionOrUtils.h>
  14. #include <LibWeb/Bindings/PlatformObject.h>
  15. #include <LibWeb/Bindings/TablePrototype.h>
  16. namespace Web::WebAssembly {
  17. struct TableDescriptor {
  18. Bindings::TableKind element;
  19. u32 initial { 0 };
  20. Optional<u32> maximum;
  21. };
  22. class Table : public Bindings::PlatformObject {
  23. WEB_PLATFORM_OBJECT(Table, Bindings::PlatformObject);
  24. JS_DECLARE_ALLOCATOR(Table);
  25. public:
  26. static WebIDL::ExceptionOr<JS::NonnullGCPtr<Table>> construct_impl(JS::Realm&, TableDescriptor& descriptor, JS::Value value);
  27. WebIDL::ExceptionOr<u32> grow(u32 delta, JS::Value value);
  28. WebIDL::ExceptionOr<JS::Value> get(u32 index) const;
  29. WebIDL::ExceptionOr<void> set(u32 index, JS::Value value);
  30. WebIDL::ExceptionOr<u32> length() const;
  31. Wasm::TableAddress address() const { return m_address; }
  32. private:
  33. Table(JS::Realm&, Wasm::TableAddress);
  34. virtual void initialize(JS::Realm&) override;
  35. Wasm::TableAddress m_address;
  36. };
  37. }