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

LibWeb: Implement ReadableByteStreamControllerConvertPullIntoDescriptor

This commit is contained in:
Shannon Booth 2023-11-19 11:54:46 +13:00 committed by Andreas Kling
parent 25f8b80eab
commit 26e393fbbc
2 changed files with 25 additions and 0 deletions

View file

@ -527,6 +527,30 @@ WebIDL::ExceptionOr<void> readable_stream_default_reader_read(ReadableStreamDefa
return {};
}
// https://streams.spec.whatwg.org/#readable-byte-stream-controller-convert-pull-into-descriptor
JS::Value readable_byte_stream_controller_convert_pull_into_descriptor(JS::Realm& realm, PullIntoDescriptor const& pull_into_descriptor)
{
auto& vm = realm.vm();
// 1. Let bytesFilled be pullIntoDescriptors bytes filled.
auto bytes_filled = pull_into_descriptor.bytes_filled;
// 2. Let elementSize be pullIntoDescriptors element size.
auto element_size = pull_into_descriptor.element_size;
// 3. Assert: bytesFilled ≤ pullIntoDescriptors byte length.
VERIFY(bytes_filled <= pull_into_descriptor.byte_length);
// 4. Assert: bytesFilled mod elementSize is 0.
VERIFY(bytes_filled % element_size == 0);
// 5. Let buffer be ! TransferArrayBuffer(pullIntoDescriptors buffer).
auto buffer = MUST(transfer_array_buffer(realm, pull_into_descriptor.buffer));
// 6. Return ! Construct(pullIntoDescriptors view constructor, « buffer, pullIntoDescriptors byte offset, bytesFilled ÷ elementSize »).
return MUST(JS::construct(vm, *pull_into_descriptor.view_constructor, buffer, JS::Value(pull_into_descriptor.byte_offset), JS::Value(bytes_filled / element_size)));
}
// https://streams.spec.whatwg.org/#abstract-opdef-readablestreamdefaultreaderrelease
WebIDL::ExceptionOr<void> readable_stream_default_reader_release(ReadableStreamDefaultReader& reader)
{