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

LibWeb: Add AO transform_stream_default_sink_close_algorithm()

This commit is contained in:
Kenneth Myhra 2023-07-07 22:16:40 +02:00 committed by Andreas Kling
parent 48921add86
commit 641b9edd89
2 changed files with 45 additions and 0 deletions

View file

@ -2857,6 +2857,50 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> transform_stream_default_
return WebIDL::create_resolved_promise(realm, JS::js_undefined());
}
// https://streams.spec.whatwg.org/#transform-stream-default-sink-close-algorithm
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> transform_stream_default_sink_close_algorithm(TransformStream& stream)
{
auto& realm = stream.realm();
// 1. Let readable be stream.[[readable]].
auto readable = stream.readable();
// 2. Let controller be stream.[[controller]].
auto controller = stream.controller();
// 3. Let flushPromise be the result of performing controller.[[flushAlgorithm]].
auto flush_promise = TRY((*controller->flush_algorithm())());
// 4. Perform ! TransformStreamDefaultControllerClearAlgorithms(controller).
transform_stream_default_controller_clear_algorithms(*controller);
// 5. Return the result of reacting to flushPromise:
auto react_result = WebIDL::react_to_promise(
*flush_promise,
// 1. If flushPromise was fulfilled, then:
[readable](auto const&) -> WebIDL::ExceptionOr<JS::Value> {
// 1. If readable.[[state]] is "errored", throw readable.[[storedError]].
if (readable->state() == ReadableStream::State::Errored)
return JS::throw_completion(readable->stored_error());
VERIFY(readable->controller().has_value() && readable->controller()->has<JS::NonnullGCPtr<ReadableStreamDefaultController>>());
// 2. Perform ! ReadableStreamDefaultControllerClose(readable.[[controller]]).
readable_stream_default_controller_close(readable->controller().value().get<JS::NonnullGCPtr<ReadableStreamDefaultController>>());
return JS::js_undefined();
},
// 2. If flushPromise was rejected with reason r, then:
[&stream, readable](auto const& reason) -> WebIDL::ExceptionOr<JS::Value> {
// 1. Perform ! TransformStreamError(stream, r).
TRY(transform_stream_error(stream, reason));
// 2. Throw readable.[[storedError]].
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, TRY(readable->stored_error().as_string().utf8_string_view()) };
});
return WebIDL::create_resolved_promise(realm, react_result);
}
// https://streams.spec.whatwg.org/#transform-stream-default-sink-write-algorithm
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> transform_stream_default_sink_write_algorithm(TransformStream& stream, JS::Value chunk)
{

View file

@ -139,6 +139,7 @@ WebIDL::ExceptionOr<void> transform_stream_default_controller_error(TransformStr
WebIDL::ExceptionOr<void> transform_stream_default_controller_terminate(TransformStreamDefaultController&);
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> transform_stream_default_controller_perform_transform(TransformStreamDefaultController&, JS::Value chunk);
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> transform_stream_default_sink_abort_algorithm(TransformStream&, JS::Value reason);
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> transform_stream_default_sink_close_algorithm(TransformStream&);
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> transform_stream_default_sink_write_algorithm(TransformStream&, JS::Value chunk);
WebIDL::ExceptionOr<void> transform_stream_error(TransformStream&, JS::Value error);
WebIDL::ExceptionOr<void> transform_stream_error_writable_and_unblock_write(TransformStream&, JS::Value error);