Changeset 220620 in webkit


Ignore:
Timestamp:
Aug 11, 2017 5:32:03 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

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

Patch by Sam Weinig <sam@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.

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r220619 r220620  
     12017-08-11  Sam Weinig  <sam@webkit.org>
     2
     3        [Bindings] Simplify DOMPromiseProxy now that WTF::Function can return references
     4        https://bugs.webkit.org/show_bug.cgi?id=175394
     5
     6        Reviewed by Chris Dumez.
     7
     8        * bindings/IDLTypes.h:
     9        (WebCore::IDLWrapper::convertToParameterType): Deleted.
     10
     11            Remove no longer used convertToParameterType.
     12
     13        * bindings/js/DOMPromiseProxy.h:
     14
     15            - Replace Variant<Value, Exception> with ExceptionOr<Value> / ExceptionOr<void>.
     16            - Update ResolveCallback to have a return type of IDLType::ParameterType, rather than
     17              IDLType::ImplementationType, now that WTF::Function supports references as the
     18              return type. This is needed, since the IDLType::ParameterType for an interface T
     19              is T&.
     20
     21        * css/FontFace.cpp:
     22        * css/FontFace.h:
     23        * css/FontFaceSet.cpp:
     24        * css/FontFaceSet.h:
     25
     26            Update resolve callbacks to return a reference rather than a RefPtr, matching
     27            the new signature requirement.
     28
    1292017-08-11  Sam Weinig  <sam@webkit.org>
    230
  • trunk/Source/WebCore/bindings/IDLTypes.h

    r220433 r220620  
    171171    template<typename U> static inline bool isNullValue(U&& value) { return !value; }
    172172    template<typename U> static inline U&& extractValueFromNullable(U&& value) { return std::forward<U>(value); }
    173 
    174     static ParameterType convertToParameterType(RefPtr<T> value) { ASSERT(value); return *value.get(); }
    175173};
    176174
  • trunk/Source/WebCore/bindings/js/DOMPromiseProxy.h

    r220440 r220620  
    2626#pragma once
    2727
    28 #include "Exception.h"
     28#include "ExceptionOr.h"
    2929#include "JSDOMGlobalObject.h"
    3030#include "JSDOMPromiseDeferred.h"
    3131#include <wtf/Function.h>
    3232#include <wtf/Optional.h>
    33 #include <wtf/Variant.h>
    3433#include <wtf/Vector.h>
    3534
     
    4039public:
    4140    using Value = typename IDLType::StorageType;
    42     using ValueOrException = Variant<Value, Exception>;
    4341
    4442    DOMPromiseProxy() = default;
     
    5654   
    5755private:
    58     std::optional<ValueOrException> m_valueOrException;
     56    std::optional<ExceptionOr<Value>> m_valueOrException;
    5957    Vector<Ref<DeferredPromise>, 1> m_deferredPromises;
    6058};
     
    6361class DOMPromiseProxy<IDLVoid> {
    6462public:
    65     using Value = bool;
    66     using ValueOrException = Variant<Value, Exception>;
    67 
    6863    DOMPromiseProxy() = default;
    6964    ~DOMPromiseProxy() = default;
     
    7974
    8075private:
    81     std::optional<ValueOrException> m_valueOrException;
     76    std::optional<ExceptionOr<void>> m_valueOrException;
    8277    Vector<Ref<DeferredPromise>, 1> m_deferredPromises;
    8378};
     
    9085class DOMPromiseProxyWithResolveCallback {
    9186public:
    92     using Value = bool;
    93     using ValueOrException = Variant<Value, Exception>;
    94     // FIXME: This should return a IDLType::ParameterType, but WTF::Function does
    95     //        not support returning references / non-default initializable types.
    96     //        See https://webkit.org/b/175244.
    97     using ResolveCallback = WTF::Function<typename IDLType::ImplementationType ()>;
     87    using ResolveCallback = WTF::Function<typename IDLType::ParameterType ()>;
    9888
    9989    template <typename Class, typename BaseClass>
    100     DOMPromiseProxyWithResolveCallback(Class&, typename IDLType::ImplementationType (BaseClass::*)());
     90    DOMPromiseProxyWithResolveCallback(Class&, typename IDLType::ParameterType (BaseClass::*)());
    10191    DOMPromiseProxyWithResolveCallback(ResolveCallback&&);
    10292    ~DOMPromiseProxyWithResolveCallback() = default;
     
    114104private:
    115105    ResolveCallback m_resolveCallback;
    116 
    117     std::optional<ValueOrException> m_valueOrException;
     106    std::optional<ExceptionOr<void>> m_valueOrException;
    118107    Vector<Ref<DeferredPromise>, 1> m_deferredPromises;
    119108};
     
    136125
    137126    if (m_valueOrException) {
    138         if (WTF::holds_alternative<Value>(*m_valueOrException))
    139             deferredPromise->template resolve<IDLType>(WTF::get<Value>(*m_valueOrException));
     127        if (m_valueOrException->hasException())
     128            deferredPromise->reject(m_valueOrException->exception());
    140129        else
    141             deferredPromise->reject(WTF::get<Exception>(*m_valueOrException));
     130            deferredPromise->template resolve<IDLType>(m_valueOrException->returnValue());
    142131    }
    143132
     
    165154    ASSERT(!m_valueOrException);
    166155
    167     m_valueOrException = ValueOrException { std::forward<typename IDLType::ParameterType>(value) };
    168     for (auto& deferredPromise : m_deferredPromises)
    169         deferredPromise->template resolve<IDLType>(WTF::get<Value>(*m_valueOrException));
     156    m_valueOrException = ExceptionOr<Value> { std::forward<typename IDLType::ParameterType>(value) };
     157    for (auto& deferredPromise : m_deferredPromises)
     158        deferredPromise->template resolve<IDLType>(m_valueOrException->returnValue());
    170159}
    171160
     
    175164    ASSERT(!m_valueOrException);
    176165
    177     m_valueOrException = ValueOrException { std::forward<typename IDLType::ParameterType>(value) };
    178     for (auto& deferredPromise : m_deferredPromises)
    179         deferredPromise->template resolveWithNewlyCreated<IDLType>(WTF::get<Value>(*m_valueOrException));
     166    m_valueOrException = ExceptionOr<Value> { std::forward<typename IDLType::ParameterType>(value) };
     167    for (auto& deferredPromise : m_deferredPromises)
     168        deferredPromise->template resolveWithNewlyCreated<IDLType>(m_valueOrException->returnValue());
    180169}
    181170
     
    185174    ASSERT(!m_valueOrException);
    186175
    187     m_valueOrException = ValueOrException { WTFMove(exception) };
    188     for (auto& deferredPromise : m_deferredPromises)
    189         deferredPromise->reject(WTF::get<Exception>(*m_valueOrException));
     176    m_valueOrException = ExceptionOr<Value> { WTFMove(exception) };
     177    for (auto& deferredPromise : m_deferredPromises)
     178        deferredPromise->reject(m_valueOrException->exception());
    190179}
    191180
     
    206195
    207196    if (m_valueOrException) {
    208         if (WTF::holds_alternative<Value>(*m_valueOrException))
     197        if (m_valueOrException->hasException())
     198            deferredPromise->reject(m_valueOrException->exception());
     199        else
    209200            deferredPromise->resolve();
    210         else
    211             deferredPromise->reject(WTF::get<Exception>(*m_valueOrException));
    212201    }
    213202
     
    231220{
    232221    ASSERT(!m_valueOrException);
    233     m_valueOrException = ValueOrException { true };
     222    m_valueOrException = ExceptionOr<void> { };
    234223    for (auto& deferredPromise : m_deferredPromises)
    235224        deferredPromise->resolve();
     
    239228{
    240229    ASSERT(!m_valueOrException);
    241     m_valueOrException = ValueOrException { WTFMove(exception) };
    242     for (auto& deferredPromise : m_deferredPromises)
    243         deferredPromise->reject(WTF::get<Exception>(*m_valueOrException));
     230    m_valueOrException = ExceptionOr<void> { WTFMove(exception) };
     231    for (auto& deferredPromise : m_deferredPromises)
     232        deferredPromise->reject(m_valueOrException->exception());
    244233}
    245234
     
    248237template<typename IDLType>
    249238template <typename Class, typename BaseClass>
    250 inline DOMPromiseProxyWithResolveCallback<IDLType>::DOMPromiseProxyWithResolveCallback(Class& object, typename IDLType::ImplementationType (BaseClass::*function)())
     239inline DOMPromiseProxyWithResolveCallback<IDLType>::DOMPromiseProxyWithResolveCallback(Class& object, typename IDLType::ParameterType (BaseClass::*function)())
    251240    : m_resolveCallback(std::bind(function, &object))
    252241{
     
    273262
    274263    if (m_valueOrException) {
    275         if (WTF::holds_alternative<Value>(*m_valueOrException))
    276             deferredPromise->template resolve<IDLType>(IDLType::convertToParameterType(m_resolveCallback()));
     264        if (m_valueOrException->hasException())
     265            deferredPromise->reject(m_valueOrException->exception());
    277266        else
    278             deferredPromise->reject(WTF::get<Exception>(*m_valueOrException));
     267            deferredPromise->template resolve<IDLType>(m_resolveCallback());
    279268    }
    280269
     
    302291    ASSERT(!m_valueOrException);
    303292
    304     m_valueOrException = ValueOrException { true };
     293    m_valueOrException = ExceptionOr<void> { };
    305294    for (auto& deferredPromise : m_deferredPromises)
    306295        deferredPromise->template resolve<IDLType>(value);
     
    312301    ASSERT(!m_valueOrException);
    313302
    314     m_valueOrException = ValueOrException { true };
     303    m_valueOrException = ExceptionOr<void> { };
    315304    for (auto& deferredPromise : m_deferredPromises)
    316305        deferredPromise->template resolveWithNewlyCreated<IDLType>(value);
     
    322311    ASSERT(!m_valueOrException);
    323312
    324     m_valueOrException = ValueOrException { WTFMove(exception) };
    325     for (auto& deferredPromise : m_deferredPromises)
    326         deferredPromise->reject(WTF::get<Exception>(*m_valueOrException));
    327 }
    328 
    329 }
     313    m_valueOrException = ExceptionOr<void> { WTFMove(exception) };
     314    for (auto& deferredPromise : m_deferredPromises)
     315        deferredPromise->reject(m_valueOrException->exception());
     316}
     317
     318}
  • trunk/Source/WebCore/css/FontFace.cpp

    r220433 r220620  
    449449}
    450450
    451 RefPtr<FontFace> FontFace::loadedPromiseResolve()
    452 {
    453     return this;
    454 }
    455 
    456 }
     451FontFace& FontFace::loadedPromiseResolve()
     452{
     453    return *this;
     454}
     455
     456}
  • trunk/Source/WebCore/css/FontFace.h

    r220433 r220620  
    9595    explicit FontFace(CSSFontFace&);
    9696
    97     RefPtr<FontFace> loadedPromiseResolve();
     97    // Callback for LoadedPromise.
     98    FontFace& loadedPromiseResolve();
    9899
    99100    WeakPtrFactory<FontFace> m_weakPtrFactory;
  • trunk/Source/WebCore/css/FontFaceSet.cpp

    r220440 r220620  
    225225}
    226226
    227 RefPtr<FontFaceSet> FontFaceSet::readyPromiseResolve()
    228 {
    229     return this;
    230 }
    231 
    232 }
     227FontFaceSet& FontFaceSet::readyPromiseResolve()
     228{
     229    return *this;
     230}
     231
     232}
  • trunk/Source/WebCore/css/FontFaceSet.h

    r220440 r220620  
    109109    void derefEventTarget() final { deref(); }
    110110
    111     RefPtr<FontFaceSet> readyPromiseResolve();
     111    // Callback for ReadyPromise.
     112    FontFaceSet& readyPromiseResolve();
    112113
    113114    Ref<CSSFontFaceSet> m_backing;
Note: See TracChangeset for help on using the changeset viewer.