Title: [220620] trunk/Source/WebCore
Revision
220620
Author
commit-qu...@webkit.org
Date
2017-08-11 17:32:03 -0700 (Fri, 11 Aug 2017)

Log Message

[Bindings] Simplify DOMPromiseProxy now that WTF::Function can return references
https://bugs.webkit.org/show_bug.cgi?id=175394

Patch by Sam Weinig <s...@webkit.org> on 2017-08-11
Reviewed by Chris Dumez.

* bindings/IDLTypes.h:
(WebCore::IDLWrapper::convertToParameterType): Deleted.

    Remove no longer used convertToParameterType.

* bindings/js/DOMPromiseProxy.h:

    - Replace Variant<Value, Exception> with ExceptionOr<Value> / ExceptionOr<void>.
    - Update ResolveCallback to have a return type of IDLType::ParameterType, rather than
      IDLType::ImplementationType, now that WTF::Function supports references as the
      return type. This is needed, since the IDLType::ParameterType for an interface T
      is T&.

* css/FontFace.cpp:
* css/FontFace.h:
* css/FontFaceSet.cpp:
* css/FontFaceSet.h:

    Update resolve callbacks to return a reference rather than a RefPtr, matching
    the new signature requirement.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (220619 => 220620)


--- trunk/Source/WebCore/ChangeLog	2017-08-12 00:07:00 UTC (rev 220619)
+++ trunk/Source/WebCore/ChangeLog	2017-08-12 00:32:03 UTC (rev 220620)
@@ -1,5 +1,33 @@
 2017-08-11  Sam Weinig  <s...@webkit.org>
 
+        [Bindings] Simplify DOMPromiseProxy now that WTF::Function can return references
+        https://bugs.webkit.org/show_bug.cgi?id=175394
+
+        Reviewed by Chris Dumez.
+
+        * bindings/IDLTypes.h:
+        (WebCore::IDLWrapper::convertToParameterType): Deleted.
+
+            Remove no longer used convertToParameterType.
+
+        * bindings/js/DOMPromiseProxy.h:
+
+            - Replace Variant<Value, Exception> with ExceptionOr<Value> / ExceptionOr<void>.
+            - Update ResolveCallback to have a return type of IDLType::ParameterType, rather than
+              IDLType::ImplementationType, now that WTF::Function supports references as the 
+              return type. This is needed, since the IDLType::ParameterType for an interface T
+              is T&.
+
+        * css/FontFace.cpp:
+        * css/FontFace.h:
+        * css/FontFaceSet.cpp:
+        * css/FontFaceSet.h:
+
+            Update resolve callbacks to return a reference rather than a RefPtr, matching
+            the new signature requirement.
+
+2017-08-11  Sam Weinig  <s...@webkit.org>
+
         [WebIDL] Replace JSCryptoKeyCustom and JSCryptoAlgorithmBuilder with generated code
         https://bugs.webkit.org/show_bug.cgi?id=175457
 

Modified: trunk/Source/WebCore/bindings/IDLTypes.h (220619 => 220620)


--- trunk/Source/WebCore/bindings/IDLTypes.h	2017-08-12 00:07:00 UTC (rev 220619)
+++ trunk/Source/WebCore/bindings/IDLTypes.h	2017-08-12 00:32:03 UTC (rev 220620)
@@ -170,8 +170,6 @@
     static inline std::nullptr_t nullValue() { return nullptr; }
     template<typename U> static inline bool isNullValue(U&& value) { return !value; }
     template<typename U> static inline U&& extractValueFromNullable(U&& value) { return std::forward<U>(value); }
-
-    static ParameterType convertToParameterType(RefPtr<T> value) { ASSERT(value); return *value.get(); }
 };
 
 template<typename T> struct IDLInterface : IDLWrapper<T> { };

Modified: trunk/Source/WebCore/bindings/js/DOMPromiseProxy.h (220619 => 220620)


--- trunk/Source/WebCore/bindings/js/DOMPromiseProxy.h	2017-08-12 00:07:00 UTC (rev 220619)
+++ trunk/Source/WebCore/bindings/js/DOMPromiseProxy.h	2017-08-12 00:32:03 UTC (rev 220620)
@@ -25,12 +25,11 @@
 
 #pragma once
 
-#include "Exception.h"
+#include "ExceptionOr.h"
 #include "JSDOMGlobalObject.h"
 #include "JSDOMPromiseDeferred.h"
 #include <wtf/Function.h>
 #include <wtf/Optional.h>
-#include <wtf/Variant.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
@@ -39,7 +38,6 @@
 class DOMPromiseProxy {
 public:
     using Value = typename IDLType::StorageType;
-    using ValueOrException = Variant<Value, Exception>;
 
     DOMPromiseProxy() = default;
     ~DOMPromiseProxy() = default;
@@ -55,7 +53,7 @@
     void reject(Exception);
     
 private:
-    std::optional<ValueOrException> m_valueOrException;
+    std::optional<ExceptionOr<Value>> m_valueOrException;
     Vector<Ref<DeferredPromise>, 1> m_deferredPromises;
 };
 
@@ -62,9 +60,6 @@
 template<>
 class DOMPromiseProxy<IDLVoid> {
 public:
-    using Value = bool;
-    using ValueOrException = Variant<Value, Exception>;
-
     DOMPromiseProxy() = default;
     ~DOMPromiseProxy() = default;
 
@@ -78,7 +73,7 @@
     void reject(Exception);
 
 private:
-    std::optional<ValueOrException> m_valueOrException;
+    std::optional<ExceptionOr<void>> m_valueOrException;
     Vector<Ref<DeferredPromise>, 1> m_deferredPromises;
 };
 
@@ -89,15 +84,10 @@
 template<typename IDLType>
 class DOMPromiseProxyWithResolveCallback {
 public:
-    using Value = bool;
-    using ValueOrException = Variant<Value, Exception>;
-    // FIXME: This should return a IDLType::ParameterType, but WTF::Function does
-    //        not support returning references / non-default initializable types.
-    //        See https://webkit.org/b/175244.
-    using ResolveCallback = WTF::Function<typename IDLType::ImplementationType ()>;
+    using ResolveCallback = WTF::Function<typename IDLType::ParameterType ()>;
 
     template <typename Class, typename BaseClass>
-    DOMPromiseProxyWithResolveCallback(Class&, typename IDLType::ImplementationType (BaseClass::*)());
+    DOMPromiseProxyWithResolveCallback(Class&, typename IDLType::ParameterType (BaseClass::*)());
     DOMPromiseProxyWithResolveCallback(ResolveCallback&&);
     ~DOMPromiseProxyWithResolveCallback() = default;
 
@@ -113,8 +103,7 @@
     
 private:
     ResolveCallback m_resolveCallback;
-
-    std::optional<ValueOrException> m_valueOrException;
+    std::optional<ExceptionOr<void>> m_valueOrException;
     Vector<Ref<DeferredPromise>, 1> m_deferredPromises;
 };
 
@@ -135,10 +124,10 @@
         return JSC::jsUndefined();
 
     if (m_valueOrException) {
-        if (WTF::holds_alternative<Value>(*m_valueOrException))
-            deferredPromise->template resolve<IDLType>(WTF::get<Value>(*m_valueOrException));
+        if (m_valueOrException->hasException())
+            deferredPromise->reject(m_valueOrException->exception());
         else
-            deferredPromise->reject(WTF::get<Exception>(*m_valueOrException));
+            deferredPromise->template resolve<IDLType>(m_valueOrException->returnValue());
     }
 
     auto result = deferredPromise->promise();
@@ -164,9 +153,9 @@
 {
     ASSERT(!m_valueOrException);
 
-    m_valueOrException = ValueOrException { std::forward<typename IDLType::ParameterType>(value) };
+    m_valueOrException = ExceptionOr<Value> { std::forward<typename IDLType::ParameterType>(value) };
     for (auto& deferredPromise : m_deferredPromises)
-        deferredPromise->template resolve<IDLType>(WTF::get<Value>(*m_valueOrException));
+        deferredPromise->template resolve<IDLType>(m_valueOrException->returnValue());
 }
 
 template<typename IDLType>
@@ -174,9 +163,9 @@
 {
     ASSERT(!m_valueOrException);
 
-    m_valueOrException = ValueOrException { std::forward<typename IDLType::ParameterType>(value) };
+    m_valueOrException = ExceptionOr<Value> { std::forward<typename IDLType::ParameterType>(value) };
     for (auto& deferredPromise : m_deferredPromises)
-        deferredPromise->template resolveWithNewlyCreated<IDLType>(WTF::get<Value>(*m_valueOrException));
+        deferredPromise->template resolveWithNewlyCreated<IDLType>(m_valueOrException->returnValue());
 }
 
 template<typename IDLType>
@@ -184,9 +173,9 @@
 {
     ASSERT(!m_valueOrException);
 
-    m_valueOrException = ValueOrException { WTFMove(exception) };
+    m_valueOrException = ExceptionOr<Value> { WTFMove(exception) };
     for (auto& deferredPromise : m_deferredPromises)
-        deferredPromise->reject(WTF::get<Exception>(*m_valueOrException));
+        deferredPromise->reject(m_valueOrException->exception());
 }
 
 
@@ -205,10 +194,10 @@
         return JSC::jsUndefined();
 
     if (m_valueOrException) {
-        if (WTF::holds_alternative<Value>(*m_valueOrException))
+        if (m_valueOrException->hasException())
+            deferredPromise->reject(m_valueOrException->exception());
+        else
             deferredPromise->resolve();
-        else
-            deferredPromise->reject(WTF::get<Exception>(*m_valueOrException));
     }
 
     auto result = deferredPromise->promise();
@@ -230,7 +219,7 @@
 inline void DOMPromiseProxy<IDLVoid>::resolve()
 {
     ASSERT(!m_valueOrException);
-    m_valueOrException = ValueOrException { true };
+    m_valueOrException = ExceptionOr<void> { };
     for (auto& deferredPromise : m_deferredPromises)
         deferredPromise->resolve();
 }
@@ -238,9 +227,9 @@
 inline void DOMPromiseProxy<IDLVoid>::reject(Exception exception)
 {
     ASSERT(!m_valueOrException);
-    m_valueOrException = ValueOrException { WTFMove(exception) };
+    m_valueOrException = ExceptionOr<void> { WTFMove(exception) };
     for (auto& deferredPromise : m_deferredPromises)
-        deferredPromise->reject(WTF::get<Exception>(*m_valueOrException));
+        deferredPromise->reject(m_valueOrException->exception());
 }
 
 // MARK: - DOMPromiseProxyWithResolveCallback<IDLType> implementation
@@ -247,7 +236,7 @@
 
 template<typename IDLType>
 template <typename Class, typename BaseClass>
-inline DOMPromiseProxyWithResolveCallback<IDLType>::DOMPromiseProxyWithResolveCallback(Class& object, typename IDLType::ImplementationType (BaseClass::*function)())
+inline DOMPromiseProxyWithResolveCallback<IDLType>::DOMPromiseProxyWithResolveCallback(Class& object, typename IDLType::ParameterType (BaseClass::*function)())
     : m_resolveCallback(std::bind(function, &object))
 {
 }
@@ -272,10 +261,10 @@
         return JSC::jsUndefined();
 
     if (m_valueOrException) {
-        if (WTF::holds_alternative<Value>(*m_valueOrException))
-            deferredPromise->template resolve<IDLType>(IDLType::convertToParameterType(m_resolveCallback()));
+        if (m_valueOrException->hasException())
+            deferredPromise->reject(m_valueOrException->exception());
         else
-            deferredPromise->reject(WTF::get<Exception>(*m_valueOrException));
+            deferredPromise->template resolve<IDLType>(m_resolveCallback());
     }
 
     auto result = deferredPromise->promise();
@@ -301,7 +290,7 @@
 {
     ASSERT(!m_valueOrException);
 
-    m_valueOrException = ValueOrException { true };
+    m_valueOrException = ExceptionOr<void> { };
     for (auto& deferredPromise : m_deferredPromises)
         deferredPromise->template resolve<IDLType>(value);
 }
@@ -311,7 +300,7 @@
 {
     ASSERT(!m_valueOrException);
 
-    m_valueOrException = ValueOrException { true };
+    m_valueOrException = ExceptionOr<void> { };
     for (auto& deferredPromise : m_deferredPromises)
         deferredPromise->template resolveWithNewlyCreated<IDLType>(value);
 }
@@ -321,9 +310,9 @@
 {
     ASSERT(!m_valueOrException);
 
-    m_valueOrException = ValueOrException { WTFMove(exception) };
+    m_valueOrException = ExceptionOr<void> { WTFMove(exception) };
     for (auto& deferredPromise : m_deferredPromises)
-        deferredPromise->reject(WTF::get<Exception>(*m_valueOrException));
+        deferredPromise->reject(m_valueOrException->exception());
 }
 
 }

Modified: trunk/Source/WebCore/css/FontFace.cpp (220619 => 220620)


--- trunk/Source/WebCore/css/FontFace.cpp	2017-08-12 00:07:00 UTC (rev 220619)
+++ trunk/Source/WebCore/css/FontFace.cpp	2017-08-12 00:32:03 UTC (rev 220620)
@@ -448,9 +448,9 @@
     return m_loadedPromise;
 }
 
-RefPtr<FontFace> FontFace::loadedPromiseResolve()
+FontFace& FontFace::loadedPromiseResolve()
 {
-    return this;
+    return *this;
 }
 
 }

Modified: trunk/Source/WebCore/css/FontFace.h (220619 => 220620)


--- trunk/Source/WebCore/css/FontFace.h	2017-08-12 00:07:00 UTC (rev 220619)
+++ trunk/Source/WebCore/css/FontFace.h	2017-08-12 00:32:03 UTC (rev 220620)
@@ -94,7 +94,8 @@
     explicit FontFace(CSSFontSelector&);
     explicit FontFace(CSSFontFace&);
 
-    RefPtr<FontFace> loadedPromiseResolve();
+    // Callback for LoadedPromise.
+    FontFace& loadedPromiseResolve();
 
     WeakPtrFactory<FontFace> m_weakPtrFactory;
     Ref<CSSFontFace> m_backing;

Modified: trunk/Source/WebCore/css/FontFaceSet.cpp (220619 => 220620)


--- trunk/Source/WebCore/css/FontFaceSet.cpp	2017-08-12 00:07:00 UTC (rev 220619)
+++ trunk/Source/WebCore/css/FontFaceSet.cpp	2017-08-12 00:32:03 UTC (rev 220620)
@@ -224,9 +224,9 @@
     m_pendingPromises.remove(iterator);
 }
 
-RefPtr<FontFaceSet> FontFaceSet::readyPromiseResolve()
+FontFaceSet& FontFaceSet::readyPromiseResolve()
 {
-    return this;
+    return *this;
 }
 
 }

Modified: trunk/Source/WebCore/css/FontFaceSet.h (220619 => 220620)


--- trunk/Source/WebCore/css/FontFaceSet.h	2017-08-12 00:07:00 UTC (rev 220619)
+++ trunk/Source/WebCore/css/FontFaceSet.h	2017-08-12 00:32:03 UTC (rev 220620)
@@ -108,7 +108,8 @@
     void refEventTarget() final { ref(); }
     void derefEventTarget() final { deref(); }
 
-    RefPtr<FontFaceSet> readyPromiseResolve();
+    // Callback for ReadyPromise.
+    FontFaceSet& readyPromiseResolve();
 
     Ref<CSSFontFaceSet> m_backing;
     HashMap<RefPtr<FontFace>, Vector<Ref<PendingPromise>>> m_pendingPromises;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to