/* * 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; }; class Memory : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(Memory, Bindings::PlatformObject); 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); virtual JS::ThrowCompletionOr initialize(JS::Realm&) override; WebIDL::ExceptionOr reset_the_memory_buffer(); static WebIDL::ExceptionOr> create_a_memory_buffer(JS::VM&, JS::Realm&, Wasm::MemoryAddress); Wasm::MemoryAddress m_address; mutable JS::GCPtr m_buffer; }; }