/* * Copyright (c) 2021, Ali Mohammad Pur * Copyright (c) 2023, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace Web::WebAssembly { struct MemoryDescriptor { u32 initial { 0 }; Optional maximum; Optional shared; }; class Memory : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(Memory, Bindings::PlatformObject); GC_DECLARE_ALLOCATOR(Memory); enum class Shared { No, Yes, }; public: static WebIDL::ExceptionOr> construct_impl(JS::Realm&, MemoryDescriptor& descriptor); WebIDL::ExceptionOr grow(u32 delta); WebIDL::ExceptionOr> buffer() const; Wasm::MemoryAddress address() const { return m_address; } private: Memory(JS::Realm&, Wasm::MemoryAddress, Shared shared); virtual void initialize(JS::Realm&) override; virtual void visit_edges(Visitor&) override; WebIDL::ExceptionOr reset_the_memory_buffer(); static WebIDL::ExceptionOr> create_a_fixed_length_memory_buffer(JS::VM&, JS::Realm&, Wasm::MemoryAddress, Shared shared); Wasm::MemoryAddress m_address; Shared m_shared { Shared::No }; mutable GC::Ptr m_buffer; }; }