From 09124fc3a52262eb45f556c69786132b685cb7fe Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 25 Jan 2024 14:40:55 -0500 Subject: [PATCH] LibWeb: Set up the Fetch response's body with the appropriate stream --- .../Text/expected/Streams/init-from-fetch.txt | 1 + .../LibWeb/Text/input/Streams/init-from-fetch.html | 14 ++++++++++++++ Userland/Libraries/LibWeb/Fetch/BodyInit.cpp | 13 ++++++++----- 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/Streams/init-from-fetch.txt create mode 100644 Tests/LibWeb/Text/input/Streams/init-from-fetch.html diff --git a/Tests/LibWeb/Text/expected/Streams/init-from-fetch.txt b/Tests/LibWeb/Text/expected/Streams/init-from-fetch.txt new file mode 100644 index 0000000000..0670438aaf --- /dev/null +++ b/Tests/LibWeb/Text/expected/Streams/init-from-fetch.txt @@ -0,0 +1 @@ +Was able to create a reader from a Fetch response! diff --git a/Tests/LibWeb/Text/input/Streams/init-from-fetch.html b/Tests/LibWeb/Text/input/Streams/init-from-fetch.html new file mode 100644 index 0000000000..851d540070 --- /dev/null +++ b/Tests/LibWeb/Text/input/Streams/init-from-fetch.html @@ -0,0 +1,14 @@ + + diff --git a/Userland/Libraries/LibWeb/Fetch/BodyInit.cpp b/Userland/Libraries/LibWeb/Fetch/BodyInit.cpp index 4fe430520b..95bcf05a78 100644 --- a/Userland/Libraries/LibWeb/Fetch/BodyInit.cpp +++ b/Userland/Libraries/LibWeb/Fetch/BodyInit.cpp @@ -8,7 +8,10 @@ #include #include #include +#include #include +#include +#include #include #include #include @@ -33,6 +36,8 @@ WebIDL::ExceptionOr safely_extract_body(JS::Realm& // https://fetch.spec.whatwg.org/#concept-bodyinit-extract WebIDL::ExceptionOr extract_body(JS::Realm& realm, BodyInitOrReadableBytes const& object, bool keepalive) { + HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + auto& vm = realm.vm(); // 1. Let stream be null. @@ -44,14 +49,12 @@ WebIDL::ExceptionOr extract_body(JS::Realm& realm, } // 3. Otherwise, if object is a Blob object, set stream to the result of running object’s get stream. else if (auto const* blob_handle = object.get_pointer>()) { - // FIXME: "set stream to the result of running object’s get stream" - (void)blob_handle; - stream = realm.heap().allocate(realm, realm); + stream = TRY(blob_handle->cell()->get_stream()); } - // 4. Otherwise, set stream to a new ReadableStream object, and set up stream. + // 4. Otherwise, set stream to a new ReadableStream object, and set up stream with byte reading support. else { - // FIXME: "set up stream" stream = realm.heap().allocate(realm, realm); + TRY(Streams::set_up_readable_stream_controller_with_byte_reading_support(*stream)); } // 5. Assert: stream is a ReadableStream object.