From 91f58eb220ea8e6d26ca0fc01476ce95a1b33afe Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Fri, 7 Jul 2023 16:09:27 +0200 Subject: [PATCH] LibWeb: Add AO transform_stream_set_backpressure() --- .../LibWeb/Streams/AbstractOperations.cpp | 22 +++++++++++++++++++ .../LibWeb/Streams/AbstractOperations.h | 1 + 2 files changed, 23 insertions(+) diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp index 40f5bb17d6..8f299db1cc 100644 --- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp +++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -2733,6 +2734,27 @@ void transform_stream_default_controller_clear_algorithms(TransformStreamDefault controller.set_flush_algorithm({}); } +// https://streams.spec.whatwg.org/#transform-stream-set-backpressure +WebIDL::ExceptionOr transform_stream_set_backpressure(TransformStream& stream, bool backpressure) +{ + auto& realm = stream.realm(); + + // 1. Assert: stream.[[backpressure]] is not backpressure. + VERIFY(stream.backpressure() != backpressure); + + // 2. If stream.[[backpressureChangePromise]] is not undefined, resolve stream.[[backpressureChangePromise]] with undefined. + if (stream.backpressure_change_promise()) + WebIDL::resolve_promise(realm, *stream.backpressure_change_promise(), JS::js_undefined()); + + // 3. Set stream.[[backpressureChangePromise]] to a new promise. + stream.set_backpressure_change_promise(WebIDL::create_promise(realm)); + + // 4. Set stream.[[backpressure]] to backpressure. + stream.set_backpressure(backpressure); + + return {}; +} + // https://streams.spec.whatwg.org/#is-non-negative-number bool is_non_negative_number(JS::Value value) { diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.h b/Userland/Libraries/LibWeb/Streams/AbstractOperations.h index 2ff9e92f79..b01581b433 100644 --- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.h +++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.h @@ -133,6 +133,7 @@ WebIDL::ExceptionOr writable_stream_default_controller_process_write(Writa WebIDL::ExceptionOr writable_stream_default_controller_write(WritableStreamDefaultController&, JS::Value chunk, JS::Value chunk_size); void transform_stream_default_controller_clear_algorithms(TransformStreamDefaultController&); +WebIDL::ExceptionOr transform_stream_set_backpressure(TransformStream&, bool backpressure); bool is_non_negative_number(JS::Value);