diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp index cfeb709ad7..3f3b7f2d7c 100644 --- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp +++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp @@ -2799,6 +2799,30 @@ WebIDL::ExceptionOr transform_stream_default_controller_error(TransformStr return {}; } +// https://streams.spec.whatwg.org/#transform-stream-default-controller-terminate +WebIDL::ExceptionOr transform_stream_default_controller_terminate(TransformStreamDefaultController& controller) +{ + auto& realm = controller.realm(); + + // 1. Let stream be controller.[[stream]]. + auto stream = controller.stream(); + + // 2. Let readableController be stream.[[readable]].[[controller]]. + VERIFY(stream->readable()->controller().has_value() && stream->readable()->controller()->has>()); + auto readable_controller = stream->readable()->controller()->get>(); + + // 3. Perform ! ReadableStreamDefaultControllerClose(readableController). + readable_stream_default_controller_close(readable_controller); + + // 4. Let error be a TypeError exception indicating that the stream has been terminated. + auto error = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Stream has been terminated."sv)); + + // 5. Perform ! TransformStreamErrorWritableAndUnblockWrite(stream, error). + TRY(transform_stream_error_writable_and_unblock_write(*stream, error)); + + return {}; +} + // 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 c7e4445fe4..cca08b3f17 100644 --- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.h +++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.h @@ -136,6 +136,7 @@ WebIDL::ExceptionOr writable_stream_default_controller_write(WritableStrea void transform_stream_default_controller_clear_algorithms(TransformStreamDefaultController&); 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_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);