summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorMatthew Olsson <matthewcolsson@gmail.com>2023-04-08 06:31:36 -0700
committerLinus Groh <mail@linusgroh.de>2023-04-14 13:03:34 +0200
commitc97f6b7701d87029658b757eff77315d21650ab1 (patch)
treeff24d8c4b677bb28e9c30e4b5dfcc047870d760e /Userland
parent82749063012e017c14ae8b65da63666633f7e2d9 (diff)
downloadserenity-c97f6b7701d87029658b757eff77315d21650ab1.zip
LibWeb: Implement ReadableByteStreamController.[[CancelSteps]]
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp38
-rw-r--r--Userland/Libraries/LibWeb/Streams/AbstractOperations.h3
-rw-r--r--Userland/Libraries/LibWeb/Streams/ReadableByteStreamController.cpp19
-rw-r--r--Userland/Libraries/LibWeb/Streams/ReadableByteStreamController.h2
-rw-r--r--Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.h6
5 files changed, 68 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp
index 3d5e9ff109..0a7447c113 100644
--- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp
+++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp
@@ -12,6 +12,7 @@
#include <LibWeb/Streams/AbstractOperations.h>
#include <LibWeb/Streams/ReadableByteStreamController.h>
#include <LibWeb/Streams/ReadableStream.h>
+#include <LibWeb/Streams/ReadableStreamBYOBRequest.h>
#include <LibWeb/Streams/ReadableStreamDefaultController.h>
#include <LibWeb/Streams/ReadableStreamDefaultReader.h>
#include <LibWeb/Streams/ReadableStreamGenericReader.h>
@@ -744,6 +745,26 @@ WebIDL::ExceptionOr<void> set_up_readable_stream_default_controller_from_underly
return set_up_readable_stream_default_controller(stream, controller, move(start_algorithm), move(pull_algorithm), move(cancel_algorithm), high_water_mark, move(size_algorithm));
}
+// https://streams.spec.whatwg.org/#readable-byte-stream-controller-clear-algorithms
+void readable_byte_stream_controller_clear_algorithms(ReadableByteStreamController& controller)
+{
+ // 1. Set controller.[[pullAlgorithm]] to undefined.
+ controller.set_pull_algorithm({});
+
+ // 2. Set controller.[[cancelAlgorithm]] to undefined.
+ controller.set_cancel_algorithm({});
+}
+
+// https://streams.spec.whatwg.org/#readable-byte-stream-controller-clear-pending-pull-intos
+void readable_byte_stream_controller_clear_pending_pull_intos(ReadableByteStreamController& controller)
+{
+ // 1. Perform ! ReadableByteStreamControllerInvalidateBYOBRequest(controller).
+ readable_byte_stream_controller_invalidate_byob_request(controller);
+
+ // 2. Set controller.[[pendingPullIntos]] to a new empty list.
+ controller.pending_pull_intos().clear();
+}
+
// https://streams.spec.whatwg.org/#readable-byte-stream-controller-get-desired-size
Optional<double> readable_byte_stream_controller_get_desired_size(ReadableByteStreamController const& controller)
{
@@ -762,6 +783,23 @@ Optional<double> readable_byte_stream_controller_get_desired_size(ReadableByteSt
return controller.strategy_hwm() - controller.queue_total_size();
}
+// https://streams.spec.whatwg.org/#readable-byte-stream-controller-invalidate-byob-request
+void readable_byte_stream_controller_invalidate_byob_request(ReadableByteStreamController& controller)
+{
+ // 1. If controller.[[byobRequest]] is null, return.
+ if (!controller.byob_request())
+ return;
+
+ // 2. Set controller.[[byobRequest]].[[controller]] to undefined.
+ controller.byob_request()->set_controller({});
+
+ // 3. Set controller.[[byobRequest]].[[view]] to null.
+ controller.byob_request()->set_view({});
+
+ // 4. Set controller.[[byobRequest]] to null.
+ controller.set_byob_request({});
+}
+
// https://streams.spec.whatwg.org/#acquire-writable-stream-default-writer
WebIDL::ExceptionOr<JS::NonnullGCPtr<WritableStreamDefaultWriter>> acquire_writable_stream_default_writer(WritableStream& stream)
{
diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.h b/Userland/Libraries/LibWeb/Streams/AbstractOperations.h
index 13b696b6be..084b60a193 100644
--- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.h
+++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.h
@@ -53,7 +53,10 @@ bool readable_stream_default_controller_can_close_or_enqueue(ReadableStreamDefau
WebIDL::ExceptionOr<void> set_up_readable_stream_default_controller(ReadableStream&, ReadableStreamDefaultController&, StartAlgorithm&&, PullAlgorithm&&, CancelAlgorithm&&, double high_water_mark, SizeAlgorithm&&);
WebIDL::ExceptionOr<void> set_up_readable_stream_default_controller_from_underlying_source(ReadableStream&, JS::Value underlying_source_value, UnderlyingSource, double high_water_mark, SizeAlgorithm&&);
+void readable_byte_stream_controller_clear_algorithms(ReadableByteStreamController&);
+void readable_byte_stream_controller_clear_pending_pull_intos(ReadableByteStreamController&);
Optional<double> readable_byte_stream_controller_get_desired_size(ReadableByteStreamController const&);
+void readable_byte_stream_controller_invalidate_byob_request(ReadableByteStreamController&);
WebIDL::ExceptionOr<JS::NonnullGCPtr<WritableStreamDefaultWriter>> acquire_writable_stream_default_writer(WritableStream&);
bool is_writable_stream_locked(WritableStream const&);
diff --git a/Userland/Libraries/LibWeb/Streams/ReadableByteStreamController.cpp b/Userland/Libraries/LibWeb/Streams/ReadableByteStreamController.cpp
index bcaa70c273..0b6d175f63 100644
--- a/Userland/Libraries/LibWeb/Streams/ReadableByteStreamController.cpp
+++ b/Userland/Libraries/LibWeb/Streams/ReadableByteStreamController.cpp
@@ -22,6 +22,25 @@ ReadableByteStreamController::ReadableByteStreamController(JS::Realm& realm)
{
}
+// https://streams.spec.whatwg.org/#rbs-controller-private-cancel
+WebIDL::ExceptionOr<JS::GCPtr<WebIDL::Promise>> ReadableByteStreamController::cancel_steps(JS::Value reason)
+{
+ // 1. Perform ! ReadableByteStreamControllerClearPendingPullIntos(this).
+ readable_byte_stream_controller_clear_pending_pull_intos(*this);
+
+ // 2. Perform ! ResetQueue(this).
+ reset_queue(*this);
+
+ // 3. Let result be the result of performing this.[[cancelAlgorithm]], passing in reason.
+ auto result = (*m_cancel_algorithm)(reason);
+
+ // 4. Perform ! ReadableByteStreamControllerClearAlgorithms(this).
+ readable_byte_stream_controller_clear_algorithms(*this);
+
+ // 5. Return result.
+ return result;
+}
+
void ReadableByteStreamController::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
diff --git a/Userland/Libraries/LibWeb/Streams/ReadableByteStreamController.h b/Userland/Libraries/LibWeb/Streams/ReadableByteStreamController.h
index fd04225bff..6efaf898de 100644
--- a/Userland/Libraries/LibWeb/Streams/ReadableByteStreamController.h
+++ b/Userland/Libraries/LibWeb/Streams/ReadableByteStreamController.h
@@ -116,6 +116,8 @@ public:
JS::GCPtr<ReadableStream> stream() { return m_stream; }
void set_stream(JS::GCPtr<ReadableStream> stream) { m_stream = stream; }
+ WebIDL::ExceptionOr<JS::GCPtr<WebIDL::Promise>> cancel_steps(JS::Value reason);
+
private:
explicit ReadableByteStreamController(JS::Realm&);
diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.h b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.h
index 29b74d24e0..594cf66efe 100644
--- a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.h
+++ b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.h
@@ -8,6 +8,8 @@
#include <LibJS/Runtime/TypedArray.h>
#include <LibWeb/Bindings/PlatformObject.h>
+#include <LibWeb/Forward.h>
+#include <LibWeb/Streams/ReadableByteStreamController.h>
namespace Web::Streams {
@@ -20,6 +22,10 @@ public:
JS::GCPtr<JS::TypedArrayBase> view();
+ void set_controller(JS::GCPtr<ReadableByteStreamController> value) { m_controller = value; }
+
+ void set_view(JS::GCPtr<JS::TypedArrayBase> value) { m_view = value; }
+
private:
explicit ReadableStreamBYOBRequest(JS::Realm&);