diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp index 9da3be3cfdb..c8fad8b5eb8 100644 --- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp +++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp @@ -744,7 +744,7 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const transform_stream->set_up(identity_transform_algorithm, flush_algorithm); // 4. Set internalResponse’s body’s stream to the result of internalResponse’s body’s stream piped through transformStream. - auto promise = Streams::readable_stream_pipe_to(internal_response->body()->stream(), transform_stream->writable(), false, false, false, {}); + auto promise = internal_response->body()->stream()->piped_through(transform_stream->writable()); WebIDL::mark_promise_as_handled(*promise); internal_response->body()->set_stream(transform_stream->readable()); } diff --git a/Libraries/LibWeb/Streams/AbstractOperations.cpp b/Libraries/LibWeb/Streams/AbstractOperations.cpp index 103ae128b10..33d8b08b8b1 100644 --- a/Libraries/LibWeb/Streams/AbstractOperations.cpp +++ b/Libraries/LibWeb/Streams/AbstractOperations.cpp @@ -290,7 +290,7 @@ bool readable_stream_has_default_reader(ReadableStream const& stream) } // https://streams.spec.whatwg.org/#readable-stream-pipe-to -GC::Ref readable_stream_pipe_to(ReadableStream& source, WritableStream& dest, bool, bool, bool, Optional signal) +GC::Ref readable_stream_pipe_to(ReadableStream& source, WritableStream& dest, bool, bool, bool, JS::Value signal) { auto& realm = source.realm(); @@ -299,11 +299,10 @@ GC::Ref readable_stream_pipe_to(ReadableStream& source, Writabl // 3. Assert: preventClose, preventAbort, and preventCancel are all booleans. // 4. If signal was not given, let signal be undefined. - if (!signal.has_value()) - signal = JS::js_undefined(); + // NOTE: Done by default argument // 5. Assert: either signal is undefined, or signal implements AbortSignal. - VERIFY(signal->is_undefined() || (signal->is_object() && is(signal->as_object()))); + VERIFY(signal.is_undefined() || (signal.is_object() && is(signal.as_object()))); // 6. Assert: ! IsReadableStreamLocked(source) is false. VERIFY(!is_readable_stream_locked(source)); diff --git a/Libraries/LibWeb/Streams/AbstractOperations.h b/Libraries/LibWeb/Streams/AbstractOperations.h index ec181944ffd..0e6595ab062 100644 --- a/Libraries/LibWeb/Streams/AbstractOperations.h +++ b/Libraries/LibWeb/Streams/AbstractOperations.h @@ -40,7 +40,7 @@ size_t readable_stream_get_num_read_requests(ReadableStream const&); bool readable_stream_has_byob_reader(ReadableStream const&); bool readable_stream_has_default_reader(ReadableStream const&); -GC::Ref readable_stream_pipe_to(ReadableStream& source, WritableStream& dest, bool prevent_close, bool prevent_abort, bool prevent_cancel, Optional signal); +GC::Ref readable_stream_pipe_to(ReadableStream& source, WritableStream& dest, bool prevent_close, bool prevent_abort, bool prevent_cancel, JS::Value signal = JS::js_undefined()); WebIDL::ExceptionOr readable_stream_tee(JS::Realm&, ReadableStream&, bool clone_for_branch2); WebIDL::ExceptionOr readable_stream_default_tee(JS::Realm& realm, ReadableStream& stream, bool clone_for_branch2); diff --git a/Libraries/LibWeb/Streams/ReadableStream.cpp b/Libraries/LibWeb/Streams/ReadableStream.cpp index 03510479307..0f02b12be9d 100644 --- a/Libraries/LibWeb/Streams/ReadableStream.cpp +++ b/Libraries/LibWeb/Streams/ReadableStream.cpp @@ -383,4 +383,20 @@ void ReadableStream::set_up_with_byte_reading_support(GC::Ptr pul MUST(set_up_readable_byte_stream_controller(*this, controller, start_algorithm, pull_algorithm_wrapper, cancel_algorithm_wrapper, high_water_mark, JS::js_undefined())); } +// https://streams.spec.whatwg.org/#readablestream-pipe-through +GC::Ref ReadableStream::piped_through(GC::Ref writable, bool prevent_close, bool prevent_abort, bool prevent_cancel, JS::Value signal) +{ + // 1. Assert: ! IsReadableStreamLocked(readable) is false. + VERIFY(!is_readable_stream_locked(*this)); + + // 2. Assert: ! IsWritableStreamLocked(writable) is false. + VERIFY(!is_writable_stream_locked(writable)); + + // 3. Let signalArg be signal if signal was given, or undefined otherwise. + // NOTE: Done by default arguments. + + // 4. Return ! ReadableStreamPipeTo(readable, writable, preventClose, preventAbort, preventCancel, signalArg). + return readable_stream_pipe_to(*this, writable, prevent_close, prevent_abort, prevent_cancel, signal); +} + } diff --git a/Libraries/LibWeb/Streams/ReadableStream.h b/Libraries/LibWeb/Streams/ReadableStream.h index 29d3418cc30..54be7a4abb7 100644 --- a/Libraries/LibWeb/Streams/ReadableStream.h +++ b/Libraries/LibWeb/Streams/ReadableStream.h @@ -108,6 +108,7 @@ public: WebIDL::ExceptionOr pull_from_bytes(ByteBuffer); WebIDL::ExceptionOr enqueue(JS::Value chunk); void set_up_with_byte_reading_support(GC::Ptr = {}, GC::Ptr = {}, double high_water_mark = 0); + GC::Ref piped_through(GC::Ref, bool prevent_close = false, bool prevent_abort = false, bool prevent_cancel = false, JS::Value signal = JS::js_undefined()); private: explicit ReadableStream(JS::Realm&);