ladybird/Libraries/LibWeb/Fetch/BodyInit.h
Shannon Booth 97abc707c7 LibWeb/Bindings: Generate buffer typedefs as variants
Represent BufferSource and ArrayBufferView as ordinary IDL typedefs over
their underlying union types, instead of special casing in the IDL
generator. This allows the union conversion/return machinery handle
these types consistently with other typedefs, which removes buffer
specific paths from the IDL generator.

This necessitates changing the WebIDL::BufferSource and
WebIDL::ArrayBufferView classes as views over these variants. This
replaces the old GC backed BufferableObject wrapper structure and
provide convenience helpers to determine things such as the byte length,
byte offset, backing buffer, and typed-array APIs.
2026-05-30 11:22:08 +02:00

28 lines
1.1 KiB
C++

/*
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Forward.h>
#include <AK/Variant.h>
#include <LibCore/ImmutableBytes.h>
#include <LibJS/Forward.h>
#include <LibWeb/Export.h>
#include <LibWeb/Forward.h>
#include <LibWeb/WebIDL/Buffers.h>
namespace Web::Fetch {
// https://fetch.spec.whatwg.org/#bodyinit
using XMLHttpRequestBodyInit = FlattenVariant<WebIDL::BufferSourceVariant, Variant<GC::Ref<FileAPI::Blob>, GC::Ref<XHR::FormData>, GC::Ref<DOMURL::URLSearchParams>, String>>;
using BodyInit = FlattenVariant<Variant<GC::Ref<Streams::ReadableStream>>, XMLHttpRequestBodyInit>;
using NullableBodyInit = FlattenVariant<BodyInit, Variant<Empty>>;
using BodyInitOrReadableBytes = FlattenVariant<BodyInit, Variant<ReadonlyBytes, Core::ImmutableBytes>>;
WEB_API Infrastructure::BodyWithType safely_extract_body(JS::Realm&, BodyInitOrReadableBytes const&);
WEB_API WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm&, BodyInitOrReadableBytes const&, bool keepalive = false);
}