LibWeb: Close acquired writer in AO readable_stream_pipe_to()

Also adds a test to prove that the WritableStream's close callback is
called.
This commit is contained in:
Kenneth Myhra 2024-05-20 10:42:33 +02:00 committed by Tim Flynn
parent 15b677385c
commit e2c4019bfc
Notes: sideshowbarker 2024-07-16 23:55:09 +09:00
3 changed files with 29 additions and 2 deletions

View file

@ -0,0 +1 @@
Writer has been closed.

View file

@ -0,0 +1,20 @@
<script src="../include.js"></script>
<script>
asyncTest(done => {
const writableStream = new WritableStream({
close() {
println("Writer has been closed.");
}
}
);
const stream = new ReadableStream({
pull(controller) {
controller.close();
}
});
stream.pipeTo(writableStream).then(() => {
done();
});
});
</script>

View file

@ -314,11 +314,17 @@ JS::NonnullGCPtr<WebIDL::Promise> readable_stream_pipe_to(ReadableStream& source
WebIDL::resolve_promise(realm, promise, JS::js_undefined());
};
auto success_steps = [promise, &realm](ByteBuffer) {
auto success_steps = [promise, &realm, writer](ByteBuffer) {
// Make sure we close the acquired writer.
WebIDL::resolve_promise(realm, writable_stream_default_writer_close(*writer), JS::js_undefined());
WebIDL::resolve_promise(realm, promise, JS::js_undefined());
};
auto failure_steps = [promise, &realm](JS::Value error) {
auto failure_steps = [promise, &realm, writer](JS::Value error) {
// Make sure we close the acquired writer.
WebIDL::resolve_promise(realm, writable_stream_default_writer_close(*writer), JS::js_undefined());
WebIDL::reject_promise(realm, promise, error);
};