/* * Copyright (c) 2023, Kenneth Myhra * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace Web::XHR { // https://xhr.spec.whatwg.org/#formdataentryvalue using FormDataEntryValue = Variant, String>; struct FormDataEntry { String name; FormDataEntryValue value; }; // https://xhr.spec.whatwg.org/#interface-formdata class FormData : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(FormData, Bindings::PlatformObject); public: virtual ~FormData() override; static WebIDL::ExceptionOr> construct_impl(JS::Realm&, Optional> form = {}); static WebIDL::ExceptionOr> construct_impl(JS::Realm&, Vector entry_list); WebIDL::ExceptionOr append(String const& name, String const& value); WebIDL::ExceptionOr append(String const& name, JS::NonnullGCPtr const& blob_value, Optional const& filename = {}); void delete_(String const& name); Variant, String, Empty> get(String const& name); WebIDL::ExceptionOr> get_all(String const& name); bool has(String const& name); WebIDL::ExceptionOr set(String const& name, String const& value); WebIDL::ExceptionOr set(String const& name, JS::NonnullGCPtr const& blob_value, Optional const& filename = {}); Vector const& entry_list() const { return m_entry_list; } using ForEachCallback = Function(String const&, FormDataEntryValue const&)>; JS::ThrowCompletionOr for_each(ForEachCallback); private: friend class FormDataIterator; explicit FormData(JS::Realm&, Vector entry_list = {}); virtual JS::ThrowCompletionOr initialize(JS::Realm&) override; WebIDL::ExceptionOr append_impl(String const& name, Variant, String> const& value, Optional const& filename = {}); WebIDL::ExceptionOr set_impl(String const& name, Variant, String> const& value, Optional const& filename = {}); Vector m_entry_list; }; }