From 14437157753b633cc065ff617436f26469e125b2 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 19 Nov 2023 12:21:47 +1300 Subject: [PATCH] LibWeb: Add ReadableBSControllerProcessPullIntoDescriptorsUsingQueue --- .../LibWeb/Streams/AbstractOperations.cpp | 29 +++++++++++++++++++ .../LibWeb/Streams/AbstractOperations.h | 1 + 2 files changed, 30 insertions(+) diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp index 6d4e3c19d6..f59d1b7786 100644 --- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp +++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp @@ -1848,6 +1848,35 @@ void readable_byte_stream_controller_commit_pull_into_descriptor(ReadableStream& } } +// https://streams.spec.whatwg.org/#readable-byte-stream-controller-process-pull-into-descriptors-using-queue +void readable_byte_stream_controller_process_pull_into_descriptors_using_queue(ReadableByteStreamController& controller) +{ + // 1. Assert: controller.[[closeRequested]] is false. + VERIFY(!controller.close_requested()); + + // 2. While controller.[[pendingPullIntos]] is not empty, + while (!controller.pending_pull_intos().is_empty()) { + // 1. If controller.[[queueTotalSize]] is 0, return. + if (controller.queue_total_size() == 0) + return; + + // 2. Let pullIntoDescriptor be controller.[[pendingPullIntos]][0]. + auto& pull_into_descriptor = controller.pending_pull_intos().first(); + + // 3. If ! ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) is true, + if (readable_byte_stream_controller_fill_pull_into_descriptor_from_queue(controller, pull_into_descriptor)) { + // NOTE: We store the returned pull into descriptor here as the 'shift pending pull into' will remove + // the first entry into the list which we have a reference to above. + + // 1. Perform ! ReadableByteStreamControllerShiftPendingPullInto(controller). + auto descriptor = readable_byte_stream_controller_shift_pending_pull_into(controller); + + // 2. Perform ! ReadableByteStreamControllerCommitPullIntoDescriptor(controller.[[stream]], pullIntoDescriptor). + readable_byte_stream_controller_commit_pull_into_descriptor(*controller.stream(), descriptor); + } + } +} + // https://streams.spec.whatwg.org/#abstract-opdef-readablebytestreamcontrollerprocessreadrequestsusingqueue WebIDL::ExceptionOr readable_byte_stream_controller_process_read_requests_using_queue(ReadableByteStreamController& controller) { diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.h b/Userland/Libraries/LibWeb/Streams/AbstractOperations.h index 558861b19f..dd190e0525 100644 --- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.h +++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.h @@ -83,6 +83,7 @@ WebIDL::ExceptionOr> transfer_array_buffer(JS: WebIDL::ExceptionOr readable_byte_stream_controller_enqueue_detached_pull_into_queue(ReadableByteStreamController& controller, PullIntoDescriptor& pull_into_descriptor); void readable_byte_stream_controller_commit_pull_into_descriptor(ReadableStream&, PullIntoDescriptor const&); WebIDL::ExceptionOr readable_byte_stream_controller_process_read_requests_using_queue(ReadableByteStreamController& controller); +void readable_byte_stream_controller_process_pull_into_descriptors_using_queue(ReadableByteStreamController&); void readable_byte_stream_controller_enqueue_chunk_to_queue(ReadableByteStreamController& controller, JS::NonnullGCPtr buffer, u32 byte_offset, u32 byte_length); WebIDL::ExceptionOr readable_byte_stream_controller_enqueue_cloned_chunk_to_queue(ReadableByteStreamController& controller, JS::ArrayBuffer& buffer, u64 byte_offset, u64 byte_length); PullIntoDescriptor readable_byte_stream_controller_shift_pending_pull_into(ReadableByteStreamController& controller);