mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 01:37:39 +03:00
LibWeb: Remove ReadableStreamDummy in favor of ReadableStream
This commit is contained in:
parent
87654f5b51
commit
f98ce156c4
Notes:
sideshowbarker
2024-07-17 07:11:12 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/f98ce156c4 Pull-request: https://github.com/SerenityOS/serenity/pull/15323 Reviewed-by: https://github.com/davidot ✅ Reviewed-by: https://github.com/kennethmyhra ✅
@ -8,13 +8,13 @@
|
||||
|
||||
namespace Web::Fetch::Infrastructure {
|
||||
|
||||
Body::Body(ReadableStreamDummy stream)
|
||||
: m_stream(stream)
|
||||
Body::Body(JS::Handle<Streams::ReadableStream> stream)
|
||||
: m_stream(move(stream))
|
||||
{
|
||||
}
|
||||
|
||||
Body::Body(ReadableStreamDummy stream, SourceType source, Optional<u64> length)
|
||||
: m_stream(stream)
|
||||
Body::Body(JS::Handle<Streams::ReadableStream> stream, SourceType source, Optional<u64> length)
|
||||
: m_stream(move(stream))
|
||||
, m_source(move(source))
|
||||
, m_length(move(length))
|
||||
{
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <AK/Variant.h>
|
||||
#include <LibJS/Heap/Handle.h>
|
||||
#include <LibWeb/FileAPI/Blob.h>
|
||||
#include <LibWeb/Streams/ReadableStream.h>
|
||||
|
||||
namespace Web::Fetch::Infrastructure {
|
||||
|
||||
@ -21,20 +22,17 @@ class Body final {
|
||||
public:
|
||||
using SourceType = Variant<Empty, ByteBuffer, JS::Handle<FileAPI::Blob>>;
|
||||
|
||||
struct ReadableStreamDummy { };
|
||||
explicit Body(JS::Handle<Streams::ReadableStream>);
|
||||
Body(JS::Handle<Streams::ReadableStream>, SourceType, Optional<u64>);
|
||||
|
||||
explicit Body(ReadableStreamDummy);
|
||||
Body(ReadableStreamDummy, SourceType, Optional<u64>);
|
||||
|
||||
[[nodiscard]] ReadableStreamDummy const& stream() { return m_stream; }
|
||||
[[nodiscard]] JS::NonnullGCPtr<Streams::ReadableStream> stream() { return *m_stream; }
|
||||
[[nodiscard]] SourceType const& source() const { return m_source; }
|
||||
[[nodiscard]] Optional<u64> const& length() const { return m_length; }
|
||||
|
||||
private:
|
||||
// https://fetch.spec.whatwg.org/#concept-body-stream
|
||||
// A stream (a ReadableStream object).
|
||||
// FIXME: Just a placeholder for now.
|
||||
ReadableStreamDummy m_stream;
|
||||
JS::Handle<Streams::ReadableStream> m_stream;
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-body-source
|
||||
// A source (null, a byte sequence, a Blob object, or a FormData object), initially null.
|
||||
|
@ -270,10 +270,12 @@ Optional<StringView> XMLHttpRequest::get_final_encoding() const
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-bodyinit-extract
|
||||
// FIXME: The parameter 'body_init' should be 'typedef (ReadableStream or XMLHttpRequestBodyInit) BodyInit'. For now we just let it be 'XMLHttpRequestBodyInit'.
|
||||
static ErrorOr<Fetch::Infrastructure::BodyWithType> extract_body(Fetch::XMLHttpRequestBodyInit const& body_init)
|
||||
static ErrorOr<Fetch::Infrastructure::BodyWithType> extract_body(JS::Realm& realm, Fetch::XMLHttpRequestBodyInit const& body_init)
|
||||
{
|
||||
auto& window = verify_cast<HTML::Window>(realm.global_object());
|
||||
|
||||
// FIXME: 1. Let stream be object if object is a ReadableStream object. Otherwise, let stream be a new ReadableStream, and set up stream.
|
||||
Fetch::Infrastructure::Body::ReadableStreamDummy stream {};
|
||||
auto* stream = realm.heap().allocate<Streams::ReadableStream>(realm, window);
|
||||
// FIXME: 2. Let action be null.
|
||||
// 3. Let source be null.
|
||||
Fetch::Infrastructure::Body::SourceType source {};
|
||||
@ -321,7 +323,7 @@ static ErrorOr<Fetch::Infrastructure::BodyWithType> extract_body(Fetch::XMLHttpR
|
||||
// FIXME: 8. If action is non-null, then run these steps in in parallel:
|
||||
|
||||
// 9. Let body be a body whose stream is stream, source is source, and length is length.
|
||||
auto body = Fetch::Infrastructure::Body { move(stream), move(source), move(length) };
|
||||
auto body = Fetch::Infrastructure::Body { JS::make_handle(stream), move(source), move(length) };
|
||||
// 10. Return (body, type).
|
||||
return Fetch::Infrastructure::BodyWithType { .body = move(body), .type = move(type) };
|
||||
}
|
||||
@ -455,6 +457,9 @@ DOM::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, String
|
||||
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send
|
||||
DOM::ExceptionOr<void> XMLHttpRequest::send(Optional<Fetch::XMLHttpRequestBodyInit> body)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
if (m_ready_state != ReadyState::Opened)
|
||||
return DOM::InvalidStateError::create(global_object(), "XHR readyState is not OPENED");
|
||||
|
||||
@ -465,7 +470,7 @@ DOM::ExceptionOr<void> XMLHttpRequest::send(Optional<Fetch::XMLHttpRequestBodyIn
|
||||
if (m_method.is_one_of("GET"sv, "HEAD"sv))
|
||||
body = {};
|
||||
|
||||
auto body_with_type = body.has_value() ? TRY_OR_RETURN_OOM(global_object(), extract_body(body.value())) : Optional<Fetch::Infrastructure::BodyWithType> {};
|
||||
auto body_with_type = body.has_value() ? TRY_OR_RETURN_OOM(global_object(), extract_body(realm, body.value())) : Optional<Fetch::Infrastructure::BodyWithType> {};
|
||||
|
||||
AK::URL request_url = m_window->associated_document().parse_url(m_url.to_string());
|
||||
dbgln("XHR send from {} to {}", m_window->associated_document().url(), request_url);
|
||||
|
Loading…
Reference in New Issue
Block a user