Memory.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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/ArrayBuffer.h>
  12. #include <LibWasm/AbstractMachine/AbstractMachine.h>
  13. #include <LibWeb/Bindings/ExceptionOrUtils.h>
  14. #include <LibWeb/Bindings/PlatformObject.h>
  15. namespace Web::WebAssembly {
  16. struct MemoryDescriptor {
  17. u32 initial { 0 };
  18. Optional<u32> maximum;
  19. };
  20. class Memory : public Bindings::PlatformObject {
  21. WEB_PLATFORM_OBJECT(Memory, Bindings::PlatformObject);
  22. public:
  23. static WebIDL::ExceptionOr<JS::NonnullGCPtr<Memory>> construct_impl(JS::Realm&, MemoryDescriptor& descriptor);
  24. WebIDL::ExceptionOr<u32> grow(u32 delta);
  25. WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::ArrayBuffer>> buffer() const;
  26. Wasm::MemoryAddress address() const { return m_address; }
  27. private:
  28. Memory(JS::Realm&, Wasm::MemoryAddress);
  29. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  30. Wasm::MemoryAddress m_address;
  31. };
  32. }