mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibWeb: Add ReadableStreamGetReaderOptions to ReadableStream.getReader
Co-Authored-By: Matthew Olsson <mattco@serenityos.org>
This commit is contained in:
parent
729f4838c2
commit
0f040456a7
Notes:
sideshowbarker
2024-07-17 08:43:11 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/0f040456a7 Pull-request: https://github.com/SerenityOS/serenity/pull/19740 Reviewed-by: https://github.com/linusg Reviewed-by: https://github.com/mattco98 ✅
4 changed files with 26 additions and 8 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -93,14 +93,17 @@ WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> ReadableStream::cancel(JS::Value reas
|
|||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#rs-get-reader
|
||||
WebIDL::ExceptionOr<ReadableStreamReader> ReadableStream::get_reader()
|
||||
WebIDL::ExceptionOr<ReadableStreamReader> 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<void> ReadableStream::initialize(JS::Realm& realm)
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <AK/Forward.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/Bindings/ReadableStreamPrototype.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/Streams/QueuingStrategy.h>
|
||||
|
||||
|
@ -20,6 +21,11 @@ using ReadableStreamReader = Variant<JS::NonnullGCPtr<ReadableStreamDefaultReade
|
|||
// https://streams.spec.whatwg.org/#typedefdef-readablestreamcontroller
|
||||
using ReadableStreamController = Variant<JS::NonnullGCPtr<ReadableStreamDefaultController>, JS::NonnullGCPtr<ReadableByteStreamController>>;
|
||||
|
||||
// https://streams.spec.whatwg.org/#dictdef-readablestreamgetreaderoptions
|
||||
struct ReadableStreamGetReaderOptions {
|
||||
Optional<Bindings::ReadableStreamReaderMode> 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<JS::GCPtr<JS::Object>> cancel(JS::Value reason);
|
||||
WebIDL::ExceptionOr<ReadableStreamReader> get_reader();
|
||||
WebIDL::ExceptionOr<ReadableStreamReader> get_reader(ReadableStreamGetReaderOptions const& = {});
|
||||
|
||||
Optional<ReadableStreamController>& controller() { return m_controller; }
|
||||
void set_controller(Optional<ReadableStreamController> value) { m_controller = move(value); }
|
||||
|
|
|
@ -2,6 +2,14 @@
|
|||
#import <Streams/ReadableStreamBYOBReader.idl>
|
||||
#import <Streams/ReadableStreamDefaultReader.idl>
|
||||
|
||||
// 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<undefined> cancel(optional any reason);
|
||||
// FIXME: optional ReadableStreamGetReaderOptions options = {}
|
||||
ReadableStreamReader getReader();
|
||||
ReadableStreamReader getReader(optional ReadableStreamGetReaderOptions options = {});
|
||||
};
|
||||
|
||||
typedef (ReadableStreamDefaultReader or ReadableStreamBYOBReader) ReadableStreamReader;
|
||||
|
|
Loading…
Reference in a new issue