Changeset 220620 in webkit
- Timestamp:
- Aug 11, 2017, 5:32:03 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r220619 r220620 1 2017-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 1 29 2017-08-11 Sam Weinig <sam@webkit.org> 2 30 -
trunk/Source/WebCore/bindings/IDLTypes.h
r220433 r220620 171 171 template<typename U> static inline bool isNullValue(U&& value) { return !value; } 172 172 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(); }175 173 }; 176 174 -
trunk/Source/WebCore/bindings/js/DOMPromiseProxy.h
r220440 r220620 26 26 #pragma once 27 27 28 #include "Exception .h"28 #include "ExceptionOr.h" 29 29 #include "JSDOMGlobalObject.h" 30 30 #include "JSDOMPromiseDeferred.h" 31 31 #include <wtf/Function.h> 32 32 #include <wtf/Optional.h> 33 #include <wtf/Variant.h>34 33 #include <wtf/Vector.h> 35 34 … … 40 39 public: 41 40 using Value = typename IDLType::StorageType; 42 using ValueOrException = Variant<Value, Exception>;43 41 44 42 DOMPromiseProxy() = default; … … 56 54 57 55 private: 58 std::optional< ValueOrException> m_valueOrException;56 std::optional<ExceptionOr<Value>> m_valueOrException; 59 57 Vector<Ref<DeferredPromise>, 1> m_deferredPromises; 60 58 }; … … 63 61 class DOMPromiseProxy<IDLVoid> { 64 62 public: 65 using Value = bool;66 using ValueOrException = Variant<Value, Exception>;67 68 63 DOMPromiseProxy() = default; 69 64 ~DOMPromiseProxy() = default; … … 79 74 80 75 private: 81 std::optional< ValueOrException> m_valueOrException;76 std::optional<ExceptionOr<void>> m_valueOrException; 82 77 Vector<Ref<DeferredPromise>, 1> m_deferredPromises; 83 78 }; … … 90 85 class DOMPromiseProxyWithResolveCallback { 91 86 public: 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 ()>; 98 88 99 89 template <typename Class, typename BaseClass> 100 DOMPromiseProxyWithResolveCallback(Class&, typename IDLType:: ImplementationType (BaseClass::*)());90 DOMPromiseProxyWithResolveCallback(Class&, typename IDLType::ParameterType (BaseClass::*)()); 101 91 DOMPromiseProxyWithResolveCallback(ResolveCallback&&); 102 92 ~DOMPromiseProxyWithResolveCallback() = default; … … 114 104 private: 115 105 ResolveCallback m_resolveCallback; 116 117 std::optional<ValueOrException> m_valueOrException; 106 std::optional<ExceptionOr<void>> m_valueOrException; 118 107 Vector<Ref<DeferredPromise>, 1> m_deferredPromises; 119 108 }; … … 136 125 137 126 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()); 140 129 else 141 deferredPromise-> reject(WTF::get<Exception>(*m_valueOrException));130 deferredPromise->template resolve<IDLType>(m_valueOrException->returnValue()); 142 131 } 143 132 … … 165 154 ASSERT(!m_valueOrException); 166 155 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()); 170 159 } 171 160 … … 175 164 ASSERT(!m_valueOrException); 176 165 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()); 180 169 } 181 170 … … 185 174 ASSERT(!m_valueOrException); 186 175 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()); 190 179 } 191 180 … … 206 195 207 196 if (m_valueOrException) { 208 if (WTF::holds_alternative<Value>(*m_valueOrException)) 197 if (m_valueOrException->hasException()) 198 deferredPromise->reject(m_valueOrException->exception()); 199 else 209 200 deferredPromise->resolve(); 210 else211 deferredPromise->reject(WTF::get<Exception>(*m_valueOrException));212 201 } 213 202 … … 231 220 { 232 221 ASSERT(!m_valueOrException); 233 m_valueOrException = ValueOrException { true};222 m_valueOrException = ExceptionOr<void> { }; 234 223 for (auto& deferredPromise : m_deferredPromises) 235 224 deferredPromise->resolve(); … … 239 228 { 240 229 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()); 244 233 } 245 234 … … 248 237 template<typename IDLType> 249 238 template <typename Class, typename BaseClass> 250 inline DOMPromiseProxyWithResolveCallback<IDLType>::DOMPromiseProxyWithResolveCallback(Class& object, typename IDLType:: ImplementationType (BaseClass::*function)())239 inline DOMPromiseProxyWithResolveCallback<IDLType>::DOMPromiseProxyWithResolveCallback(Class& object, typename IDLType::ParameterType (BaseClass::*function)()) 251 240 : m_resolveCallback(std::bind(function, &object)) 252 241 { … … 273 262 274 263 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()); 277 266 else 278 deferredPromise-> reject(WTF::get<Exception>(*m_valueOrException));267 deferredPromise->template resolve<IDLType>(m_resolveCallback()); 279 268 } 280 269 … … 302 291 ASSERT(!m_valueOrException); 303 292 304 m_valueOrException = ValueOrException { true};293 m_valueOrException = ExceptionOr<void> { }; 305 294 for (auto& deferredPromise : m_deferredPromises) 306 295 deferredPromise->template resolve<IDLType>(value); … … 312 301 ASSERT(!m_valueOrException); 313 302 314 m_valueOrException = ValueOrException { true};303 m_valueOrException = ExceptionOr<void> { }; 315 304 for (auto& deferredPromise : m_deferredPromises) 316 305 deferredPromise->template resolveWithNewlyCreated<IDLType>(value); … … 322 311 ASSERT(!m_valueOrException); 323 312 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 449 449 } 450 450 451 RefPtr<FontFace>FontFace::loadedPromiseResolve()452 { 453 return this;454 } 455 456 } 451 FontFace& FontFace::loadedPromiseResolve() 452 { 453 return *this; 454 } 455 456 } -
trunk/Source/WebCore/css/FontFace.h
r220433 r220620 95 95 explicit FontFace(CSSFontFace&); 96 96 97 RefPtr<FontFace> loadedPromiseResolve(); 97 // Callback for LoadedPromise. 98 FontFace& loadedPromiseResolve(); 98 99 99 100 WeakPtrFactory<FontFace> m_weakPtrFactory; -
trunk/Source/WebCore/css/FontFaceSet.cpp
r220440 r220620 225 225 } 226 226 227 RefPtr<FontFaceSet>FontFaceSet::readyPromiseResolve()228 { 229 return this;230 } 231 232 } 227 FontFaceSet& FontFaceSet::readyPromiseResolve() 228 { 229 return *this; 230 } 231 232 } -
trunk/Source/WebCore/css/FontFaceSet.h
r220440 r220620 109 109 void derefEventTarget() final { deref(); } 110 110 111 RefPtr<FontFaceSet> readyPromiseResolve(); 111 // Callback for ReadyPromise. 112 FontFaceSet& readyPromiseResolve(); 112 113 113 114 Ref<CSSFontFaceSet> m_backing;
Note:
See TracChangeset
for help on using the changeset viewer.