Table.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. public:
  25. static WebIDL::ExceptionOr<JS::NonnullGCPtr<Table>> construct_impl(JS::Realm&, TableDescriptor& descriptor, JS::Value value);
  26. WebIDL::ExceptionOr<u32> grow(u32 delta, JS::Value value);
  27. WebIDL::ExceptionOr<JS::Value> get(u32 index) const;
  28. WebIDL::ExceptionOr<void> set(u32 index, JS::Value value);
  29. WebIDL::ExceptionOr<u32> length() const;
  30. Wasm::TableAddress address() const { return m_address; }
  31. private:
  32. Table(JS::Realm&, Wasm::TableAddress);
  33. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  34. Wasm::TableAddress m_address;
  35. };
  36. }