summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp18
-rw-r--r--Userland/Libraries/LibWeb/Streams/AbstractOperations.h2
-rw-r--r--Userland/Libraries/LibWeb/Streams/ReadableStream.cpp3
-rw-r--r--Userland/Libraries/LibWeb/Streams/ReadableStream.h9
-rw-r--r--Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultController.cpp3
-rw-r--r--Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultController.h2
-rw-r--r--Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultReader.cpp2
7 files changed, 23 insertions, 16 deletions
diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp
index 376dea300e..4e6844bf35 100644
--- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp
+++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp
@@ -84,7 +84,9 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> readable_stream_cancel(Re
(void)reader;
// 7. Let sourceCancelPromise be ! stream.[[controller]].[[CancelSteps]](reason).
- auto source_cancel_promise = MUST(stream.controller()->cancel_steps(reason));
+ auto source_cancel_promise = TRY(stream.controller()->visit([&](auto const& controller) {
+ return controller->cancel_steps(reason);
+ }));
// 8. Return the result of reacting to sourceCancelPromise with a fulfillment step that returns undefined.
auto react_result = WebIDL::react_to_promise(*source_cancel_promise,
@@ -319,7 +321,7 @@ WebIDL::ExceptionOr<void> readable_stream_reader_generic_release(ReadableStreamG
WebIDL::mark_promise_as_handled(*reader.closed_promise_capability());
// 7. Perform ! stream.[[controller]].[[ReleaseSteps]]().
- stream->controller()->release_steps();
+ TRY(stream->controller()->visit([](auto const& controller) { return controller->release_steps(); }));
// 8. Set stream.[[reader]] to undefined.
stream->set_reader({});
@@ -345,7 +347,7 @@ void readable_stream_default_reader_error_read_requests(ReadableStreamDefaultRea
}
// https://streams.spec.whatwg.org/#readable-stream-default-reader-read
-void readable_stream_default_reader_read(ReadableStreamDefaultReader& reader, ReadRequest& read_request)
+WebIDL::ExceptionOr<void> readable_stream_default_reader_read(ReadableStreamDefaultReader& reader, ReadRequest& read_request)
{
// 1. Let stream be reader.[[stream]].
auto stream = reader.stream();
@@ -370,8 +372,12 @@ void readable_stream_default_reader_read(ReadableStreamDefaultReader& reader, Re
VERIFY(stream->is_readable());
// 2. Perform ! stream.[[controller]].[[PullSteps]](readRequest).
- MUST(stream->controller()->pull_steps(read_request));
+ TRY(stream->controller()->visit([&](auto const& controller) {
+ return controller->pull_steps(read_request);
+ }));
}
+
+ return {};
}
// https://streams.spec.whatwg.org/#abstract-opdef-readablestreamdefaultreaderrelease
@@ -635,7 +641,7 @@ WebIDL::ExceptionOr<void> set_up_readable_stream_default_controller(ReadableStre
auto& realm = stream.realm();
// 1. Assert: stream.[[controller]] is undefined.
- VERIFY(!stream.controller());
+ VERIFY(!stream.controller().has_value());
// 2. Set controller.[[stream]] to stream.
controller.set_stream(stream);
@@ -660,7 +666,7 @@ WebIDL::ExceptionOr<void> set_up_readable_stream_default_controller(ReadableStre
controller.set_cancel_algorithm(move(cancel_algorithm));
// 8. Set stream.[[controller]] to controller.
- stream.set_controller(controller);
+ stream.set_controller(ReadableStreamController { controller });
// 9. Let startResult be the result of performing startAlgorithm. (This might throw an exception.)
auto start_result = TRY(start_algorithm());
diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.h b/Userland/Libraries/LibWeb/Streams/AbstractOperations.h
index 47a935bb47..229e6ef0b0 100644
--- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.h
+++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.h
@@ -38,7 +38,7 @@ void readable_stream_reader_generic_initialize(ReadableStreamGenericReaderMixin&
WebIDL::ExceptionOr<void> readable_stream_reader_generic_release(ReadableStreamGenericReaderMixin&);
void readable_stream_default_reader_error_read_requests(ReadableStreamDefaultReader&, JS::Value error);
-void readable_stream_default_reader_read(ReadableStreamDefaultReader&, ReadRequest&);
+WebIDL::ExceptionOr<void> readable_stream_default_reader_read(ReadableStreamDefaultReader&, ReadRequest&);
WebIDL::ExceptionOr<void> readable_stream_default_reader_release(ReadableStreamDefaultReader&);
WebIDL::ExceptionOr<void> set_up_readable_stream_default_reader(ReadableStreamDefaultReader&, ReadableStream&);
void readable_stream_default_controller_close(ReadableStreamDefaultController&);
diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp b/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp
index ea6e66a519..ef321ad4cb 100644
--- a/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp
+++ b/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp
@@ -7,6 +7,7 @@
#include <LibJS/Runtime/PromiseCapability.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Streams/AbstractOperations.h>
+#include <LibWeb/Streams/ReadableByteStreamController.h>
#include <LibWeb/Streams/ReadableStream.h>
#include <LibWeb/Streams/ReadableStreamDefaultController.h>
#include <LibWeb/Streams/ReadableStreamDefaultReader.h>
@@ -107,7 +108,7 @@ JS::ThrowCompletionOr<void> ReadableStream::initialize(JS::Realm& realm)
void ReadableStream::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
- visitor.visit(m_controller);
+ m_controller->visit([&](auto& controller) { visitor.visit(controller); });
visitor.visit(m_stored_error);
visitor.visit(m_reader);
}
diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStream.h b/Userland/Libraries/LibWeb/Streams/ReadableStream.h
index ca101904a0..8ee92c1c4e 100644
--- a/Userland/Libraries/LibWeb/Streams/ReadableStream.h
+++ b/Userland/Libraries/LibWeb/Streams/ReadableStream.h
@@ -17,9 +17,8 @@ namespace Web::Streams {
// https://streams.spec.whatwg.org/#typedefdef-readablestreamreader
using ReadableStreamReader = JS::GCPtr<ReadableStreamDefaultReader>;
-// FIXME: Variant<DefaultController, ByteStreamController>
// https://streams.spec.whatwg.org/#typedefdef-readablestreamcontroller
-using ReadableStreamController = JS::GCPtr<ReadableStreamDefaultController>;
+using ReadableStreamController = Variant<JS::NonnullGCPtr<ReadableStreamDefaultController>, JS::NonnullGCPtr<ReadableByteStreamController>>;
// https://streams.spec.whatwg.org/#readablestream
class ReadableStream final : public Bindings::PlatformObject {
@@ -40,8 +39,8 @@ public:
WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> cancel(JS::Value view);
WebIDL::ExceptionOr<ReadableStreamReader> get_reader();
- ReadableStreamController controller() { return m_controller; }
- void set_controller(ReadableStreamController value) { m_controller = value; }
+ Optional<ReadableStreamController>& controller() { return m_controller; }
+ void set_controller(Optional<ReadableStreamController> value) { m_controller = move(value); }
JS::Value stored_error() const { return m_stored_error; }
void set_stored_error(JS::Value value) { m_stored_error = value; }
@@ -68,7 +67,7 @@ private:
// https://streams.spec.whatwg.org/#readablestream-controller
// A ReadableStreamDefaultController or ReadableByteStreamController created with the ability to control the state and queue of this stream
- ReadableStreamController m_controller;
+ Optional<ReadableStreamController> m_controller;
// https://streams.spec.whatwg.org/#readablestream-detached
// A boolean flag set to true when the stream is transferred
diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultController.cpp b/Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultController.cpp
index e0c20b6b8e..07422c9655 100644
--- a/Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultController.cpp
+++ b/Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultController.cpp
@@ -118,9 +118,10 @@ WebIDL::ExceptionOr<void> ReadableStreamDefaultController::pull_steps(Web::Strea
}
// https://streams.spec.whatwg.org/#abstract-opdef-readablestreamdefaultcontroller-releasesteps
-void ReadableStreamDefaultController::release_steps()
+WebIDL::ExceptionOr<void> ReadableStreamDefaultController::release_steps()
{
// 1. Return.
+ return {};
}
JS::ThrowCompletionOr<void> ReadableStreamDefaultController::initialize(JS::Realm& realm)
diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultController.h b/Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultController.h
index d731d19f14..e2deea907d 100644
--- a/Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultController.h
+++ b/Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultController.h
@@ -65,7 +65,7 @@ public:
WebIDL::ExceptionOr<JS::GCPtr<WebIDL::Promise>> cancel_steps(JS::Value reason);
WebIDL::ExceptionOr<void> pull_steps(ReadRequest&);
- void release_steps();
+ WebIDL::ExceptionOr<void> release_steps();
private:
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultReader.cpp b/Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultReader.cpp
index 271314db6e..c0124bef08 100644
--- a/Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultReader.cpp
+++ b/Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultReader.cpp
@@ -102,7 +102,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> ReadableStreamDefaultReader::
auto read_request = adopt_ref(*new DefaultReaderReadRequest(realm, promise_capability));
// 4. Perform ! ReadableStreamDefaultReaderRead(this, readRequest).
- readable_stream_default_reader_read(*this, read_request);
+ TRY(readable_stream_default_reader_read(*this, read_request));
// 5. Return promise.
return JS::NonnullGCPtr { verify_cast<JS::Promise>(*promise_capability->promise()) };