فهرست منبع

LibWeb: Implement the Streams SetUpReadableStreamBYOBReader AO

Co-Authored-By: Matthew Olsson <mattco@serenityos.org>
Shannon Booth 2 سال پیش
والد
کامیت
9ccadf61a2
2فایلهای تغییر یافته به همراه21 افزوده شده و 0 حذف شده
  1. 20 0
      Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp
  2. 1 0
      Userland/Libraries/LibWeb/Streams/AbstractOperations.h

+ 20 - 0
Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp

@@ -481,6 +481,26 @@ WebIDL::ExceptionOr<void> set_up_readable_stream_default_reader(ReadableStreamDe
     return {};
     return {};
 }
 }
 
 
+// https://streams.spec.whatwg.org/#set-up-readable-stream-byob-reader
+WebIDL::ExceptionOr<void> set_up_readable_stream_byob_reader(ReadableStreamBYOBReader& reader, ReadableStream& stream)
+{
+    // 1. If ! IsReadableStreamLocked(stream) is true, throw a TypeError exception.
+    if (is_readable_stream_locked(stream))
+        return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Cannot create stream reader for a locked stream"sv };
+
+    // 2. If stream.[[controller]] does not implement ReadableByteStreamController, throw a TypeError exception.
+    if (!stream.controller()->has<JS::NonnullGCPtr<ReadableByteStreamController>>())
+        return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "BYOB reader cannot set up reader from non-byte stream"sv };
+
+    // 3. Perform ! ReadableStreamReaderGenericInitialize(reader, stream).
+    readable_stream_reader_generic_initialize(ReadableStreamReader { reader }, stream);
+
+    // 4. Set reader.[[readIntoRequests]] to a new empty list.
+    reader.read_into_requests().clear();
+
+    return {};
+}
+
 // https://streams.spec.whatwg.org/#readable-stream-default-controller-close
 // https://streams.spec.whatwg.org/#readable-stream-default-controller-close
 void readable_stream_default_controller_close(ReadableStreamDefaultController& controller)
 void readable_stream_default_controller_close(ReadableStreamDefaultController& controller)
 {
 {

+ 1 - 0
Userland/Libraries/LibWeb/Streams/AbstractOperations.h

@@ -49,6 +49,7 @@ void readable_stream_default_reader_error_read_requests(ReadableStreamDefaultRea
 WebIDL::ExceptionOr<void> readable_stream_default_reader_read(ReadableStreamDefaultReader&, ReadRequest&);
 WebIDL::ExceptionOr<void> readable_stream_default_reader_read(ReadableStreamDefaultReader&, ReadRequest&);
 WebIDL::ExceptionOr<void> readable_stream_default_reader_release(ReadableStreamDefaultReader&);
 WebIDL::ExceptionOr<void> readable_stream_default_reader_release(ReadableStreamDefaultReader&);
 WebIDL::ExceptionOr<void> set_up_readable_stream_default_reader(ReadableStreamDefaultReader&, ReadableStream&);
 WebIDL::ExceptionOr<void> set_up_readable_stream_default_reader(ReadableStreamDefaultReader&, ReadableStream&);
+WebIDL::ExceptionOr<void> set_up_readable_stream_byob_reader(ReadableStreamBYOBReader&, ReadableStream&);
 void readable_stream_default_controller_close(ReadableStreamDefaultController&);
 void readable_stream_default_controller_close(ReadableStreamDefaultController&);
 WebIDL::ExceptionOr<void> readable_stream_default_controller_enqueue(ReadableStreamDefaultController&, JS::Value chunk);
 WebIDL::ExceptionOr<void> readable_stream_default_controller_enqueue(ReadableStreamDefaultController&, JS::Value chunk);
 WebIDL::ExceptionOr<void> readable_stream_default_controller_can_pull_if_needed(ReadableStreamDefaultController&);
 WebIDL::ExceptionOr<void> readable_stream_default_controller_can_pull_if_needed(ReadableStreamDefaultController&);