From 1536d51c5c184602f6e0a640a562ef2458d04de1 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 14 Apr 2025 15:45:40 -0400 Subject: [PATCH] LibWeb: Perform writes during ReadableStreamPipeTo asynchronously I don't quite see what spec text requires this, but it is explicitly checked by WPT. We used to pass this test, but that regressed after commit 3c6010c663dddb78aa84b85e7a27307c4841a9dd. --- Libraries/LibWeb/Streams/AbstractOperations.cpp | 11 +++++++++-- .../streams/piping/general-addition.any.txt | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Libraries/LibWeb/Streams/AbstractOperations.cpp b/Libraries/LibWeb/Streams/AbstractOperations.cpp index fa157fa3b16..0db11dd9657 100644 --- a/Libraries/LibWeb/Streams/AbstractOperations.cpp +++ b/Libraries/LibWeb/Streams/AbstractOperations.cpp @@ -497,8 +497,15 @@ private: auto on_chunk = GC::create_function(heap(), [this](JS::Value chunk) { m_unwritten_chunks.append(chunk); - write_chunk(); - process(); + + if (check_for_error_and_close_states()) + return; + + HTML::queue_a_microtask(nullptr, GC::create_function(m_realm->heap(), [this]() { + HTML::TemporaryExecutionContext execution_context { m_realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + write_chunk(); + process(); + })); }); auto on_complete = GC::create_function(heap(), [this]() { diff --git a/Tests/LibWeb/Text/expected/wpt-import/streams/piping/general-addition.any.txt b/Tests/LibWeb/Text/expected/wpt-import/streams/piping/general-addition.any.txt index 384673a5c59..588d11c5969 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/streams/piping/general-addition.any.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/streams/piping/general-addition.any.txt @@ -2,5 +2,5 @@ Harness status: OK Found 1 tests -1 Fail -Fail enqueue() must not synchronously call write algorithm \ No newline at end of file +1 Pass +Pass enqueue() must not synchronously call write algorithm \ No newline at end of file