diff --git a/Tests/LibWeb/Text/expected/Streams/ReadableStream-from-asyncIterator.txt b/Tests/LibWeb/Text/expected/Streams/ReadableStream-from-asyncIterator.txt new file mode 100644 index 00000000000..a6f7c83c32e --- /dev/null +++ b/Tests/LibWeb/Text/expected/Streams/ReadableStream-from-asyncIterator.txt @@ -0,0 +1,5 @@ +Well +Hello +Friends +! +🦬 diff --git a/Tests/LibWeb/Text/input/Streams/ReadableStream-from-asyncIterator.html b/Tests/LibWeb/Text/input/Streams/ReadableStream-from-asyncIterator.html new file mode 100644 index 00000000000..9d4a4a2ca5b --- /dev/null +++ b/Tests/LibWeb/Text/input/Streams/ReadableStream-from-asyncIterator.html @@ -0,0 +1,30 @@ + + diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp b/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp index 05afdd23e90..a5dc13cd196 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp +++ b/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp @@ -68,6 +68,13 @@ WebIDL::ExceptionOr> ReadableStream::construct_ return readable_stream; } +// https://streams.spec.whatwg.org/#rs-from +WebIDL::ExceptionOr> ReadableStream::from(JS::VM& vm, JS::Value async_iterable) +{ + // 1. Return ? ReadableStreamFromIterable(asyncIterable). + return TRY(readable_stream_from_iterable(vm, async_iterable)); +} + ReadableStream::ReadableStream(JS::Realm& realm) : PlatformObject(realm) { diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStream.h b/Userland/Libraries/LibWeb/Streams/ReadableStream.h index fbe57f104a2..ff9bcc0b573 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStream.h +++ b/Userland/Libraries/LibWeb/Streams/ReadableStream.h @@ -70,6 +70,8 @@ public: static WebIDL::ExceptionOr> construct_impl(JS::Realm&, Optional> const& underlying_source, QueuingStrategy const& = {}); + static WebIDL::ExceptionOr> from(JS::VM& vm, JS::Value async_iterable); + virtual ~ReadableStream() override; bool locked() const; diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStream.idl b/Userland/Libraries/LibWeb/Streams/ReadableStream.idl index f58795e6fd8..589c5c272b6 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStream.idl +++ b/Userland/Libraries/LibWeb/Streams/ReadableStream.idl @@ -29,7 +29,7 @@ dictionary ReadableStreamGetReaderOptions { interface ReadableStream { constructor(optional object underlyingSource, optional QueuingStrategy strategy = {}); - [FIXME] static ReadableStream from(any asyncIterable); + static ReadableStream from(any asyncIterable); readonly attribute boolean locked;