From 11c060072914af3a93f2b08bfa9b3891e60e163a Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Fri, 7 Jul 2023 21:44:19 +0200 Subject: [PATCH] LibWeb: Add AO transform_stream_default_controller_perform_transform() --- .../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 3f3b7f2d7c..a28b83af22 100644 --- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp +++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp @@ -2823,6 +2823,28 @@ WebIDL::ExceptionOr transform_stream_default_controller_terminate(Transfor return {}; } +// https://streams.spec.whatwg.org/#transform-stream-default-controller-perform-transform +WebIDL::ExceptionOr> transform_stream_default_controller_perform_transform(TransformStreamDefaultController& controller, JS::Value chunk) +{ + auto& realm = controller.realm(); + + // 1. Let transformPromise be the result of performing controller.[[transformAlgorithm]], passing chunk. + auto transform_promise = TRY((*controller.transform_algorithm())(chunk)); + + // 2. Return the result of reacting to transformPromise with the following rejection steps given the argument r: + auto react_result = WebIDL::react_to_promise(*transform_promise, + {}, + [&](auto const& reason) -> WebIDL::ExceptionOr { + // 1. Perform ! TransformStreamError(controller.[[stream]], r). + TRY(transform_stream_error(*controller.stream(), reason)); + + // 2. Throw r. + return JS::throw_completion(reason); + }); + + return WebIDL::create_resolved_promise(realm, react_result); +} + // https://streams.spec.whatwg.org/#transform-stream-error WebIDL::ExceptionOr transform_stream_error(TransformStream& stream, JS::Value error) { diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.h b/Userland/Libraries/LibWeb/Streams/AbstractOperations.h index cca08b3f17..58128191a2 100644 --- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.h +++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.h @@ -137,6 +137,7 @@ void transform_stream_default_controller_clear_algorithms(TransformStreamDefault WebIDL::ExceptionOr transform_stream_default_controller_enqueue(TransformStreamDefaultController&, JS::Value chunk); WebIDL::ExceptionOr transform_stream_default_controller_error(TransformStreamDefaultController&, JS::Value error); WebIDL::ExceptionOr transform_stream_default_controller_terminate(TransformStreamDefaultController&); +WebIDL::ExceptionOr> transform_stream_default_controller_perform_transform(TransformStreamDefaultController&, JS::Value chunk); WebIDL::ExceptionOr transform_stream_error(TransformStream&, JS::Value error); WebIDL::ExceptionOr transform_stream_error_writable_and_unblock_write(TransformStream&, JS::Value error); WebIDL::ExceptionOr transform_stream_set_backpressure(TransformStream&, bool backpressure);