1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:07:34 +00:00

LibWeb: Implement AO ReadableByteStreamControllerRespondInClosedState

This commit is contained in:
Shannon Booth 2023-12-02 21:15:44 +13:00 committed by Andreas Kling
parent be2195cb8c
commit 426cbd8ed3
2 changed files with 27 additions and 0 deletions

View file

@ -1159,6 +1159,32 @@ WebIDL::ExceptionOr<void> readable_byte_stream_controller_respond_in_readable_st
return {};
}
// https://streams.spec.whatwg.org/#readable-byte-stream-controller-respond-in-closed-state
void readable_byte_stream_controller_respond_in_closed_state(ReadableByteStreamController& controller, PullIntoDescriptor& first_descriptor)
{
// 1. Assert: the remainder after dividing firstDescriptors bytes filled by firstDescriptors element size is 0.
VERIFY(first_descriptor.bytes_filled % first_descriptor.element_size == 0);
// 2. If firstDescriptors reader type is "none", perform ! ReadableByteStreamControllerShiftPendingPullInto(controller).
if (first_descriptor.reader_type == ReaderType::None)
readable_byte_stream_controller_shift_pending_pull_into(controller);
// 3. Let stream be controller.[[stream]].
auto& stream = *controller.stream();
// 4. If ! ReadableStreamHasBYOBReader(stream) is true,
if (readable_stream_has_default_reader(stream)) {
// 1. While ! ReadableStreamGetNumReadIntoRequests(stream) > 0,
while (readable_stream_get_num_read_requests(stream) > 0) {
// 1. Let pullIntoDescriptor be ! ReadableByteStreamControllerShiftPendingPullInto(controller).
auto pull_into_descriptor = readable_byte_stream_controller_shift_pending_pull_into(controller);
// 2. Perform ! ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor).
readable_byte_stream_controller_commit_pull_into_descriptor(stream, pull_into_descriptor);
}
}
}
// https://streams.spec.whatwg.org/#readable-stream-default-controller-error
void readable_stream_default_controller_error(ReadableStreamDefaultController& controller, JS::Value error)
{

View file

@ -81,6 +81,7 @@ WebIDL::ExceptionOr<void> set_up_readable_byte_stream_controller_from_underlying
JS::GCPtr<ReadableStreamBYOBRequest> readable_byte_stream_controller_get_byob_request(JS::NonnullGCPtr<ReadableByteStreamController>);
WebIDL::ExceptionOr<void> readable_byte_stream_controller_respond_in_readable_state(ReadableByteStreamController&, u64 bytes_written, PullIntoDescriptor&);
void readable_byte_stream_controller_respond_in_closed_state(ReadableByteStreamController&, PullIntoDescriptor&);
WebIDL::ExceptionOr<void> readable_stream_enqueue(ReadableStreamController& controller, JS::Value chunk);
WebIDL::ExceptionOr<void> readable_byte_stream_controller_enqueue(ReadableByteStreamController& controller, JS::Value chunk);