diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 8547a47bb9f..319fdb56ba8 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -33,6 +33,7 @@ enum class CanvasFillRule; enum class DOMParserSupportedType; enum class EndingType; enum class ImageSmoothingQuality; +enum class ReadableStreamReaderMode; enum class ReferrerPolicy; enum class RequestCache; enum class RequestCredentials; @@ -553,6 +554,7 @@ class WritableStreamDefaultWriter; struct PullIntoDescriptor; struct QueuingStrategy; struct QueuingStrategyInit; +struct ReadableStreamGetReaderOptions; struct UnderlyingSink; struct UnderlyingSource; } diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp b/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp index 1b88812e534..a9ffae89652 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp +++ b/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp @@ -93,14 +93,17 @@ WebIDL::ExceptionOr> ReadableStream::cancel(JS::Value reas } // https://streams.spec.whatwg.org/#rs-get-reader -WebIDL::ExceptionOr ReadableStream::get_reader() +WebIDL::ExceptionOr ReadableStream::get_reader(ReadableStreamGetReaderOptions const& options) { - // FIXME: // 1. If options["mode"] does not exist, return ? AcquireReadableStreamDefaultReader(this). - // 2. Assert: options["mode"] is "byob". - // 3. Return ? AcquireReadableStreamBYOBReader(this). + if (!options.mode.has_value()) + return TRY(acquire_readable_stream_default_reader(*this)); - return TRY(acquire_readable_stream_default_reader(*this)); + // 2. Assert: options["mode"] is "byob". + VERIFY(*options.mode == Bindings::ReadableStreamReaderMode::Byob); + + // 3. Return ? AcquireReadableStreamBYOBReader(this). + return TRY(acquire_readable_stream_byob_reader(*this)); } JS::ThrowCompletionOr ReadableStream::initialize(JS::Realm& realm) diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStream.h b/Userland/Libraries/LibWeb/Streams/ReadableStream.h index 5016c55cb99..425b552d6b4 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStream.h +++ b/Userland/Libraries/LibWeb/Streams/ReadableStream.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -20,6 +21,11 @@ using ReadableStreamReader = Variant, JS::NonnullGCPtr>; +// https://streams.spec.whatwg.org/#dictdef-readablestreamgetreaderoptions +struct ReadableStreamGetReaderOptions { + Optional mode; +}; + // https://streams.spec.whatwg.org/#readablestream class ReadableStream final : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(ReadableStream, Bindings::PlatformObject); @@ -37,7 +43,7 @@ public: bool locked() const; WebIDL::ExceptionOr> cancel(JS::Value reason); - WebIDL::ExceptionOr get_reader(); + WebIDL::ExceptionOr get_reader(ReadableStreamGetReaderOptions const& = {}); Optional& controller() { return m_controller; } void set_controller(Optional value) { m_controller = move(value); } diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStream.idl b/Userland/Libraries/LibWeb/Streams/ReadableStream.idl index 635feaebcfe..027980c7a24 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStream.idl +++ b/Userland/Libraries/LibWeb/Streams/ReadableStream.idl @@ -2,6 +2,14 @@ #import #import +// https://streams.spec.whatwg.org/#enumdef-readablestreamreadermode +enum ReadableStreamReaderMode { "byob" }; + +// https://streams.spec.whatwg.org/#dictdef-readablestreamgetreaderoptions +dictionary ReadableStreamGetReaderOptions { + ReadableStreamReaderMode mode; +}; + // https://streams.spec.whatwg.org/#readablestream [Exposed=*, Transferable] interface ReadableStream { @@ -10,8 +18,7 @@ interface ReadableStream { readonly attribute boolean locked; Promise cancel(optional any reason); - // FIXME: optional ReadableStreamGetReaderOptions options = {} - ReadableStreamReader getReader(); + ReadableStreamReader getReader(optional ReadableStreamGetReaderOptions options = {}); }; typedef (ReadableStreamDefaultReader or ReadableStreamBYOBReader) ReadableStreamReader;