LibWeb: Add an 'enqueue' helper method on TransformStream

This commit is contained in:
Shannon Booth 2024-12-24 12:56:59 +13:00 committed by Andreas Kling
commit 5f2b75852f
Notes: github-actions[bot] 2024-12-25 11:03:07 +00:00
3 changed files with 10 additions and 2 deletions

View file

@ -133,7 +133,7 @@ WebIDL::ExceptionOr<void> DecompressionStream::decompress_and_enqueue_chunk(JS::
auto array = JS::Uint8Array::create(realm, array_buffer->byte_length(), *array_buffer); auto array = JS::Uint8Array::create(realm, array_buffer->byte_length(), *array_buffer);
// 5. For each Uint8Array array, enqueue array in ds's transform. // 5. For each Uint8Array array, enqueue array in ds's transform.
TRY(Streams::transform_stream_default_controller_enqueue(*m_transform->controller(), array)); m_transform->enqueue(array);
return {}; return {};
} }
@ -159,7 +159,7 @@ WebIDL::ExceptionOr<void> DecompressionStream::decompress_flush_and_enqueue()
auto array = JS::Uint8Array::create(realm, array_buffer->byte_length(), *array_buffer); auto array = JS::Uint8Array::create(realm, array_buffer->byte_length(), *array_buffer);
// 5. For each Uint8Array array, enqueue array in ds's transform. // 5. For each Uint8Array array, enqueue array in ds's transform.
TRY(Streams::transform_stream_default_controller_enqueue(*m_transform->controller(), array)); m_transform->enqueue(array);
return {}; return {};
} }

View file

@ -74,6 +74,13 @@ WebIDL::ExceptionOr<GC::Ref<TransformStream>> TransformStream::construct_impl(JS
return stream; return stream;
} }
// https://streams.spec.whatwg.org/#transformstream-enqueue
void TransformStream::enqueue(JS::Value chunk)
{
// To enqueue the JavaScript value chunk into a TransformStream stream, perform ! TransformStreamDefaultControllerEnqueue(stream.[[controller]], chunk).
MUST(Streams::transform_stream_default_controller_enqueue(*controller(), chunk));
}
// https://streams.spec.whatwg.org/#transformstream-set-up // https://streams.spec.whatwg.org/#transformstream-set-up
void TransformStream::set_up(GC::Ref<TransformAlgorithm> transform_algorithm, GC::Ptr<FlushAlgorithm> flush_algorithm, GC::Ptr<CancelAlgorithm> cancel_algorithm) void TransformStream::set_up(GC::Ref<TransformAlgorithm> transform_algorithm, GC::Ptr<FlushAlgorithm> flush_algorithm, GC::Ptr<CancelAlgorithm> cancel_algorithm)
{ {

View file

@ -42,6 +42,7 @@ public:
void set_controller(GC::Ptr<TransformStreamDefaultController> value) { m_controller = value; } void set_controller(GC::Ptr<TransformStreamDefaultController> value) { m_controller = value; }
void set_up(GC::Ref<TransformAlgorithm>, GC::Ptr<FlushAlgorithm> = {}, GC::Ptr<CancelAlgorithm> = {}); void set_up(GC::Ref<TransformAlgorithm>, GC::Ptr<FlushAlgorithm> = {}, GC::Ptr<CancelAlgorithm> = {});
void enqueue(JS::Value chunk);
private: private:
explicit TransformStream(JS::Realm& realm); explicit TransformStream(JS::Realm& realm);