Parcourir la source

LibWeb: Capture incoming reason argument

Capture the incoming reason argument to
transform_stream_default_source_cancel_algorithm() on the
on_fulfilled_callback() of WebIDL::react_to_promise() on step 7.
Kenneth Myhra il y a 10 mois
Parent
commit
26fe7a628c

+ 3 - 0
Tests/LibWeb/Text/expected/Streams/TransformStream-readable-cancel.txt

@@ -0,0 +1,3 @@
+catch Error: error1
+catch Error: error1
+catch Error: error1

+ 22 - 0
Tests/LibWeb/Text/input/Streams/TransformStream-readable-cancel.html

@@ -0,0 +1,22 @@
+<script src="../include.js"></script>
+<script>
+    test(() => {
+        const ts = new TransformStream();
+        ts.readable.cancel(new Error("error1"));
+        ts.writable.getWriter().closed.catch(e => {
+            println(`catch ${e}`);
+        });
+
+        const tsWithBackpressure = new TransformStream({}, undefined, { highWaterMark: 0 });
+        tsWithBackpressure.readable.cancel(new Error("error1"))
+        tsWithBackpressure.writable.getWriter().closed.catch(e => {
+            println(`catch ${e}`)
+        })
+
+        const tsWithoutBackpressure = new TransformStream({}, undefined, { highWaterMark: 1 });
+        tsWithoutBackpressure.readable.cancel(new Error("error1"))
+        tsWithoutBackpressure.writable.getWriter().closed.catch(e => {
+            println(`catch ${e}`)
+        })
+    });
+</script>

+ 1 - 1
Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp

@@ -5168,7 +5168,7 @@ JS::NonnullGCPtr<WebIDL::Promise> transform_stream_default_source_cancel_algorit
     WebIDL::react_to_promise(
     WebIDL::react_to_promise(
         *cancel_promise,
         *cancel_promise,
         // 1. If cancelPromise was fulfilled, then:
         // 1. If cancelPromise was fulfilled, then:
-        JS::create_heap_function(realm.heap(), [&realm, writable, controller, &stream](JS::Value reason) -> WebIDL::ExceptionOr<JS::Value> {
+        JS::create_heap_function(realm.heap(), [&realm, writable, controller, &stream, reason](JS::Value) -> WebIDL::ExceptionOr<JS::Value> {
             // 1. If writable.[[state]] is "errored", reject controller.[[finishPromise]] with writable.[[storedError]].
             // 1. If writable.[[state]] is "errored", reject controller.[[finishPromise]] with writable.[[storedError]].
             if (writable->state() == WritableStream::State::Errored) {
             if (writable->state() == WritableStream::State::Errored) {
                 WebIDL::reject_promise(realm, *controller->finish_promise(), writable->stored_error());
                 WebIDL::reject_promise(realm, *controller->finish_promise(), writable->stored_error());