Changeset 231223 in webkit
- Timestamp:
- May 1, 2018 9:32:33 PM (6 years ago)
- Location:
- trunk/Source
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r231197 r231223 1 2018-05-01 Yusuke Suzuki <utatane.tea@gmail.com> 2 3 Use default std::optional if it is provided 4 https://bugs.webkit.org/show_bug.cgi?id=185159 5 6 Reviewed by JF Bastien. 7 8 Now C++17 flag is enabled. It means that any standard libraries can use <optional> internally. 9 If we define std::optional regardless of the existence of the standard library's <optional>, 10 it causes compile errors. For example, in GCC 7 (specifically GCC 7.3.0) environment, 11 <optional> is included in <unordered_map>. 12 We do not define std::optional in WebKit side if <optional> is offered. 13 14 And we also remove std::optional<T&> use since this is not accepted in C++17. Use 15 std::optional<std::reference_wrapper<T>> instead. 16 17 * wtf/Expected.h: 18 constexpr does not mean const in C++17. 19 20 * wtf/Optional.h: 21 Do not define std::optional if <optional> is provided. 22 23 (WTF::valueOrCompute): 24 1 25 2018-05-01 Robin Morisset <rmorisset@apple.com> 2 26 -
trunk/Source/WTF/wtf/Expected.h
r225728 r231223 574 574 }}} // namespace std::experimental::fundamentals_v3 575 575 576 __EXPECTED_INLINE_VARIABLE constexpr std::experimental::unexpected_t& unexpect = std::experimental::unexpect;576 __EXPECTED_INLINE_VARIABLE constexpr auto& unexpect = std::experimental::unexpect; 577 577 template<class T, class E> using Expected = std::experimental::expected<T, E>; -
trunk/Source/WTF/wtf/Optional.h
r230113 r231223 47 47 # include <wtf/Compiler.h> 48 48 # include <wtf/StdLibExtras.h> 49 50 #if !COMPILER(MSVC) && __has_include(<optional>) 51 # include <optional> 52 #endif 53 54 #if !COMPILER(MSVC) && defined(__cpp_lib_optional) && __cpp_lib_optional >= 201603 55 56 // Use default std::optional. 57 58 #else 49 59 50 60 # define TR2_OPTIONAL_REQUIRES(...) typename std::enable_if<__VA_ARGS__::value, bool>::type = false … … 1013 1023 } // namespace std 1014 1024 1025 namespace std 1026 { 1027 template <typename T> 1028 struct hash<std::optional<T>> 1029 { 1030 typedef typename hash<T>::result_type result_type; 1031 typedef std::optional<T> argument_type; 1032 1033 constexpr result_type operator()(argument_type const& arg) const { 1034 return arg ? std::hash<T>{}(*arg) : result_type{}; 1035 } 1036 }; 1037 1038 template <typename T> 1039 struct hash<std::optional<T&>> 1040 { 1041 typedef typename hash<T>::result_type result_type; 1042 typedef std::optional<T&> argument_type; 1043 1044 constexpr result_type operator()(argument_type const& arg) const { 1045 return arg ? std::hash<T>{}(*arg) : result_type{}; 1046 } 1047 }; 1048 } 1049 1050 # undef TR2_OPTIONAL_REQUIRES 1051 # undef TR2_OPTIONAL_ASSERTED_EXPRESSION 1052 1053 #endif // defined(__cpp_lib_optional) 1054 1015 1055 namespace WTF { 1016 1056 … … 1027 1067 } // namespace WTF 1028 1068 1029 namespace std1030 {1031 template <typename T>1032 struct hash<std::optional<T>>1033 {1034 typedef typename hash<T>::result_type result_type;1035 typedef std::optional<T> argument_type;1036 1037 constexpr result_type operator()(argument_type const& arg) const {1038 return arg ? std::hash<T>{}(*arg) : result_type{};1039 }1040 };1041 1042 template <typename T>1043 struct hash<std::optional<T&>>1044 {1045 typedef typename hash<T>::result_type result_type;1046 typedef std::optional<T&> argument_type;1047 1048 constexpr result_type operator()(argument_type const& arg) const {1049 return arg ? std::hash<T>{}(*arg) : result_type{};1050 }1051 };1052 }1053 1054 # undef TR2_OPTIONAL_REQUIRES1055 # undef TR2_OPTIONAL_ASSERTED_EXPRESSION1056 1057 1069 using WTF::valueOrCompute; -
trunk/Source/WebCore/ChangeLog
r231221 r231223 1 2018-05-01 Yusuke Suzuki <utatane.tea@gmail.com> 2 3 Use default std::optional if it is provided 4 https://bugs.webkit.org/show_bug.cgi?id=185159 5 6 Reviewed by JF Bastien. 7 8 * Modules/mediastream/RTCPeerConnection.cpp: 9 (WebCore::iceServersFromConfiguration): 10 (WebCore::RTCPeerConnection::setConfiguration): 11 * css/parser/CSSParser.cpp: 12 (WebCore::CSSParser::parseSystemColor): 13 * css/parser/CSSParser.h: 14 * dom/DatasetDOMStringMap.cpp: 15 (WebCore::DatasetDOMStringMap::item const): 16 (WebCore::DatasetDOMStringMap::namedItem const): 17 (WebCore:: const): Deleted. 18 * dom/DatasetDOMStringMap.h: 19 * dom/Element.cpp: 20 (WebCore::Element::insertAdjacentHTML): 21 * dom/Element.h: 22 * inspector/DOMEditor.cpp: 23 * platform/network/curl/CurlFormDataStream.cpp: 24 (WebCore::CurlFormDataStream::getPostData): 25 (): Deleted. 26 * platform/network/curl/CurlFormDataStream.h: 27 * testing/MockCDMFactory.cpp: 28 (WebCore::MockCDMFactory::keysForSessionWithID const): 29 (WebCore::MockCDMInstance::updateLicense): 30 (WebCore:: const): Deleted. 31 * testing/MockCDMFactory.h: 32 1 33 2018-05-01 Chris Dumez <cdumez@apple.com> 2 34 -
trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp
r229645 r231223 302 302 303 303 // Implementation of https://w3c.github.io/webrtc-pc/#set-pc-configuration 304 static inline ExceptionOr<Vector<MediaEndpointConfiguration::IceServerInfo>> iceServersFromConfiguration(RTCConfiguration& newConfiguration, std::optional< const RTCConfiguration&> existingConfiguration, bool isLocalDescriptionSet)305 { 306 if (existingConfiguration && newConfiguration.bundlePolicy != existingConfiguration-> bundlePolicy)304 static inline ExceptionOr<Vector<MediaEndpointConfiguration::IceServerInfo>> iceServersFromConfiguration(RTCConfiguration& newConfiguration, std::optional<std::reference_wrapper<const RTCConfiguration>> existingConfiguration, bool isLocalDescriptionSet) 305 { 306 if (existingConfiguration && newConfiguration.bundlePolicy != existingConfiguration->get().bundlePolicy) 307 307 return Exception { InvalidModificationError, "IceTransportPolicy does not match existing policy" }; 308 308 309 if (existingConfiguration && newConfiguration.iceCandidatePoolSize != existingConfiguration-> iceCandidatePoolSize && isLocalDescriptionSet)309 if (existingConfiguration && newConfiguration.iceCandidatePoolSize != existingConfiguration->get().iceCandidatePoolSize && isLocalDescriptionSet) 310 310 return Exception { InvalidModificationError, "IceTransportPolicy pool size does not match existing pool size" }; 311 311 … … 361 361 INFO_LOG(LOGIDENTIFIER); 362 362 363 auto servers = iceServersFromConfiguration(configuration, m_configuration, m_backend->isLocalDescriptionSet());363 auto servers = iceServersFromConfiguration(configuration, std::cref(m_configuration), m_backend->isLocalDescriptionSet()); 364 364 if (servers.hasException()) 365 365 return servers.releaseException(); -
trunk/Source/WebCore/css/parser/CSSParser.cpp
r230978 r231223 179 179 } 180 180 181 Color CSSParser::parseSystemColor(const String& string, std::optional< const CSSParserContext&> context)181 Color CSSParser::parseSystemColor(const String& string, std::optional<std::reference_wrapper<const CSSParserContext>> context) 182 182 { 183 183 CSSValueID id = cssValueKeywordID(string); … … 186 186 187 187 OptionSet<StyleColor::Options> options; 188 if (context && context .value().useSystemAppearance)188 if (context && context->get().useSystemAppearance) 189 189 options |= StyleColor::Options::UseSystemAppearance; 190 190 return RenderTheme::singleton().systemColor(id, options); -
trunk/Source/WebCore/css/parser/CSSParser.h
r229448 r231223 79 79 80 80 static Color parseColor(const String&, bool strict = false); 81 static Color parseSystemColor(const String&, std::optional< const CSSParserContext&>);81 static Color parseSystemColor(const String&, std::optional<std::reference_wrapper<const CSSParserContext>>); 82 82 83 83 private: -
trunk/Source/WebCore/dom/DatasetDOMStringMap.cpp
r219856 r231223 189 189 } 190 190 191 std::optional< const AtomicString&> DatasetDOMStringMap::item(const String& propertyName) const191 std::optional<std::reference_wrapper<const AtomicString>> DatasetDOMStringMap::item(const String& propertyName) const 192 192 { 193 193 if (m_element.hasAttributes()) { … … 199 199 const Attribute& attribute = *attributeIteratorAccessor.begin(); 200 200 if (propertyNameMatchesAttributeName(propertyName, attribute.localName())) 201 return attribute.value();201 return std::cref(attribute.value()); 202 202 } else { 203 203 AtomicString attributeName = convertPropertyNameToAttributeName(propertyName); 204 204 for (const Attribute& attribute : attributeIteratorAccessor) { 205 205 if (attribute.localName() == attributeName) 206 return attribute.value();206 return std::cref(attribute.value()); 207 207 } 208 208 } … … 214 214 String DatasetDOMStringMap::namedItem(const AtomicString& name) const 215 215 { 216 return item(name).value_or(String { }); 216 if (auto value = item(name)) 217 return value->get(); 218 return String { }; 217 219 } 218 220 -
trunk/Source/WebCore/dom/DatasetDOMStringMap.h
r217773 r231223 54 54 55 55 private: 56 std::optional< const AtomicString&> item(const String& name) const;56 std::optional<std::reference_wrapper<const AtomicString>> item(const String& name) const; 57 57 58 58 Element& m_element; -
trunk/Source/WebCore/dom/Element.cpp
r231114 r231223 3734 3734 3735 3735 // https://w3c.github.io/DOM-Parsing/#dom-element-insertadjacenthtml 3736 ExceptionOr<void> Element::insertAdjacentHTML(const String& where, const String& markup, std::optional< NodeVector&> addedNodes)3736 ExceptionOr<void> Element::insertAdjacentHTML(const String& where, const String& markup, std::optional<std::reference_wrapper<NodeVector>> addedNodes) 3737 3737 { 3738 3738 // Steps 1 and 2. … … 3748 3748 // Must be called before insertAdjacent, as otherwise the children of fragment will be moved 3749 3749 // to their new parent and will be harder to keep track of. 3750 *addedNodes= collectChildNodes(fragment.returnValue());3750 addedNodes->get() = collectChildNodes(fragment.returnValue()); 3751 3751 } 3752 3752 -
trunk/Source/WebCore/dom/Element.h
r230229 r231223 315 315 virtual RefPtr<Element> focusDelegate(); 316 316 317 ExceptionOr<void> insertAdjacentHTML(const String& where, const String& html, std::optional< NodeVector&> addedNodes);317 ExceptionOr<void> insertAdjacentHTML(const String& where, const String& html, std::optional<std::reference_wrapper<NodeVector>> addedNodes); 318 318 319 319 WEBCORE_EXPORT ExceptionOr<Element*> insertAdjacentElement(const String& where, Element& newChild); -
trunk/Source/WebCore/inspector/DOMEditor.cpp
r224648 r231223 267 267 ExceptionOr<void> redo() final 268 268 { 269 auto result = m_element->insertAdjacentHTML(m_position, m_html, m_addedNodes);269 auto result = m_element->insertAdjacentHTML(m_position, m_html, std::ref(m_addedNodes)); 270 270 if (result.hasException()) 271 271 return result.releaseException(); -
trunk/Source/WebCore/platform/network/curl/CurlFormDataStream.cpp
r226656 r231223 70 70 } 71 71 72 std::optional< const Vector<char>&> CurlFormDataStream::getPostData()72 std::optional<std::reference_wrapper<const Vector<char>>> CurlFormDataStream::getPostData() 73 73 { 74 74 if (!m_formData) … … 78 78 m_postData = std::make_unique<Vector<char>>(m_formData->flatten()); 79 79 80 return *m_postData;80 return std::cref(*m_postData); 81 81 } 82 82 -
trunk/Source/WebCore/platform/network/curl/CurlFormDataStream.h
r230229 r231223 42 42 size_t elementSize() { return m_formData ? m_formData->elements().size() : 0; } 43 43 44 std::optional< const Vector<char>&> getPostData();44 std::optional<std::reference_wrapper<const Vector<char>>> getPostData(); 45 45 bool shouldUseChunkTransfer(); 46 46 unsigned long long totalSize(); -
trunk/Source/WebCore/platform/network/curl/CurlRequest.cpp
r230973 r231223 491 491 if (elementSize == 1) { 492 492 auto postData = m_formDataStream.getPostData(); 493 if (postData && postData-> size())494 m_curlHandle->setPostFields(postData-> data(), postData->size());493 if (postData && postData->get().size()) 494 m_curlHandle->setPostFields(postData->get().data(), postData->get().size()); 495 495 } else 496 496 setupSendData(false); -
trunk/Source/WebCore/testing/MockCDMFactory.cpp
r228218 r231223 82 82 } 83 83 84 std::optional< const Vector<Ref<SharedBuffer>>&> MockCDMFactory::keysForSessionWithID(const String& id) const84 std::optional<std::reference_wrapper<const Vector<Ref<SharedBuffer>>>> MockCDMFactory::keysForSessionWithID(const String& id) const 85 85 { 86 86 auto it = m_sessions.find(id); 87 87 if (it == m_sessions.end()) 88 88 return std::nullopt; 89 return it->value;89 return std::cref(it->value); 90 90 } 91 91 … … 315 315 std::optional<KeyStatusVector> changedKeys; 316 316 if (responseVector.contains(String(ASCIILiteral("keys-changed")))) { 317 std::optional< const Vector<Ref<SharedBuffer>>&> keys = factory->keysForSessionWithID(sessionID);317 std::optional<std::reference_wrapper<const Vector<Ref<SharedBuffer>>>> keys = factory->keysForSessionWithID(sessionID); 318 318 if (keys) { 319 319 KeyStatusVector keyStatusVector; 320 keyStatusVector.reserveInitialCapacity(keys-> size());321 for (auto& key : *keys)320 keyStatusVector.reserveInitialCapacity(keys->get().size()); 321 for (auto& key : (*keys).get()) 322 322 keyStatusVector.uncheckedAppend({ key.copyRef(), KeyStatus::Usable }); 323 323 -
trunk/Source/WebCore/testing/MockCDMFactory.h
r224707 r231223 74 74 void removeSessionWithID(const String& id) { m_sessions.remove(id); } 75 75 void addKeysToSessionWithID(const String& id, Vector<Ref<SharedBuffer>>&&); 76 std::optional< const Vector<Ref<SharedBuffer>>&> keysForSessionWithID(const String& id) const;76 std::optional<std::reference_wrapper<const Vector<Ref<SharedBuffer>>>> keysForSessionWithID(const String& id) const; 77 77 Vector<Ref<SharedBuffer>> removeKeysFromSessionWithID(const String& id); 78 78 -
trunk/Source/WebKit/ChangeLog
r231215 r231223 1 2018-05-01 Yusuke Suzuki <utatane.tea@gmail.com> 2 3 Use default std::optional if it is provided 4 https://bugs.webkit.org/show_bug.cgi?id=185159 5 6 Reviewed by JF Bastien. 7 8 * Shared/SandboxExtension.h: 9 (WebKit::SandboxExtension::Handle::decode): 10 * Shared/TouchBarMenuItemData.cpp: 11 (WebKit::TouchBarMenuItemData::decode): 12 1 13 2018-05-01 Jer Noble <jer.noble@apple.com> 2 14 -
trunk/Source/WebKit/Shared/SandboxExtension.h
r229309 r231223 121 121 inline SandboxExtension::Handle::~Handle() { } 122 122 inline void SandboxExtension::Handle::encode(IPC::Encoder&) const { } 123 inline std::optional<SandboxExtension::Handle> SandboxExtension::Handle::decode(IPC::Decoder&) { return {{ }}; }123 inline std::optional<SandboxExtension::Handle> SandboxExtension::Handle::decode(IPC::Decoder&) { return SandboxExtension::Handle { }; } 124 124 inline SandboxExtension::HandleArray::HandleArray() { } 125 125 inline SandboxExtension::HandleArray::~HandleArray() { } -
trunk/Source/WebKit/Shared/TouchBarMenuItemData.cpp
r225505 r231223 66 66 return std::nullopt; 67 67 68 return WTFMove(result);68 return std::make_optional(WTFMove(result)); 69 69 } 70 70
Note: See TracChangeset
for help on using the changeset viewer.