LibWeb: Add a 'piped through' helper method on ReadableStream

This reads a bit nicer, and follows the streams spec pattern on
performing operations on a stream outside of the streams spec.
This commit is contained in:
Shannon Booth 2024-12-24 12:25:01 +13:00 committed by Andreas Kling
parent 79a2b96d1c
commit da408cb09a
Notes: github-actions[bot] 2024-12-25 11:03:22 +00:00
5 changed files with 22 additions and 6 deletions

View file

@ -290,7 +290,7 @@ bool readable_stream_has_default_reader(ReadableStream const& stream)
}
// https://streams.spec.whatwg.org/#readable-stream-pipe-to
GC::Ref<WebIDL::Promise> readable_stream_pipe_to(ReadableStream& source, WritableStream& dest, bool, bool, bool, Optional<JS::Value> signal)
GC::Ref<WebIDL::Promise> readable_stream_pipe_to(ReadableStream& source, WritableStream& dest, bool, bool, bool, JS::Value signal)
{
auto& realm = source.realm();
@ -299,11 +299,10 @@ GC::Ref<WebIDL::Promise> 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<DOM::AbortSignal>(signal->as_object())));
VERIFY(signal.is_undefined() || (signal.is_object() && is<DOM::AbortSignal>(signal.as_object())));
// 6. Assert: ! IsReadableStreamLocked(source) is false.
VERIFY(!is_readable_stream_locked(source));