[WTF] Import std::optional reference implementation as WTF::Optional
[WebKit-https.git] / Source / WebCore / Modules / streams / ReadableStreamSource.h
index 617b27b..65919f2 100644 (file)
 
 namespace WebCore {
 
-typedef int ExceptionCode;
-
 class ReadableStreamSource : public RefCounted<ReadableStreamSource> {
 public:
     virtual ~ReadableStreamSource() { }
 
-    typedef DOMPromise<std::nullptr_t> Promise;
-
-    void start(ReadableStreamDefaultController&&, Promise&&);
-    void pull(Promise&&);
+    void start(ReadableStreamDefaultController&&, DOMPromise<void>&&);
+    void pull(DOMPromise<void>&&);
     void cancel(JSC::JSValue);
 
     bool isPulling() const { return !!m_promise; }
@@ -67,11 +63,11 @@ protected:
     virtual void doCancel() = 0;
 
 private:
-    Optional<Promise> m_promise;
-    Optional<ReadableStreamDefaultController> m_controller;
+    std::optional<DOMPromise<void>> m_promise;
+    std::optional<ReadableStreamDefaultController> m_controller;
 };
 
-inline void ReadableStreamSource::start(ReadableStreamDefaultController&& controller, Promise&& promise)
+inline void ReadableStreamSource::start(ReadableStreamDefaultController&& controller, DOMPromise<void>&& promise)
 {
     ASSERT(!m_promise);
     m_promise = WTFMove(promise);
@@ -81,7 +77,7 @@ inline void ReadableStreamSource::start(ReadableStreamDefaultController&& contro
     doStart();
 }
 
-inline void ReadableStreamSource::pull(Promise&& promise)
+inline void ReadableStreamSource::pull(DOMPromise<void>&& promise)
 {
     ASSERT(!m_promise);
     ASSERT(m_controller);
@@ -95,14 +91,14 @@ inline void ReadableStreamSource::pull(Promise&& promise)
 inline void ReadableStreamSource::startFinished()
 {
     ASSERT(m_promise);
-    std::exchange(m_promise, Nullopt).value().resolve(nullptr);
+    std::exchange(m_promise, std::nullopt).value().resolve();
     setInactive();
 }
 
 inline void ReadableStreamSource::pullFinished()
 {
     ASSERT(m_promise);
-    std::exchange(m_promise, Nullopt).value().resolve(nullptr);
+    std::exchange(m_promise, std::nullopt).value().resolve();
     setInactive();
 }
 
@@ -115,7 +111,7 @@ inline void ReadableStreamSource::cancel(JSC::JSValue)
 inline void ReadableStreamSource::clean()
 {
     if (m_promise) {
-        m_promise = Nullopt;
+        m_promise = std::nullopt;
         setInactive();
     }
 }