mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
bdd3a16b16
Making the body GC-allocated allows us to avoid using `JS::Handle` for `m_stream` in its members.
51 lines
1.6 KiB
C++
51 lines
1.6 KiB
C++
/*
|
|
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Forward.h>
|
|
#include <LibJS/Forward.h>
|
|
#include <LibJS/Heap/GCPtr.h>
|
|
#include <LibWeb/Forward.h>
|
|
|
|
namespace Web::Fetch {
|
|
|
|
enum class PackageDataType {
|
|
ArrayBuffer,
|
|
Blob,
|
|
FormData,
|
|
JSON,
|
|
Text,
|
|
};
|
|
|
|
// https://fetch.spec.whatwg.org/#body-mixin
|
|
class BodyMixin {
|
|
public:
|
|
virtual ~BodyMixin();
|
|
|
|
virtual ErrorOr<Optional<MimeSniff::MimeType>> mime_type_impl() const = 0;
|
|
virtual JS::GCPtr<Infrastructure::Body> body_impl() = 0;
|
|
virtual JS::GCPtr<Infrastructure::Body const> body_impl() const = 0;
|
|
virtual Bindings::PlatformObject& as_platform_object() = 0;
|
|
virtual Bindings::PlatformObject const& as_platform_object() const = 0;
|
|
|
|
[[nodiscard]] bool is_unusable() const;
|
|
[[nodiscard]] JS::GCPtr<Streams::ReadableStream> body() const;
|
|
[[nodiscard]] bool body_used() const;
|
|
|
|
// JS API functions
|
|
[[nodiscard]] WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> array_buffer() const;
|
|
[[nodiscard]] WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> blob() const;
|
|
[[nodiscard]] WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> form_data() const;
|
|
[[nodiscard]] WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> json() const;
|
|
[[nodiscard]] WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> text() const;
|
|
};
|
|
|
|
[[nodiscard]] WebIDL::ExceptionOr<JS::Value> package_data(JS::Realm&, ByteBuffer, PackageDataType, Optional<MimeSniff::MimeType> const&);
|
|
[[nodiscard]] WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> consume_body(JS::Realm&, BodyMixin const&, PackageDataType);
|
|
|
|
}
|