haikuwebkit/Source/WTF/wtf/Expected.h

582 lines
24 KiB
C
Raw Permalink Normal View History

Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
/*
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
* Copyright (C) 2016-2017 Apple Inc. All rights reserved.
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
// Implementation of Library Fundamentals v3's std::expected, as described here: http://wg21.link/p0323r4
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
#pragma once
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
/*
expected synopsis
namespace std {
namespace experimental {
inline namespace fundamentals_v3 {
// ?.?.4, Expected for object types
template <class T, class E>
class expected;
// ?.?.5, Expected specialization for void
template <class E>
class expected<void,E>;
// ?.?.6, unexpect tag
struct unexpect_t {
unexpect_t() = default;
};
inline constexpr unexpect_t unexpect{};
// ?.?.7, class bad_expected_access
template <class E>
class bad_expected_access;
// ?.?.8, Specialization for void.
template <>
class bad_expected_access<void>;
// ?.?.9, Expected relational operators
template <class T, class E>
constexpr bool operator==(const expected<T, E>&, const expected<T, E>&);
template <class T, class E>
constexpr bool operator!=(const expected<T, E>&, const expected<T, E>&);
// ?.?.10, Comparison with T
template <class T, class E>
constexpr bool operator==(const expected<T, E>&, const T&);
template <class T, class E>
constexpr bool operator==(const T&, const expected<T, E>&);
template <class T, class E>
constexpr bool operator!=(const expected<T, E>&, const T&);
template <class T, class E>
constexpr bool operator!=(const T&, const expected<T, E>&);
// ?.?.10, Comparison with unexpected<E>
template <class T, class E>
constexpr bool operator==(const expected<T, E>&, const unexpected<E>&);
template <class T, class E>
constexpr bool operator==(const unexpected<E>&, const expected<T, E>&);
template <class T, class E>
constexpr bool operator!=(const expected<T, E>&, const unexpected<E>&);
template <class T, class E>
constexpr bool operator!=(const unexpected<E>&, const expected<T, E>&);
// ?.?.11, Specialized algorithms
void swap(expected<T, E>&, expected<T, E>&) noexcept(see below);
template <class T, class E>
class expected
{
public:
typedef T value_type;
typedef E error_type;
typedef unexpected<E> unexpected_type;
template <class U>
struct rebind {
using type = expected<U, error_type>;
};
// ?.?.4.1, constructors
constexpr expected();
constexpr expected(const expected&);
constexpr expected(expected&&) noexcept(see below);
template <class U, class G>
EXPLICIT constexpr expected(const expected<U, G>&);
template <class U, class G>
EXPLICIT constexpr expected(expected<U, G>&&);
template <class U = T>
EXPLICIT constexpr expected(U&& v);
template <class... Args>
constexpr explicit expected(in_place_t, Args&&...);
template <class U, class... Args>
constexpr explicit expected(in_place_t, initializer_list<U>, Args&&...);
template <class G = E>
constexpr expected(unexpected<G> const&);
template <class G = E>
constexpr expected(unexpected<G> &&);
template <class... Args>
constexpr explicit expected(unexpect_t, Args&&...);
template <class U, class... Args>
constexpr explicit expected(unexpect_t, initializer_list<U>, Args&&...);
// ?.?.4.2, destructor
~expected();
// ?.?.4.3, assignment
expected& operator=(const expected&);
expected& operator=(expected&&) noexcept(see below);
template <class U = T> expected& operator=(U&&);
template <class G = E>
expected& operator=(const unexpected<G>&);
template <class G = E>
expected& operator=(unexpected<G>&&) noexcept(see below);
template <class... Args>
void emplace(Args&&...);
template <class U, class... Args>
void emplace(initializer_list<U>, Args&&...);
// ?.?.4.4, swap
void swap(expected&) noexcept(see below);
// ?.?.4.5, observers
constexpr const T* operator ->() const;
constexpr T* operator ->();
constexpr const T& operator *() const&;
constexpr T& operator *() &;
constexpr const T&& operator *() const &&;
constexpr T&& operator *() &&;
constexpr explicit operator bool() const noexcept;
constexpr bool has_value() const noexcept;
constexpr const T& value() const&;
constexpr T& value() &;
constexpr const T&& value() const &&;
constexpr T&& value() &&;
constexpr const E& error() const&;
constexpr E& error() &;
constexpr const E&& error() const &&;
constexpr E&& error() &&;
template <class U>
constexpr T value_or(U&&) const&;
template <class U>
T value_or(U&&) &&;
private:
bool has_val; // exposition only
union
{
value_type val; // exposition only
unexpected_type unexpect; // exposition only
};
};
}}}
*/
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
#include <cstdlib>
#include <initializer_list>
#include <type_traits>
#include <utility>
#include <wtf/Assertions.h>
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
#include <wtf/Compiler.h>
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
#include <wtf/StdLibExtras.h>
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
#include <wtf/Unexpected.h>
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
namespace std {
namespace experimental {
inline namespace fundamentals_v3 {
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
struct unexpected_t {
unexpected_t() = default;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
};
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
#if __cplusplus < 201703L
#define __EXPECTED_INLINE_VARIABLE static const
#else
#define __EXPECTED_INLINE_VARIABLE inline
#endif
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
__EXPECTED_INLINE_VARIABLE constexpr unexpected_t unexpect { };
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
template<class E> class bad_expected_access;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
template<>
class bad_expected_access<void> : public std::exception {
public:
explicit bad_expected_access() { }
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
};
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
template<class E>
class bad_expected_access : public bad_expected_access<void> {
public:
explicit bad_expected_access(E val) : val(val) { }
Fix existing usage of final/override/virtual in JSC and WTF https://bugs.webkit.org/show_bug.cgi?id=211772 Reviewed by Darin Adler. Source/JavaScriptCore: * API/JSAPIWrapperObject.mm: * API/JSManagedValue.mm: * API/JSScriptSourceProvider.h: * API/ObjCCallbackFunction.mm: * API/glib/JSAPIWrapperGlobalObject.cpp: * API/glib/JSAPIWrapperObjectGLib.cpp: * API/glib/JSCWeakValue.cpp: * bytecode/AccessCaseSnippetParams.cpp: * bytecode/AccessCaseSnippetParams.h: * bytecode/CodeBlock.cpp: * bytecode/StructureStubClearingWatchpoint.h: * bytecode/VariableWriteFireDetail.h: * bytecode/Watchpoint.h: * dfg/DFGAdaptiveInferredPropertyValueWatchpoint.h: * dfg/DFGArrayifySlowPathGenerator.h: * dfg/DFGCallArrayAllocatorSlowPathGenerator.h: * dfg/DFGCallCreateDirectArgumentsSlowPathGenerator.h: * dfg/DFGSaneStringGetByValSlowPathGenerator.h: * dfg/DFGSlowPathGenerator.h: * dfg/DFGSnippetParams.h: * dfg/DFGWorklist.cpp: * ftl/FTLSnippetParams.h: * heap/BlockDirectory.cpp: * heap/EdenGCActivityCallback.h: * heap/FullGCActivityCallback.h: * heap/Heap.cpp: * heap/Heap.h: * heap/IncrementalSweeper.h: * heap/IsoCellSet.cpp: * heap/IsoCellSetInlines.h: * heap/IsoHeapCellType.h: * heap/IsoInlinedHeapCellType.h: * heap/ParallelSourceAdapter.h: * heap/StopIfNecessaryTimer.h: * heap/Subspace.cpp: * heap/SubspaceInlines.h: * inspector/InjectedScript.h: * inspector/JSGlobalObjectConsoleClient.h: * inspector/JSGlobalObjectInspectorController.h: * inspector/JSGlobalObjectScriptDebugServer.h: * inspector/JSInjectedScriptHost.cpp: * inspector/agents/InspectorAgent.h: * inspector/agents/InspectorScriptProfilerAgent.h: * inspector/agents/InspectorTargetAgent.h: * inspector/agents/JSGlobalObjectAuditAgent.h: * inspector/agents/JSGlobalObjectDebuggerAgent.h: * inspector/agents/JSGlobalObjectRuntimeAgent.h: * inspector/augmentable/AlternateDispatchableAgent.h: * inspector/remote/RemoteConnectionToTarget.h: * inspector/remote/RemoteInspector.h: * inspector/remote/socket/RemoteInspectorServer.h: * inspector/scripts/codegen/cpp_generator_templates.py: * inspector/scripts/codegen/generate_objc_backend_dispatcher_header.py: * inspector/scripts/tests/all/expected/definitions-with-mac-platform.json-result: * inspector/scripts/tests/generic/expected/command-targetType-matching-domain-debuggableType.json-result: * inspector/scripts/tests/generic/expected/commands-with-async-attribute.json-result: * inspector/scripts/tests/generic/expected/commands-with-optional-call-return-parameters.json-result: * inspector/scripts/tests/generic/expected/domain-debuggableTypes.json-result: * inspector/scripts/tests/generic/expected/domain-targetType-matching-domain-debuggableType.json-result: * inspector/scripts/tests/generic/expected/domain-targetTypes.json-result: * inspector/scripts/tests/generic/expected/domains-with-varying-command-sizes.json-result: * inspector/scripts/tests/generic/expected/enum-values.json-result: * inspector/scripts/tests/generic/expected/event-targetType-matching-domain-debuggableType.json-result: * inspector/scripts/tests/generic/expected/generate-domains-with-feature-guards.json-result: * inspector/scripts/tests/mac/expected/definitions-with-mac-platform.json-result: * jit/JITWorklist.cpp: * parser/Nodes.h: * parser/SourceProvider.h: * runtime/DataView.h: * runtime/DoublePredictionFuzzerAgent.h: * runtime/FileBasedFuzzerAgent.h: * runtime/GenericTypedArrayView.h: * runtime/JSMicrotask.cpp: * runtime/NarrowingNumberPredictionFuzzerAgent.h: * runtime/ObjectPropertyChangeAdaptiveWatchpoint.h: * runtime/PredictionFileCreatingFuzzerAgent.h: * runtime/PromiseTimer.h: * runtime/RandomizingFuzzerAgent.h: * runtime/RegExpCache.h: * runtime/Structure.cpp: * runtime/StructureRareData.cpp: * runtime/VMTraps.cpp: * runtime/WideningNumberPredictionFuzzerAgent.h: * tools/JSDollarVM.cpp: * wasm/WasmBBQPlan.h: * wasm/WasmCallee.h: * wasm/WasmLLIntPlan.h: * wasm/WasmOMGForOSREntryPlan.h: * wasm/WasmOMGPlan.h: * wasm/WasmWorklist.cpp: * yarr/YarrJIT.cpp: Source/WTF: * wtf/Assertions.cpp: * wtf/Expected.h: * wtf/FilePrintStream.h: * wtf/JSONValues.h: * wtf/LockedPrintStream.h: * wtf/OSLogPrintStream.h: * wtf/ParallelHelperPool.cpp: * wtf/RunLoop.h: * wtf/SharedTask.h: * wtf/StringPrintStream.h: * wtf/WorkQueue.h: * wtf/WorkerPool.cpp: Canonical link: https://commits.webkit.org/224683@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261569 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-12 19:13:18 +00:00
const char* what() const noexcept override { return std::exception::what(); }
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
E& error() & { return val; }
const E& error() const& { return val; }
E&& error() && { return std::move(val); }
const E&& error() const&& { return std::move(val); }
private:
E val;
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
};
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
namespace __expected_detail {
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
#if COMPILER_SUPPORTS(EXCEPTIONS)
#define __EXPECTED_THROW(__exception) (throw __exception)
#else
inline NO_RETURN_DUE_TO_CRASH void __expected_terminate() { RELEASE_ASSERT_NOT_REACHED(); }
#define __EXPECTED_THROW(...) __expected_detail::__expected_terminate()
#endif
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
__EXPECTED_INLINE_VARIABLE constexpr enum class value_tag_t { } value_tag { };
__EXPECTED_INLINE_VARIABLE constexpr enum class error_tag_t { } error_tag { };
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
WebAssembly JS API: improve Instance https://bugs.webkit.org/show_bug.cgi?id=164757 Reviewed by Keith Miller. JSTests: An Instance's `exports` property wasn't populated with exports. A follow-up patch will do imports. A few things of note: - LowLevelBinary: support 3-byte integers. - LowLevelBinary: support proper UTF-8 2003 code points (instead of UTF-16). * wasm/Builder.js: * wasm/Builder_WebAssemblyBinary.js: wire up exports, stub other things out some more (const.emitters.Export): * wasm/LowLevelBinary.js: (export.default.LowLevelBinary.prototype.uint24): add, used for UTF-8 (export.default.LowLevelBinary.prototype.string): support UTF-8 (export.default.LowLevelBinary.prototype.getUint24): add, used for UTF-8 (export.default.LowLevelBinary.prototype.getVaruint1): was missing (export.default.LowLevelBinary.prototype.getString): support UTF-8 (export.default.LowLevelBinary): * wasm/js-api/test_Instance.js: instance.exports.answer() // <-- this is where the magic of this entire patch is (ExportedAnswerI32): * wasm/js-api/test_basic_api.js: punt test to later (const.c.in.constructorProperties.switch): * wasm/self-test/test_BuilderWebAssembly.js: UTF-8 (CustomSection): * wasm/self-test/test_LowLevelBinary_string.js: UTF-8 now works * wasm/self-test/test_LowLevelBinary_uint16.js: was missing one value * wasm/self-test/test_LowLevelBinary_uint24.js: Copied from JSTests/wasm/self-test/test_LowLevelBinary_uint8.js. * wasm/self-test/test_LowLevelBinary_uint8.js: was missing one value * wasm/self-test/test_LowLevelBinary_varuint1.js: Added. * wasm/utilities.js: this `dump` thing was useful (const._dump): Source/JavaScriptCore: An Instance's `exports` property wasn't populated with exports. According to the spec [0], `exports` should present itself as a WebAssembly Module Record. In order to do this we need to split JSModuleRecord into AbstractModuleRecord (without the `link` and `evaluate` functions), and JSModuleRecord (which implements link and evaluate). We can then have a separate WebAssemblyModuleRecord which shares most of the implementation. `exports` then maps function names to WebAssemblyFunction and WebAssemblyFunctionCell, which call into the B3-generated WebAssembly code. A follow-up patch will do imports. A few things of note: - Use Identifier instead of String. They get uniqued, we need them for the JSModuleNamespaceObject. This is safe because JSWebAssemblyModule creation is on the main thread. - JSWebAssemblyInstance needs to refer to the JSWebAssemblyModule used to create it, because the module owns the code, identifiers, etc. The world would be very sad if it got GC'd. - Instance.exports shouldn't use putWithoutTransition because it affects all Structures, whereas here each instance needs its own exports. - Expose the compiled functions, and pipe them to the InstanceConstructor. Start moving things around to split JSModuleRecord out into JS and WebAssembly parts. [0]: https://github.com/WebAssembly/design/blob/master/JS.md#webassemblyinstance-constructor * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * runtime/AbstractModuleRecord.cpp: Copied from Source/JavaScriptCore/runtime/JSModuleRecord.cpp, which I split in two (JSC::AbstractModuleRecord::AbstractModuleRecord): (JSC::AbstractModuleRecord::destroy): (JSC::AbstractModuleRecord::finishCreation): (JSC::AbstractModuleRecord::visitChildren): (JSC::AbstractModuleRecord::appendRequestedModule): (JSC::AbstractModuleRecord::addStarExportEntry): (JSC::AbstractModuleRecord::addImportEntry): (JSC::AbstractModuleRecord::addExportEntry): (JSC::identifierToJSValue): (JSC::AbstractModuleRecord::hostResolveImportedModule): (JSC::AbstractModuleRecord::ResolveQuery::ResolveQuery): (JSC::AbstractModuleRecord::ResolveQuery::isEmptyValue): (JSC::AbstractModuleRecord::ResolveQuery::isDeletedValue): (JSC::AbstractModuleRecord::ResolveQuery::Hash::hash): (JSC::AbstractModuleRecord::ResolveQuery::Hash::equal): (JSC::AbstractModuleRecord::cacheResolution): (JSC::getExportedNames): (JSC::AbstractModuleRecord::getModuleNamespace): (JSC::printableName): (JSC::AbstractModuleRecord::dump): * runtime/AbstractModuleRecord.h: Copied from Source/JavaScriptCore/runtime/JSModuleRecord.h. (JSC::AbstractModuleRecord::ImportEntry::isNamespace): (JSC::AbstractModuleRecord::sourceCode): (JSC::AbstractModuleRecord::moduleKey): (JSC::AbstractModuleRecord::requestedModules): (JSC::AbstractModuleRecord::exportEntries): (JSC::AbstractModuleRecord::importEntries): (JSC::AbstractModuleRecord::starExportEntries): (JSC::AbstractModuleRecord::declaredVariables): (JSC::AbstractModuleRecord::lexicalVariables): (JSC::AbstractModuleRecord::moduleEnvironment): * runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::init): (JSC::JSGlobalObject::visitChildren): * runtime/JSGlobalObject.h: (JSC::JSGlobalObject::webAssemblyModuleRecordStructure): (JSC::JSGlobalObject::webAssemblyFunctionStructure): * runtime/JSModuleEnvironment.cpp: (JSC::JSModuleEnvironment::create): (JSC::JSModuleEnvironment::finishCreation): (JSC::JSModuleEnvironment::getOwnPropertySlot): (JSC::JSModuleEnvironment::getOwnNonIndexPropertyNames): (JSC::JSModuleEnvironment::put): (JSC::JSModuleEnvironment::deleteProperty): * runtime/JSModuleEnvironment.h: (JSC::JSModuleEnvironment::create): (JSC::JSModuleEnvironment::offsetOfModuleRecord): (JSC::JSModuleEnvironment::allocationSize): (JSC::JSModuleEnvironment::moduleRecord): (JSC::JSModuleEnvironment::moduleRecordSlot): * runtime/JSModuleNamespaceObject.cpp: (JSC::JSModuleNamespaceObject::finishCreation): (JSC::JSModuleNamespaceObject::getOwnPropertySlot): * runtime/JSModuleNamespaceObject.h: (JSC::JSModuleNamespaceObject::create): (JSC::JSModuleNamespaceObject::moduleRecord): * runtime/JSModuleRecord.cpp: (JSC::JSModuleRecord::createStructure): (JSC::JSModuleRecord::create): (JSC::JSModuleRecord::JSModuleRecord): (JSC::JSModuleRecord::destroy): (JSC::JSModuleRecord::finishCreation): (JSC::JSModuleRecord::visitChildren): (JSC::JSModuleRecord::instantiateDeclarations): * runtime/JSModuleRecord.h: * runtime/JSScope.cpp: (JSC::abstractAccess): (JSC::JSScope::collectClosureVariablesUnderTDZ): * runtime/VM.cpp: (JSC::VM::VM): * runtime/VM.h: * wasm/JSWebAssembly.h: * wasm/WasmFormat.h: use Identifier instead of String * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parse): (JSC::Wasm::ModuleParser::parseType): (JSC::Wasm::ModuleParser::parseImport): fix off-by-one (JSC::Wasm::ModuleParser::parseFunction): (JSC::Wasm::ModuleParser::parseExport): * wasm/WasmModuleParser.h: (JSC::Wasm::ModuleParser::ModuleParser): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::run): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::create): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::module): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::create): (JSC::JSWebAssemblyModule::finishCreation): (JSC::JSWebAssemblyModule::visitChildren): * wasm/js/JSWebAssemblyModule.h: (JSC::JSWebAssemblyModule::moduleInformation): (JSC::JSWebAssemblyModule::compiledFunctions): (JSC::JSWebAssemblyModule::exportSymbolTable): * wasm/js/WebAssemblyFunction.cpp: Added. (JSC::callWebAssemblyFunction): (JSC::WebAssemblyFunction::create): (JSC::WebAssemblyFunction::createStructure): (JSC::WebAssemblyFunction::WebAssemblyFunction): (JSC::WebAssemblyFunction::visitChildren): (JSC::WebAssemblyFunction::finishCreation): * wasm/js/WebAssemblyFunction.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.h. (JSC::CallableWebAssemblyFunction::CallableWebAssemblyFunction): (JSC::WebAssemblyFunction::webAssemblyFunctionCell): * wasm/js/WebAssemblyFunctionCell.cpp: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h. (JSC::WebAssemblyFunctionCell::create): (JSC::WebAssemblyFunctionCell::WebAssemblyFunctionCell): (JSC::WebAssemblyFunctionCell::destroy): (JSC::WebAssemblyFunctionCell::createStructure): * wasm/js/WebAssemblyFunctionCell.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h. (JSC::WebAssemblyFunctionCell::function): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): * wasm/js/WebAssemblyModuleRecord.cpp: Added. (JSC::WebAssemblyModuleRecord::createStructure): (JSC::WebAssemblyModuleRecord::create): (JSC::WebAssemblyModuleRecord::WebAssemblyModuleRecord): (JSC::WebAssemblyModuleRecord::destroy): (JSC::WebAssemblyModuleRecord::finishCreation): (JSC::WebAssemblyModuleRecord::visitChildren): (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyModuleRecord.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.h. Source/WTF: * wtf/Expected.h: (WTF::ExpectedDetail::destroy): silence a warning Canonical link: https://commits.webkit.org/182809@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209123 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-30 07:22:17 +00:00
template<class T, std::enable_if_t<std::is_trivially_destructible<T>::value>* = nullptr> void destroy(T&) { }
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
template<class T, std::enable_if_t<!std::is_trivially_destructible<T>::value && (std::is_class<T>::value || std::is_union<T>::value)>* = nullptr> void destroy(T& t) { t.~T(); }
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
template<class T, class E>
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
union constexpr_storage {
typedef T value_type;
typedef E error_type;
typedef unexpected<E> unexpected_type;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
char dummy;
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
value_type val;
error_type err;
constexpr constexpr_storage() : dummy() { }
constexpr constexpr_storage(value_tag_t) : val() { }
constexpr constexpr_storage(error_tag_t) : err() { }
template<typename U = T>
constexpr constexpr_storage(value_tag_t, U&& v) : val(std::forward<U>(v)) { }
template<typename U = E>
constexpr constexpr_storage(error_tag_t, U&& e) : err(std::forward<U>(e)) { }
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
~constexpr_storage() = default;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
};
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
template<class T, class E>
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
union storage {
typedef T value_type;
typedef E error_type;
typedef unexpected<E> unexpected_type;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
char dummy;
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
value_type val;
error_type err;
constexpr storage() : dummy() { }
constexpr storage(value_tag_t) : val() { }
constexpr storage(error_tag_t) : err() { }
constexpr storage(value_tag_t, const value_type& val) : val(val) { }
constexpr storage(value_tag_t, value_type&& val) : val(std::forward<value_type>(val)) { }
constexpr storage(error_tag_t, const error_type& err) : err(err) { }
constexpr storage(error_tag_t, error_type&& err) : err(std::forward<error_type>(err)) { }
~storage() { }
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
};
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
template<class E>
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
union constexpr_storage<void, E> {
typedef void value_type;
typedef E error_type;
typedef unexpected<E> unexpected_type;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
char dummy;
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
error_type err;
constexpr constexpr_storage() : dummy() { }
constexpr constexpr_storage(value_tag_t) : dummy() { }
constexpr constexpr_storage(error_tag_t) : err() { }
constexpr constexpr_storage(error_tag_t, const error_type& e) : err(e) { }
~constexpr_storage() = default;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
};
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
template<class E>
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
union storage<void, E> {
typedef void value_type;
typedef E error_type;
typedef unexpected<E> unexpected_type;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
char dummy;
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
error_type err;
constexpr storage() : dummy() { }
constexpr storage(value_tag_t) : dummy() { }
constexpr storage(error_tag_t) : err() { }
constexpr storage(error_tag_t, const error_type& err) : err(err) { }
constexpr storage(error_tag_t, error_type&& err) : err(std::forward<error_type>(err)) { }
~storage() { }
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
};
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
template<class T, class E>
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
struct constexpr_base {
typedef T value_type;
typedef E error_type;
typedef unexpected<E> unexpected_type;
constexpr_storage<value_type, error_type> s;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
bool has;
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
constexpr constexpr_base() : s(), has(true) { }
constexpr constexpr_base(value_tag_t tag) : s(tag), has(true) { }
constexpr constexpr_base(error_tag_t tag) : s(tag), has(false) { }
template<typename U = T>
constexpr constexpr_base(value_tag_t tag, U&& val) : s(tag, std::forward<U>(val)), has(true) { }
template<typename U = E>
constexpr constexpr_base(error_tag_t tag, U&& err) : s(tag, std::forward<U>(err)), has(false) { }
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
~constexpr_base() = default;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
};
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
template<class T, class E>
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
struct base {
typedef T value_type;
typedef E error_type;
typedef unexpected<E> unexpected_type;
storage<value_type, error_type> s;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
bool has;
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
constexpr base() : s(), has(true) { }
constexpr base(value_tag_t tag) : s(tag), has(true) { }
constexpr base(error_tag_t tag) : s(tag), has(false) { }
constexpr base(value_tag_t tag, const value_type& val) : s(tag, val), has(true) { }
constexpr base(value_tag_t tag, value_type&& val) : s(tag, std::forward<value_type>(val)), has(true) { }
constexpr base(error_tag_t tag, const error_type& err) : s(tag, err), has(false) { }
constexpr base(error_tag_t tag, error_type&& err) : s(tag, std::forward<error_type>(err)), has(false) { }
base(const base& o)
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
: has(o.has)
{
if (has)
::new (std::addressof(s.val)) value_type(o.s.val);
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
else
::new (std::addressof(s.err)) error_type(o.s.err);
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
}
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
base(base&& o)
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
: has(o.has)
{
if (has)
::new (std::addressof(s.val)) value_type(std::move(o.s.val));
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
else
::new (std::addressof(s.err)) error_type(std::move(o.s.err));
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
}
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
~base()
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
{
if (has)
destroy(s.val);
else
destroy(s.err);
}
};
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
template<class E>
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
struct constexpr_base<void, E> {
typedef void value_type;
typedef E error_type;
typedef unexpected<E> unexpected_type;
constexpr_storage<value_type, error_type> s;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
bool has;
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
constexpr constexpr_base() : s(), has(true) { }
constexpr constexpr_base(value_tag_t tag) : s(tag), has(true) { }
constexpr constexpr_base(error_tag_t tag) : s(tag), has(false) { }
constexpr constexpr_base(error_tag_t tag, const error_type& err) : s(tag, err), has(false) { }
constexpr constexpr_base(error_tag_t tag, error_type&& err) : s(tag, std::forward<error_type>(err)), has(false) { }
~constexpr_base() = default;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
};
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
template<class E>
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
struct base<void, E> {
typedef void value_type;
typedef E error_type;
typedef unexpected<E> unexpected_type;
storage<value_type, error_type> s;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
bool has;
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
constexpr base() : s(), has(true) { }
constexpr base(value_tag_t tag) : s(tag), has(true) { }
constexpr base(error_tag_t tag) : s(tag), has(false) { }
constexpr base(error_tag_t tag, const error_type& err) : s(tag, err), has(false) { }
constexpr base(error_tag_t tag, error_type&& err) : s(tag, std::forward<error_type>(err)), has(false) { }
base(const base& o)
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
: has(o.has)
{
if (!has)
::new (std::addressof(s.err)) error_type(o.s.err);
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
}
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
base(base&& o)
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
: has(o.has)
{
if (!has)
::new (std::addressof(s.err)) error_type(std::move(o.s.err));
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
}
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
~base()
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
{
if (!has)
destroy(s.err);
}
};
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
template<class T, class E>
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
using base_select = typename std::conditional<
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
((std::is_void<T>::value || std::is_trivially_destructible<T>::value)
&& std::is_trivially_destructible<E>::value),
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
constexpr_base<typename std::remove_const<T>::type, typename std::remove_const<E>::type>,
base<typename std::remove_const<T>::type, typename std::remove_const<E>::type>
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
>::type;
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
} // namespace __expected_detail
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
template<class T, class E>
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
class expected : private __expected_detail::base_select<T, E> {
[WTF][JSC] Make JSC and WTF aggressively-fast-malloced https://bugs.webkit.org/show_bug.cgi?id=200611 Reviewed by Saam Barati. Source/JavaScriptCore: This patch aggressively puts many classes into FastMalloc. In JSC side, we grep `std::make_unique` etc. to find potentially system-malloc-allocated classes. After this patch, all the JSC related allocations in JetStream2 cli is done from bmalloc. In the future, it would be nice that we add `WTF::makeUnique<T>` helper function and throw a compile error if `T` is not FastMalloc annotated[1]. Putting WebKit classes in FastMalloc has many benefits. 1. Simply, it is fast. 2. vmmap can tell the amount of memory used for WebKit. 3. bmalloc can isolate WebKit memory allocation from the rest of the world. This is useful since we can know more about what component is corrupting the memory from the memory corruption crash. [1]: https://bugs.webkit.org/show_bug.cgi?id=200620 * API/ObjCCallbackFunction.mm: * assembler/AbstractMacroAssembler.h: * b3/B3PhiChildren.h: * b3/air/AirAllocateRegistersAndStackAndGenerateCode.h: * b3/air/AirDisassembler.h: * bytecode/AccessCaseSnippetParams.h: * bytecode/CallVariant.h: * bytecode/DeferredSourceDump.h: * bytecode/ExecutionCounter.h: * bytecode/GetByIdStatus.h: * bytecode/GetByIdVariant.h: * bytecode/InByIdStatus.h: * bytecode/InByIdVariant.h: * bytecode/InstanceOfStatus.h: * bytecode/InstanceOfVariant.h: * bytecode/PutByIdStatus.h: * bytecode/PutByIdVariant.h: * bytecode/ValueProfile.h: * dfg/DFGAbstractInterpreter.h: * dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::newVariableAccessData): * dfg/DFGFlowIndexing.h: * dfg/DFGFlowMap.h: * dfg/DFGLiveCatchVariablePreservationPhase.cpp: (JSC::DFG::LiveCatchVariablePreservationPhase::newVariableAccessData): * dfg/DFGMaximalFlushInsertionPhase.cpp: (JSC::DFG::MaximalFlushInsertionPhase::newVariableAccessData): * dfg/DFGOSRExit.h: * dfg/DFGSpeculativeJIT.h: * dfg/DFGVariableAccessData.h: * disassembler/ARM64/A64DOpcode.h: * inspector/remote/socket/RemoteInspectorMessageParser.h: * inspector/remote/socket/RemoteInspectorSocket.h: * inspector/remote/socket/RemoteInspectorSocketEndpoint.h: * jit/PCToCodeOriginMap.h: * runtime/BasicBlockLocation.h: * runtime/DoublePredictionFuzzerAgent.h: * runtime/JSRunLoopTimer.h: * runtime/PromiseDeferredTimer.h: (JSC::PromiseDeferredTimer::create): PromiseDeferredTimer should be allocated as `Ref<>` instead of `std::unique_ptr` since it is inheriting ThreadSafeRefCounted<>. Holding such a class with std::unique_ptr could lead to potentially dangerous operations (like, someone holds it with Ref<> while it is deleted by std::unique_ptr<>). * runtime/RandomizingFuzzerAgent.h: * runtime/SymbolTable.h: * runtime/VM.cpp: (JSC::VM::VM): * runtime/VM.h: * tools/JSDollarVM.cpp: * tools/SigillCrashAnalyzer.cpp: * wasm/WasmFormat.h: * wasm/WasmMemory.cpp: * wasm/WasmSignature.h: * yarr/YarrJIT.h: Source/WebCore: Changed the accessor since we changed std::unique_ptr to Ref for this field. No behavior change. * bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::addTimerSetNotification): (WebCore::WorkerScriptController::removeTimerSetNotification): Source/WTF: WTF has many data structures, in particular, containers. And these containers can be allocated like `std::make_unique<Container>()`. Without WTF_MAKE_FAST_ALLOCATED, this container itself is allocated from the system malloc. This patch attaches WTF_MAKE_FAST_ALLOCATED more aggressively not to allocate them from the system malloc. And we add some `final` to containers and classes that would be never inherited. * wtf/Assertions.cpp: * wtf/Atomics.h: * wtf/AutodrainedPool.h: * wtf/Bag.h: (WTF::Bag::Bag): Deleted. (WTF::Bag::~Bag): Deleted. (WTF::Bag::clear): Deleted. (WTF::Bag::add): Deleted. (WTF::Bag::iterator::iterator): Deleted. (WTF::Bag::iterator::operator! const): Deleted. (WTF::Bag::iterator::operator* const): Deleted. (WTF::Bag::iterator::operator++): Deleted. (WTF::Bag::iterator::operator== const): Deleted. (WTF::Bag::iterator::operator!= const): Deleted. (WTF::Bag::begin): Deleted. (WTF::Bag::begin const): Deleted. (WTF::Bag::end const): Deleted. (WTF::Bag::isEmpty const): Deleted. (WTF::Bag::unwrappedHead const): Deleted. * wtf/BitVector.h: (WTF::BitVector::BitVector): Deleted. (WTF::BitVector::~BitVector): Deleted. (WTF::BitVector::operator=): Deleted. (WTF::BitVector::size const): Deleted. (WTF::BitVector::ensureSize): Deleted. (WTF::BitVector::quickGet const): Deleted. (WTF::BitVector::quickSet): Deleted. (WTF::BitVector::quickClear): Deleted. (WTF::BitVector::get const): Deleted. (WTF::BitVector::contains const): Deleted. (WTF::BitVector::set): Deleted. (WTF::BitVector::add): Deleted. (WTF::BitVector::ensureSizeAndSet): Deleted. (WTF::BitVector::clear): Deleted. (WTF::BitVector::remove): Deleted. (WTF::BitVector::merge): Deleted. (WTF::BitVector::filter): Deleted. (WTF::BitVector::exclude): Deleted. (WTF::BitVector::bitCount const): Deleted. (WTF::BitVector::isEmpty const): Deleted. (WTF::BitVector::findBit const): Deleted. (WTF::BitVector::isEmptyValue const): Deleted. (WTF::BitVector::isDeletedValue const): Deleted. (WTF::BitVector::isEmptyOrDeletedValue const): Deleted. (WTF::BitVector::operator== const): Deleted. (WTF::BitVector::hash const): Deleted. (WTF::BitVector::iterator::iterator): Deleted. (WTF::BitVector::iterator::operator* const): Deleted. (WTF::BitVector::iterator::operator++): Deleted. (WTF::BitVector::iterator::isAtEnd const): Deleted. (WTF::BitVector::iterator::operator== const): Deleted. (WTF::BitVector::iterator::operator!= const): Deleted. (WTF::BitVector::begin const): Deleted. (WTF::BitVector::end const): Deleted. (WTF::BitVector::bitsInPointer): Deleted. (WTF::BitVector::maxInlineBits): Deleted. (WTF::BitVector::byteCount): Deleted. (WTF::BitVector::makeInlineBits): Deleted. (WTF::BitVector::cleanseInlineBits): Deleted. (WTF::BitVector::bitCount): Deleted. (WTF::BitVector::findBitFast const): Deleted. (WTF::BitVector::findBitSimple const): Deleted. (WTF::BitVector::OutOfLineBits::numBits const): Deleted. (WTF::BitVector::OutOfLineBits::numWords const): Deleted. (WTF::BitVector::OutOfLineBits::bits): Deleted. (WTF::BitVector::OutOfLineBits::bits const): Deleted. (WTF::BitVector::OutOfLineBits::OutOfLineBits): Deleted. (WTF::BitVector::isInline const): Deleted. (WTF::BitVector::outOfLineBits const): Deleted. (WTF::BitVector::outOfLineBits): Deleted. (WTF::BitVector::bits): Deleted. (WTF::BitVector::bits const): Deleted. * wtf/Bitmap.h: (WTF::Bitmap::size): Deleted. (WTF::Bitmap::iterator::iterator): Deleted. (WTF::Bitmap::iterator::operator* const): Deleted. (WTF::Bitmap::iterator::operator++): Deleted. (WTF::Bitmap::iterator::operator== const): Deleted. (WTF::Bitmap::iterator::operator!= const): Deleted. (WTF::Bitmap::begin const): Deleted. (WTF::Bitmap::end const): Deleted. * wtf/Box.h: * wtf/BumpPointerAllocator.h: * wtf/CPUTime.h: * wtf/CheckedBoolean.h: * wtf/CommaPrinter.h: (WTF::CommaPrinter::CommaPrinter): Deleted. (WTF::CommaPrinter::dump const): Deleted. (WTF::CommaPrinter::didPrint const): Deleted. * wtf/CompactPointerTuple.h: (WTF::CompactPointerTuple::encodeType): Deleted. (WTF::CompactPointerTuple::decodeType): Deleted. (WTF::CompactPointerTuple::CompactPointerTuple): Deleted. (WTF::CompactPointerTuple::pointer const): Deleted. (WTF::CompactPointerTuple::setPointer): Deleted. (WTF::CompactPointerTuple::type const): Deleted. (WTF::CompactPointerTuple::setType): Deleted. * wtf/CompilationThread.h: (WTF::CompilationScope::CompilationScope): Deleted. (WTF::CompilationScope::~CompilationScope): Deleted. (WTF::CompilationScope::leaveEarly): Deleted. * wtf/CompletionHandler.h: (WTF::CompletionHandler<Out): (WTF::Detail::CallableWrapper<CompletionHandler<Out): (WTF::CompletionHandlerCallingScope::CompletionHandlerCallingScope): Deleted. (WTF::CompletionHandlerCallingScope::~CompletionHandlerCallingScope): Deleted. (WTF::CompletionHandlerCallingScope::CompletionHandler<void): Deleted. * wtf/ConcurrentBuffer.h: (WTF::ConcurrentBuffer::ConcurrentBuffer): Deleted. (WTF::ConcurrentBuffer::~ConcurrentBuffer): Deleted. (WTF::ConcurrentBuffer::growExact): Deleted. (WTF::ConcurrentBuffer::grow): Deleted. (WTF::ConcurrentBuffer::array const): Deleted. (WTF::ConcurrentBuffer::operator[]): Deleted. (WTF::ConcurrentBuffer::operator[] const): Deleted. (WTF::ConcurrentBuffer::createArray): Deleted. * wtf/ConcurrentPtrHashSet.h: (WTF::ConcurrentPtrHashSet::contains): Deleted. (WTF::ConcurrentPtrHashSet::add): Deleted. (WTF::ConcurrentPtrHashSet::size const): Deleted. (WTF::ConcurrentPtrHashSet::Table::maxLoad const): Deleted. (WTF::ConcurrentPtrHashSet::hash): Deleted. (WTF::ConcurrentPtrHashSet::cast): Deleted. (WTF::ConcurrentPtrHashSet::containsImpl const): Deleted. (WTF::ConcurrentPtrHashSet::addImpl): Deleted. * wtf/ConcurrentVector.h: (WTF::ConcurrentVector::~ConcurrentVector): Deleted. (WTF::ConcurrentVector::size const): Deleted. (WTF::ConcurrentVector::isEmpty const): Deleted. (WTF::ConcurrentVector::at): Deleted. (WTF::ConcurrentVector::at const): Deleted. (WTF::ConcurrentVector::operator[]): Deleted. (WTF::ConcurrentVector::operator[] const): Deleted. (WTF::ConcurrentVector::first): Deleted. (WTF::ConcurrentVector::first const): Deleted. (WTF::ConcurrentVector::last): Deleted. (WTF::ConcurrentVector::last const): Deleted. (WTF::ConcurrentVector::takeLast): Deleted. (WTF::ConcurrentVector::append): Deleted. (WTF::ConcurrentVector::alloc): Deleted. (WTF::ConcurrentVector::removeLast): Deleted. (WTF::ConcurrentVector::grow): Deleted. (WTF::ConcurrentVector::begin): Deleted. (WTF::ConcurrentVector::end): Deleted. (WTF::ConcurrentVector::segmentExistsFor): Deleted. (WTF::ConcurrentVector::segmentFor): Deleted. (WTF::ConcurrentVector::subscriptFor): Deleted. (WTF::ConcurrentVector::ensureSegmentsFor): Deleted. (WTF::ConcurrentVector::ensureSegment): Deleted. (WTF::ConcurrentVector::allocateSegment): Deleted. * wtf/Condition.h: (WTF::Condition::waitUntil): Deleted. (WTF::Condition::waitFor): Deleted. (WTF::Condition::wait): Deleted. (WTF::Condition::notifyOne): Deleted. (WTF::Condition::notifyAll): Deleted. * wtf/CountingLock.h: (WTF::CountingLock::LockHooks::lockHook): Deleted. (WTF::CountingLock::LockHooks::unlockHook): Deleted. (WTF::CountingLock::LockHooks::parkHook): Deleted. (WTF::CountingLock::LockHooks::handoffHook): Deleted. (WTF::CountingLock::tryLock): Deleted. (WTF::CountingLock::lock): Deleted. (WTF::CountingLock::unlock): Deleted. (WTF::CountingLock::isHeld const): Deleted. (WTF::CountingLock::isLocked const): Deleted. (WTF::CountingLock::Count::operator bool const): Deleted. (WTF::CountingLock::Count::operator== const): Deleted. (WTF::CountingLock::Count::operator!= const): Deleted. (WTF::CountingLock::tryOptimisticRead): Deleted. (WTF::CountingLock::validate): Deleted. (WTF::CountingLock::doOptimizedRead): Deleted. (WTF::CountingLock::tryOptimisticFencelessRead): Deleted. (WTF::CountingLock::fencelessValidate): Deleted. (WTF::CountingLock::doOptimizedFencelessRead): Deleted. (WTF::CountingLock::getCount): Deleted. * wtf/CrossThreadQueue.h: * wtf/CrossThreadTask.h: * wtf/CryptographicallyRandomNumber.cpp: * wtf/DataMutex.h: * wtf/DateMath.h: * wtf/Deque.h: (WTF::Deque::size const): Deleted. (WTF::Deque::isEmpty const): Deleted. (WTF::Deque::begin): Deleted. (WTF::Deque::end): Deleted. (WTF::Deque::begin const): Deleted. (WTF::Deque::end const): Deleted. (WTF::Deque::rbegin): Deleted. (WTF::Deque::rend): Deleted. (WTF::Deque::rbegin const): Deleted. (WTF::Deque::rend const): Deleted. (WTF::Deque::first): Deleted. (WTF::Deque::first const): Deleted. (WTF::Deque::last): Deleted. (WTF::Deque::last const): Deleted. (WTF::Deque::append): Deleted. * wtf/Dominators.h: * wtf/DoublyLinkedList.h: * wtf/Expected.h: * wtf/FastBitVector.h: * wtf/FileMetadata.h: * wtf/FileSystem.h: * wtf/GraphNodeWorklist.h: * wtf/GregorianDateTime.h: (WTF::GregorianDateTime::GregorianDateTime): Deleted. (WTF::GregorianDateTime::year const): Deleted. (WTF::GregorianDateTime::month const): Deleted. (WTF::GregorianDateTime::yearDay const): Deleted. (WTF::GregorianDateTime::monthDay const): Deleted. (WTF::GregorianDateTime::weekDay const): Deleted. (WTF::GregorianDateTime::hour const): Deleted. (WTF::GregorianDateTime::minute const): Deleted. (WTF::GregorianDateTime::second const): Deleted. (WTF::GregorianDateTime::utcOffset const): Deleted. (WTF::GregorianDateTime::isDST const): Deleted. (WTF::GregorianDateTime::setYear): Deleted. (WTF::GregorianDateTime::setMonth): Deleted. (WTF::GregorianDateTime::setYearDay): Deleted. (WTF::GregorianDateTime::setMonthDay): Deleted. (WTF::GregorianDateTime::setWeekDay): Deleted. (WTF::GregorianDateTime::setHour): Deleted. (WTF::GregorianDateTime::setMinute): Deleted. (WTF::GregorianDateTime::setSecond): Deleted. (WTF::GregorianDateTime::setUtcOffset): Deleted. (WTF::GregorianDateTime::setIsDST): Deleted. (WTF::GregorianDateTime::operator tm const): Deleted. (WTF::GregorianDateTime::copyFrom): Deleted. * wtf/HashTable.h: * wtf/Hasher.h: * wtf/HexNumber.h: * wtf/Indenter.h: * wtf/IndexMap.h: * wtf/IndexSet.h: * wtf/IndexSparseSet.h: * wtf/IndexedContainerIterator.h: * wtf/Insertion.h: * wtf/IteratorAdaptors.h: * wtf/IteratorRange.h: * wtf/KeyValuePair.h: * wtf/ListHashSet.h: (WTF::ListHashSet::begin): Deleted. (WTF::ListHashSet::end): Deleted. (WTF::ListHashSet::begin const): Deleted. (WTF::ListHashSet::end const): Deleted. (WTF::ListHashSet::random): Deleted. (WTF::ListHashSet::random const): Deleted. (WTF::ListHashSet::rbegin): Deleted. (WTF::ListHashSet::rend): Deleted. (WTF::ListHashSet::rbegin const): Deleted. (WTF::ListHashSet::rend const): Deleted. * wtf/Liveness.h: * wtf/LocklessBag.h: (WTF::LocklessBag::LocklessBag): Deleted. (WTF::LocklessBag::add): Deleted. (WTF::LocklessBag::iterate): Deleted. (WTF::LocklessBag::consumeAll): Deleted. (WTF::LocklessBag::consumeAllWithNode): Deleted. (WTF::LocklessBag::~LocklessBag): Deleted. * wtf/LoggingHashID.h: * wtf/MD5.h: * wtf/MachSendRight.h: * wtf/MainThreadData.h: * wtf/Markable.h: * wtf/MediaTime.h: * wtf/MemoryPressureHandler.h: * wtf/MessageQueue.h: (WTF::MessageQueue::MessageQueue): Deleted. * wtf/MetaAllocator.h: * wtf/MonotonicTime.h: (WTF::MonotonicTime::MonotonicTime): Deleted. (WTF::MonotonicTime::fromRawSeconds): Deleted. (WTF::MonotonicTime::infinity): Deleted. (WTF::MonotonicTime::nan): Deleted. (WTF::MonotonicTime::secondsSinceEpoch const): Deleted. (WTF::MonotonicTime::approximateMonotonicTime const): Deleted. (WTF::MonotonicTime::operator bool const): Deleted. (WTF::MonotonicTime::operator+ const): Deleted. (WTF::MonotonicTime::operator- const): Deleted. (WTF::MonotonicTime::operator% const): Deleted. (WTF::MonotonicTime::operator+=): Deleted. (WTF::MonotonicTime::operator-=): Deleted. (WTF::MonotonicTime::operator== const): Deleted. (WTF::MonotonicTime::operator!= const): Deleted. (WTF::MonotonicTime::operator< const): Deleted. (WTF::MonotonicTime::operator> const): Deleted. (WTF::MonotonicTime::operator<= const): Deleted. (WTF::MonotonicTime::operator>= const): Deleted. (WTF::MonotonicTime::isolatedCopy const): Deleted. (WTF::MonotonicTime::encode const): Deleted. (WTF::MonotonicTime::decode): Deleted. * wtf/NaturalLoops.h: * wtf/NoLock.h: * wtf/OSAllocator.h: * wtf/OptionSet.h: * wtf/Optional.h: * wtf/OrderMaker.h: * wtf/Packed.h: (WTF::alignof): * wtf/PackedIntVector.h: (WTF::PackedIntVector::PackedIntVector): Deleted. (WTF::PackedIntVector::operator=): Deleted. (WTF::PackedIntVector::size const): Deleted. (WTF::PackedIntVector::ensureSize): Deleted. (WTF::PackedIntVector::resize): Deleted. (WTF::PackedIntVector::clearAll): Deleted. (WTF::PackedIntVector::get const): Deleted. (WTF::PackedIntVector::set): Deleted. (WTF::PackedIntVector::mask): Deleted. * wtf/PageBlock.h: * wtf/ParallelJobsOpenMP.h: * wtf/ParkingLot.h: * wtf/PriorityQueue.h: (WTF::PriorityQueue::size const): Deleted. (WTF::PriorityQueue::isEmpty const): Deleted. (WTF::PriorityQueue::enqueue): Deleted. (WTF::PriorityQueue::peek const): Deleted. (WTF::PriorityQueue::dequeue): Deleted. (WTF::PriorityQueue::decreaseKey): Deleted. (WTF::PriorityQueue::increaseKey): Deleted. (WTF::PriorityQueue::begin const): Deleted. (WTF::PriorityQueue::end const): Deleted. (WTF::PriorityQueue::isValidHeap const): Deleted. (WTF::PriorityQueue::parentOf): Deleted. (WTF::PriorityQueue::leftChildOf): Deleted. (WTF::PriorityQueue::rightChildOf): Deleted. (WTF::PriorityQueue::siftUp): Deleted. (WTF::PriorityQueue::siftDown): Deleted. * wtf/RandomDevice.h: * wtf/Range.h: * wtf/RangeSet.h: (WTF::RangeSet::RangeSet): Deleted. (WTF::RangeSet::~RangeSet): Deleted. (WTF::RangeSet::add): Deleted. (WTF::RangeSet::contains const): Deleted. (WTF::RangeSet::overlaps const): Deleted. (WTF::RangeSet::clear): Deleted. (WTF::RangeSet::dump const): Deleted. (WTF::RangeSet::dumpRaw const): Deleted. (WTF::RangeSet::begin const): Deleted. (WTF::RangeSet::end const): Deleted. (WTF::RangeSet::addAll): Deleted. (WTF::RangeSet::compact): Deleted. (WTF::RangeSet::overlapsNonEmpty): Deleted. (WTF::RangeSet::subsumesNonEmpty): Deleted. (WTF::RangeSet::findRange const): Deleted. * wtf/RecursableLambda.h: * wtf/RedBlackTree.h: (WTF::RedBlackTree::Node::successor const): Deleted. (WTF::RedBlackTree::Node::predecessor const): Deleted. (WTF::RedBlackTree::Node::successor): Deleted. (WTF::RedBlackTree::Node::predecessor): Deleted. (WTF::RedBlackTree::Node::reset): Deleted. (WTF::RedBlackTree::Node::parent const): Deleted. (WTF::RedBlackTree::Node::setParent): Deleted. (WTF::RedBlackTree::Node::left const): Deleted. (WTF::RedBlackTree::Node::setLeft): Deleted. (WTF::RedBlackTree::Node::right const): Deleted. (WTF::RedBlackTree::Node::setRight): Deleted. (WTF::RedBlackTree::Node::color const): Deleted. (WTF::RedBlackTree::Node::setColor): Deleted. (WTF::RedBlackTree::RedBlackTree): Deleted. (WTF::RedBlackTree::insert): Deleted. (WTF::RedBlackTree::remove): Deleted. (WTF::RedBlackTree::findExact const): Deleted. (WTF::RedBlackTree::findLeastGreaterThanOrEqual const): Deleted. (WTF::RedBlackTree::findGreatestLessThanOrEqual const): Deleted. (WTF::RedBlackTree::first const): Deleted. (WTF::RedBlackTree::last const): Deleted. (WTF::RedBlackTree::size): Deleted. (WTF::RedBlackTree::isEmpty): Deleted. (WTF::RedBlackTree::treeMinimum): Deleted. (WTF::RedBlackTree::treeMaximum): Deleted. (WTF::RedBlackTree::treeInsert): Deleted. (WTF::RedBlackTree::leftRotate): Deleted. (WTF::RedBlackTree::rightRotate): Deleted. (WTF::RedBlackTree::removeFixup): Deleted. * wtf/ResourceUsage.h: * wtf/RunLoop.cpp: * wtf/RunLoopTimer.h: * wtf/SHA1.h: * wtf/Seconds.h: (WTF::Seconds::Seconds): Deleted. (WTF::Seconds::value const): Deleted. (WTF::Seconds::minutes const): Deleted. (WTF::Seconds::seconds const): Deleted. (WTF::Seconds::milliseconds const): Deleted. (WTF::Seconds::microseconds const): Deleted. (WTF::Seconds::nanoseconds const): Deleted. (WTF::Seconds::minutesAs const): Deleted. (WTF::Seconds::secondsAs const): Deleted. (WTF::Seconds::millisecondsAs const): Deleted. (WTF::Seconds::microsecondsAs const): Deleted. (WTF::Seconds::nanosecondsAs const): Deleted. (WTF::Seconds::fromMinutes): Deleted. (WTF::Seconds::fromHours): Deleted. (WTF::Seconds::fromMilliseconds): Deleted. (WTF::Seconds::fromMicroseconds): Deleted. (WTF::Seconds::fromNanoseconds): Deleted. (WTF::Seconds::infinity): Deleted. (WTF::Seconds::nan): Deleted. (WTF::Seconds::operator bool const): Deleted. (WTF::Seconds::operator+ const): Deleted. (WTF::Seconds::operator- const): Deleted. (WTF::Seconds::operator* const): Deleted. (WTF::Seconds::operator/ const): Deleted. (WTF::Seconds::operator% const): Deleted. (WTF::Seconds::operator+=): Deleted. (WTF::Seconds::operator-=): Deleted. (WTF::Seconds::operator*=): Deleted. (WTF::Seconds::operator/=): Deleted. (WTF::Seconds::operator%=): Deleted. (WTF::Seconds::operator== const): Deleted. (WTF::Seconds::operator!= const): Deleted. (WTF::Seconds::operator< const): Deleted. (WTF::Seconds::operator> const): Deleted. (WTF::Seconds::operator<= const): Deleted. (WTF::Seconds::operator>= const): Deleted. (WTF::Seconds::isolatedCopy const): Deleted. (WTF::Seconds::encode const): Deleted. (WTF::Seconds::decode): Deleted. * wtf/SegmentedVector.h: (WTF::SegmentedVector::~SegmentedVector): Deleted. (WTF::SegmentedVector::size const): Deleted. (WTF::SegmentedVector::isEmpty const): Deleted. (WTF::SegmentedVector::at): Deleted. (WTF::SegmentedVector::at const): Deleted. (WTF::SegmentedVector::operator[]): Deleted. (WTF::SegmentedVector::operator[] const): Deleted. (WTF::SegmentedVector::first): Deleted. (WTF::SegmentedVector::first const): Deleted. (WTF::SegmentedVector::last): Deleted. (WTF::SegmentedVector::last const): Deleted. (WTF::SegmentedVector::takeLast): Deleted. (WTF::SegmentedVector::append): Deleted. (WTF::SegmentedVector::alloc): Deleted. (WTF::SegmentedVector::removeLast): Deleted. (WTF::SegmentedVector::grow): Deleted. (WTF::SegmentedVector::clear): Deleted. (WTF::SegmentedVector::begin): Deleted. (WTF::SegmentedVector::end): Deleted. (WTF::SegmentedVector::shrinkToFit): Deleted. (WTF::SegmentedVector::deleteAllSegments): Deleted. (WTF::SegmentedVector::segmentExistsFor): Deleted. (WTF::SegmentedVector::segmentFor): Deleted. (WTF::SegmentedVector::subscriptFor): Deleted. (WTF::SegmentedVector::ensureSegmentsFor): Deleted. (WTF::SegmentedVector::ensureSegment): Deleted. (WTF::SegmentedVector::allocateSegment): Deleted. * wtf/SetForScope.h: * wtf/SingleRootGraph.h: * wtf/SinglyLinkedList.h: * wtf/SmallPtrSet.h: * wtf/SpanningTree.h: * wtf/Spectrum.h: * wtf/StackBounds.h: * wtf/StackShot.h: * wtf/StackShotProfiler.h: * wtf/StackStats.h: * wtf/StackTrace.h: * wtf/StreamBuffer.h: * wtf/SynchronizedFixedQueue.h: (WTF::SynchronizedFixedQueue::create): Deleted. (WTF::SynchronizedFixedQueue::open): Deleted. (WTF::SynchronizedFixedQueue::close): Deleted. (WTF::SynchronizedFixedQueue::isOpen): Deleted. (WTF::SynchronizedFixedQueue::enqueue): Deleted. (WTF::SynchronizedFixedQueue::dequeue): Deleted. (WTF::SynchronizedFixedQueue::SynchronizedFixedQueue): Deleted. * wtf/SystemTracing.h: * wtf/ThreadGroup.h: (WTF::ThreadGroup::create): Deleted. (WTF::ThreadGroup::threads const): Deleted. (WTF::ThreadGroup::getLock): Deleted. (WTF::ThreadGroup::weakFromThis): Deleted. * wtf/ThreadSpecific.h: * wtf/ThreadingPrimitives.h: (WTF::Mutex::impl): Deleted. * wtf/TimeWithDynamicClockType.h: (WTF::TimeWithDynamicClockType::TimeWithDynamicClockType): Deleted. (WTF::TimeWithDynamicClockType::fromRawSeconds): Deleted. (WTF::TimeWithDynamicClockType::secondsSinceEpoch const): Deleted. (WTF::TimeWithDynamicClockType::clockType const): Deleted. (WTF::TimeWithDynamicClockType::withSameClockAndRawSeconds const): Deleted. (WTF::TimeWithDynamicClockType::operator bool const): Deleted. (WTF::TimeWithDynamicClockType::operator+ const): Deleted. (WTF::TimeWithDynamicClockType::operator- const): Deleted. (WTF::TimeWithDynamicClockType::operator+=): Deleted. (WTF::TimeWithDynamicClockType::operator-=): Deleted. (WTF::TimeWithDynamicClockType::operator== const): Deleted. (WTF::TimeWithDynamicClockType::operator!= const): Deleted. * wtf/TimingScope.h: * wtf/TinyLRUCache.h: * wtf/TinyPtrSet.h: * wtf/URLParser.cpp: * wtf/URLParser.h: * wtf/Unexpected.h: * wtf/Variant.h: * wtf/WTFSemaphore.h: (WTF::Semaphore::Semaphore): Deleted. (WTF::Semaphore::signal): Deleted. (WTF::Semaphore::waitUntil): Deleted. (WTF::Semaphore::waitFor): Deleted. (WTF::Semaphore::wait): Deleted. * wtf/WallTime.h: (WTF::WallTime::WallTime): Deleted. (WTF::WallTime::fromRawSeconds): Deleted. (WTF::WallTime::infinity): Deleted. (WTF::WallTime::nan): Deleted. (WTF::WallTime::secondsSinceEpoch const): Deleted. (WTF::WallTime::approximateWallTime const): Deleted. (WTF::WallTime::operator bool const): Deleted. (WTF::WallTime::operator+ const): Deleted. (WTF::WallTime::operator- const): Deleted. (WTF::WallTime::operator+=): Deleted. (WTF::WallTime::operator-=): Deleted. (WTF::WallTime::operator== const): Deleted. (WTF::WallTime::operator!= const): Deleted. (WTF::WallTime::operator< const): Deleted. (WTF::WallTime::operator> const): Deleted. (WTF::WallTime::operator<= const): Deleted. (WTF::WallTime::operator>= const): Deleted. (WTF::WallTime::isolatedCopy const): Deleted. * wtf/WeakHashSet.h: (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Deleted. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Deleted. (WTF::WeakHashSet::WeakHashSetConstIterator::operator* const): Deleted. (WTF::WeakHashSet::WeakHashSetConstIterator::operator-> const): Deleted. (WTF::WeakHashSet::WeakHashSetConstIterator::operator++): Deleted. (WTF::WeakHashSet::WeakHashSetConstIterator::skipEmptyBuckets): Deleted. (WTF::WeakHashSet::WeakHashSetConstIterator::operator== const): Deleted. (WTF::WeakHashSet::WeakHashSetConstIterator::operator!= const): Deleted. (WTF::WeakHashSet::WeakHashSet): Deleted. (WTF::WeakHashSet::begin const): Deleted. (WTF::WeakHashSet::end const): Deleted. (WTF::WeakHashSet::add): Deleted. (WTF::WeakHashSet::remove): Deleted. (WTF::WeakHashSet::contains const): Deleted. (WTF::WeakHashSet::capacity const): Deleted. (WTF::WeakHashSet::computesEmpty const): Deleted. (WTF::WeakHashSet::hasNullReferences const): Deleted. (WTF::WeakHashSet::computeSize const): Deleted. (WTF::WeakHashSet::checkConsistency const): Deleted. * wtf/WeakRandom.h: (WTF::WeakRandom::WeakRandom): Deleted. (WTF::WeakRandom::setSeed): Deleted. (WTF::WeakRandom::seed const): Deleted. (WTF::WeakRandom::get): Deleted. (WTF::WeakRandom::getUint32): Deleted. (WTF::WeakRandom::lowOffset): Deleted. (WTF::WeakRandom::highOffset): Deleted. (WTF::WeakRandom::nextState): Deleted. (WTF::WeakRandom::generate): Deleted. (WTF::WeakRandom::advance): Deleted. * wtf/WordLock.h: (WTF::WordLock::lock): Deleted. (WTF::WordLock::unlock): Deleted. (WTF::WordLock::isHeld const): Deleted. (WTF::WordLock::isLocked const): Deleted. (WTF::WordLock::isFullyReset const): Deleted. * wtf/generic/MainThreadGeneric.cpp: * wtf/glib/GMutexLocker.h: * wtf/linux/CurrentProcessMemoryStatus.h: * wtf/posix/ThreadingPOSIX.cpp: (WTF::Semaphore::Semaphore): Deleted. (WTF::Semaphore::~Semaphore): Deleted. (WTF::Semaphore::wait): Deleted. (WTF::Semaphore::post): Deleted. * wtf/text/ASCIILiteral.h: (WTF::ASCIILiteral::operator const char* const): Deleted. (WTF::ASCIILiteral::fromLiteralUnsafe): Deleted. (WTF::ASCIILiteral::null): Deleted. (WTF::ASCIILiteral::characters const): Deleted. (WTF::ASCIILiteral::ASCIILiteral): Deleted. * wtf/text/AtomString.h: (WTF::AtomString::operator=): Deleted. (WTF::AtomString::isHashTableDeletedValue const): Deleted. (WTF::AtomString::existingHash const): Deleted. (WTF::AtomString::operator const String& const): Deleted. (WTF::AtomString::string const): Deleted. (WTF::AtomString::impl const): Deleted. (WTF::AtomString::is8Bit const): Deleted. (WTF::AtomString::characters8 const): Deleted. (WTF::AtomString::characters16 const): Deleted. (WTF::AtomString::length const): Deleted. (WTF::AtomString::operator[] const): Deleted. (WTF::AtomString::contains const): Deleted. (WTF::AtomString::containsIgnoringASCIICase const): Deleted. (WTF::AtomString::find const): Deleted. (WTF::AtomString::findIgnoringASCIICase const): Deleted. (WTF::AtomString::startsWith const): Deleted. (WTF::AtomString::startsWithIgnoringASCIICase const): Deleted. (WTF::AtomString::endsWith const): Deleted. (WTF::AtomString::endsWithIgnoringASCIICase const): Deleted. (WTF::AtomString::toInt const): Deleted. (WTF::AtomString::toDouble const): Deleted. (WTF::AtomString::toFloat const): Deleted. (WTF::AtomString::percentage const): Deleted. (WTF::AtomString::isNull const): Deleted. (WTF::AtomString::isEmpty const): Deleted. (WTF::AtomString::operator NSString * const): Deleted. * wtf/text/AtomStringImpl.h: (WTF::AtomStringImpl::lookUp): Deleted. (WTF::AtomStringImpl::add): Deleted. (WTF::AtomStringImpl::addWithStringTableProvider): Deleted. * wtf/text/CString.h: (WTF::CStringBuffer::data): Deleted. (WTF::CStringBuffer::length const): Deleted. (WTF::CStringBuffer::CStringBuffer): Deleted. (WTF::CStringBuffer::mutableData): Deleted. (WTF::CString::CString): Deleted. (WTF::CString::data const): Deleted. (WTF::CString::length const): Deleted. (WTF::CString::isNull const): Deleted. (WTF::CString::buffer const): Deleted. (WTF::CString::isHashTableDeletedValue const): Deleted. * wtf/text/ExternalStringImpl.h: (WTF::ExternalStringImpl::freeExternalBuffer): Deleted. * wtf/text/LineBreakIteratorPoolICU.h: * wtf/text/NullTextBreakIterator.h: * wtf/text/OrdinalNumber.h: * wtf/text/StringBuffer.h: * wtf/text/StringBuilder.h: * wtf/text/StringConcatenateNumbers.h: * wtf/text/StringHasher.h: * wtf/text/StringImpl.h: * wtf/text/StringView.cpp: * wtf/text/StringView.h: (WTF::StringView::left const): Deleted. (WTF::StringView::right const): Deleted. (WTF::StringView::underlyingStringIsValid const): Deleted. (WTF::StringView::setUnderlyingString): Deleted. * wtf/text/SymbolImpl.h: (WTF::SymbolImpl::StaticSymbolImpl::StaticSymbolImpl): Deleted. (WTF::SymbolImpl::StaticSymbolImpl::operator SymbolImpl&): Deleted. (WTF::PrivateSymbolImpl::PrivateSymbolImpl): Deleted. (WTF::RegisteredSymbolImpl::symbolRegistry const): Deleted. (WTF::RegisteredSymbolImpl::clearSymbolRegistry): Deleted. (WTF::RegisteredSymbolImpl::RegisteredSymbolImpl): Deleted. * wtf/text/SymbolRegistry.h: * wtf/text/TextBreakIterator.h: * wtf/text/TextPosition.h: * wtf/text/TextStream.h: * wtf/text/WTFString.h: (WTF::String::swap): Deleted. (WTF::String::adopt): Deleted. (WTF::String::isNull const): Deleted. (WTF::String::isEmpty const): Deleted. (WTF::String::impl const): Deleted. (WTF::String::releaseImpl): Deleted. (WTF::String::length const): Deleted. (WTF::String::characters8 const): Deleted. (WTF::String::characters16 const): Deleted. (WTF::String::is8Bit const): Deleted. (WTF::String::sizeInBytes const): Deleted. (WTF::String::operator[] const): Deleted. (WTF::String::find const): Deleted. (WTF::String::findIgnoringASCIICase const): Deleted. (WTF::String::reverseFind const): Deleted. (WTF::String::contains const): Deleted. (WTF::String::containsIgnoringASCIICase const): Deleted. (WTF::String::startsWith const): Deleted. (WTF::String::startsWithIgnoringASCIICase const): Deleted. (WTF::String::hasInfixStartingAt const): Deleted. (WTF::String::endsWith const): Deleted. (WTF::String::endsWithIgnoringASCIICase const): Deleted. (WTF::String::hasInfixEndingAt const): Deleted. (WTF::String::append): Deleted. (WTF::String::left const): Deleted. (WTF::String::right const): Deleted. (WTF::String::createUninitialized): Deleted. (WTF::String::fromUTF8WithLatin1Fallback): Deleted. (WTF::String::isAllASCII const): Deleted. (WTF::String::isAllLatin1 const): Deleted. (WTF::String::isSpecialCharacter const): Deleted. (WTF::String::isHashTableDeletedValue const): Deleted. (WTF::String::hash const): Deleted. (WTF::String::existingHash const): Deleted. * wtf/text/cf/TextBreakIteratorCF.h: * wtf/text/icu/TextBreakIteratorICU.h: * wtf/text/icu/UTextProviderLatin1.h: * wtf/threads/BinarySemaphore.h: (WTF::BinarySemaphore::waitFor): Deleted. (WTF::BinarySemaphore::wait): Deleted. * wtf/unicode/Collator.h: * wtf/win/GDIObject.h: * wtf/win/PathWalker.h: * wtf/win/Win32Handle.h: Canonical link: https://commits.webkit.org/214396@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248546 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-08-12 20:57:15 +00:00
WTF_MAKE_FAST_ALLOCATED;
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
typedef __expected_detail::base_select<T, E> base;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
public:
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
typedef typename base::value_type value_type;
typedef typename base::error_type error_type;
typedef typename base::unexpected_type unexpected_type;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
private:
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
typedef expected<value_type, error_type> type;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
public:
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
template<class U> struct rebind {
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
using type = expected<U, error_type>;
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
};
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
constexpr expected() : base(__expected_detail::value_tag) { }
expected(const expected&) = default;
expected(expected&&) = default;
constexpr expected(const value_type& e) : base(__expected_detail::value_tag, e) { }
constexpr expected(value_type&& e) : base(__expected_detail::value_tag, std::forward<value_type>(e)) { }
template<class... Args> constexpr explicit expected(std::in_place_t, Args&&... args) : base(__expected_detail::value_tag, value_type(std::forward<Args>(args)...)) { }
// template<class U, class... Args> constexpr explicit expected(in_place_t, std::initializer_list<U>, Args&&...);
constexpr expected(const unexpected_type& u) : base(__expected_detail::error_tag, u.value()) { }
constexpr expected(unexpected_type&& u) : base(__expected_detail::error_tag, std::forward<unexpected_type>(u).value()) { }
template<class Err> constexpr expected(const unexpected<Err>& u) : base(__expected_detail::error_tag, u.value()) { }
template<class Err> constexpr expected(unexpected<Err>&& u) : base(__expected_detail::error_tag, std::forward<Err>(u.value())) { }
template<class... Args> constexpr explicit expected(unexpected_t, Args&&... args) : base(__expected_detail::value_tag, unexpected_type(std::forward<Args>(args)...)) { }
// template<class U, class... Args> constexpr explicit expected(unexpected_t, std::initializer_list<U>, Args&&...);
~expected() = default;
expected& operator=(const expected& e) { type(e).swap(*this); return *this; }
expected& operator=(expected&& e) { type(std::move(e)).swap(*this); return *this; }
template<class U> expected& operator=(U&& u) { type(std::forward<U>(u)).swap(*this); return *this; }
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
expected& operator=(const unexpected_type& u) { type(u).swap(*this); return *this; }
expected& operator=(unexpected_type&& u) { type(std::move(u)).swap(*this); return *this; }
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
// template<class... Args> void emplace(Args&&...);
// template<class U, class... Args> void emplace(std::initializer_list<U>, Args&&...);
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
void swap(expected& o)
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
{
using std::swap;
if (base::has && o.has)
swap(base::s.val, o.s.val);
else if (base::has && !o.has) {
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
error_type e(std::move(o.s.err));
__expected_detail::destroy(o.s.err);
::new (std::addressof(o.s.val)) value_type(std::move(base::s.val));
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
__expected_detail::destroy(base::s.val);
::new (std::addressof(base::s.err)) error_type(std::move(e));
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
swap(base::has, o.has);
} else if (!base::has && o.has) {
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
value_type v(std::move(o.s.val));
__expected_detail::destroy(o.s.val);
::new (std::addressof(o.s.err)) error_type(std::move(base::s.err));
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
__expected_detail::destroy(base::s.err);
::new (std::addressof(base::s.val)) value_type(std::move(v));
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
swap(base::has, o.has);
} else
swap(base::s.err, o.s.err);
}
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
constexpr const value_type* operator->() const { return &base::s.val; }
value_type* operator->() { return &base::s.val; }
constexpr const value_type& operator*() const & { return base::s.val; }
value_type& operator*() & { return base::s.val; }
constexpr const value_type&& operator*() const && { return std::move(base::s.val); }
constexpr value_type&& operator*() && { return std::move(base::s.val); }
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
constexpr explicit operator bool() const { return base::has; }
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
constexpr bool has_value() const { return base::has; }
constexpr const value_type& value() const & { return base::has ? base::s.val : (__EXPECTED_THROW(bad_expected_access<error_type>(base::s.err)), base::s.val); }
constexpr value_type& value() & { return base::has ? base::s.val : (__EXPECTED_THROW(bad_expected_access<error_type>(base::s.err)), base::s.val); }
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
constexpr const value_type&& value() const && { return std::move(base::has ? base::s.val : (__EXPECTED_THROW(bad_expected_access<error_type>(base::s.err)), base::s.val)); }
constexpr value_type&& value() && { return std::move(base::has ? base::s.val : (__EXPECTED_THROW(bad_expected_access<error_type>(base::s.err)), base::s.val)); }
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
constexpr const error_type& error() const & { return !base::has ? base::s.err : (__EXPECTED_THROW(bad_expected_access<void>()), base::s.err); }
error_type& error() & { return !base::has ? base::s.err : (__EXPECTED_THROW(bad_expected_access<void>()), base::s.err); }
constexpr error_type&& error() && { return std::move(!base::has ? base::s.err : (__EXPECTED_THROW(bad_expected_access<void>()), base::s.err)); }
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
constexpr const error_type&& error() const && { return std::move(!base::has ? base::s.err : (__EXPECTED_THROW(bad_expected_access<void>()), base::s.err)); }
template<class U> constexpr value_type value_or(U&& u) const & { return base::has ? **this : static_cast<value_type>(std::forward<U>(u)); }
template<class U> value_type value_or(U&& u) && { return base::has ? std::move(**this) : static_cast<value_type>(std::forward<U>(u)); }
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
};
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
template<class E>
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
class expected<void, E> : private __expected_detail::base_select<void, E> {
typedef __expected_detail::base_select<void, E> base;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
public:
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
typedef typename base::value_type value_type;
typedef typename base::error_type error_type;
typedef typename base::unexpected_type unexpected_type;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
private:
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
typedef expected<value_type, error_type> type;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
public:
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
template<class U> struct rebind {
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
using type = expected<U, error_type>;
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
};
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
constexpr expected() : base(__expected_detail::value_tag) { }
expected(const expected&) = default;
expected(expected&&) = default;
// constexpr explicit expected(in_place_t);
constexpr expected(unexpected_type const& u) : base(__expected_detail::error_tag, u.value()) { }
constexpr expected(unexpected_type&& u) : base(__expected_detail::error_tag, std::forward<unexpected_type>(u).value()) { }
template<class Err> constexpr expected(unexpected<Err> const& u) : base(__expected_detail::error_tag, u.value()) { }
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
~expected() = default;
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
expected& operator=(const expected& e) { type(e).swap(*this); return *this; }
expected& operator=(expected&& e) { type(std::move(e)).swap(*this); return *this; }
expected& operator=(const unexpected_type& u) { type(u).swap(*this); return *this; } // Not in the current paper.
expected& operator=(unexpected_type&& u) { type(std::move(u)).swap(*this); return *this; } // Not in the current paper.
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
// void emplace();
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
void swap(expected& o)
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
{
using std::swap;
if (base::has && o.has) {
// Do nothing.
} else if (base::has && !o.has) {
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
error_type e(std::move(o.s.err));
::new (std::addressof(base::s.err)) error_type(e);
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
swap(base::has, o.has);
} else if (!base::has && o.has) {
::new (std::addressof(o.s.err)) error_type(std::move(base::s.err));
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
swap(base::has, o.has);
} else
swap(base::s.err, o.s.err);
}
constexpr explicit operator bool() const { return base::has; }
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
constexpr bool has_value() const { return base::has; }
void value() const { !base::has ? __EXPECTED_THROW(bad_expected_access<void>()) : void(); }
constexpr const E& error() const & { return !base::has ? base::s.err : (__EXPECTED_THROW(bad_expected_access<void>()), base::s.err); }
E& error() & { return !base::has ? base::s.err : (__EXPECTED_THROW(bad_expected_access<void>()), base::s.err); }
constexpr E&& error() && { return std::move(!base::has ? base::s.err : (__EXPECTED_THROW(bad_expected_access<void>()), base::s.err)); }
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
};
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
template<class T, class E> constexpr bool operator==(const expected<T, E>& x, const expected<T, E>& y) { return bool(x) == bool(y) && (x ? x.value() == y.value() : x.error() == y.error()); }
template<class T, class E> constexpr bool operator!=(const expected<T, E>& x, const expected<T, E>& y) { return !(x == y); }
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
template<class E> constexpr bool operator==(const expected<void, E>& x, const expected<void, E>& y) { return bool(x) == bool(y) && (x ? true : x.error() == y.error()); }
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
template<class T, class E> constexpr bool operator==(const expected<T, E>& x, const T& y) { return x ? *x == y : false; }
template<class T, class E> constexpr bool operator==(const T& x, const expected<T, E>& y) { return y ? x == *y : false; }
template<class T, class E> constexpr bool operator!=(const expected<T, E>& x, const T& y) { return x ? *x != y : true; }
template<class T, class E> constexpr bool operator!=(const T& x, const expected<T, E>& y) { return y ? x != *y : true; }
WTF: Update std::expected to match current proposal https://bugs.webkit.org/show_bug.cgi?id=177881 Reviewed by Mark Lam. Source/JavaScriptCore: Update API. * wasm/WasmB3IRGenerator.cpp: * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): * wasm/WasmParser.h: * wasm/WasmValidate.cpp: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): Source/WTF: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * wtf/Expected.h: (WTF::Unexpected::Unexpected): (WTF::Unexpected::value const): (WTF::operator==): (WTF::operator!=): (WTF::makeUnexpected): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::getUnexpected const): Tools: The proposal is likely to be in C++20 and I've been asked to help co-champion it. I'm therefore updating our implementation to more closely match the current proposal, and to make sure it'll work for us if standardized. - Rename UnexpectedType to Unexpected to match the proposal. - Remove relational operators, only equality / inequality remains. - Fix minor type signatures. - Add UnexpectedType typedef. - Uncomment rebind implementation. - Add in-place construction tag, as well as explicit error construction tag. - Add template unexpected constructor. - Note that make_unexpected isn't in the proposal anymore, but we keep it because we don't have C++17 deduction guides. - Remove hashing, which isn't in the proposal anymore. * TestWebKitAPI/Tests/WTF/Expected.cpp: (WTF::operator<<): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/194157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-04 20:54:26 +00:00
template<class T, class E> constexpr bool operator==(const expected<T, E>& x, const unexpected<E>& y) { return x ? false : x.error() == y.value(); }
template<class T, class E> constexpr bool operator==(const unexpected<E>& x, const expected<T, E>& y) { return y ? false : x.value() == y.error(); }
template<class T, class E> constexpr bool operator!=(const expected<T, E>& x, const unexpected<E>& y) { return x ? true : x.error() != y.value(); }
template<class T, class E> constexpr bool operator!=(const unexpected<E>& x, const expected<T, E>& y) { return y ? true : x.value() != y.error(); }
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
template<typename T, typename E> void swap(expected<T, E>& x, expected<T, E>& y) { x.swap(y); }
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
}}} // namespace std::experimental::fundamentals_v3
Implement WTF::Expected https://bugs.webkit.org/show_bug.cgi?id=164526 Reviewed by Yusuke Suzuki. std::expected isn't in C++17, and may be in C++20. It's a nice complement to std::any / std::optional because it's a type-tagged union which has a single expected result but could also contain an error. This would be useful in the WebAssembly parser, for example. Using this implementation will allow us to provide feedback to the standards committee and guide std::expected's design before it gets standardized. I've already sent a bunch of feedback to the author based on my experience implementing this. This could supplement WTF::Either and WTF::ExceptionOr. Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/Compiler.h: Add RELAXED_CONSTEXPR * wtf/Expected.h: Added. (WTF::UnexpectedType::UnexpectedType): (WTF::UnexpectedType::value): (WTF::operator==): (WTF::operator!=): (WTF::operator<): (WTF::operator>): (WTF::operator<=): (WTF::operator>=): (WTF::makeUnexpected): (WTF::ExpectedDetail::Throw): (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): (WTF::ExpectedDetail::Base::Base): (WTF::ExpectedDetail::Base::~Base): (WTF::Expected::Expected): (WTF::Expected::operator=): (WTF::Expected::swap): (WTF::Expected::operator->): (WTF::Expected::operator*): (WTF::Expected::operator bool): (WTF::Expected::hasValue): (WTF::Expected::value): (WTF::Expected::error): (WTF::Expected::getUnexpected): (WTF::Expected::valueOr): (WTF::swap): (WTF::makeExpected): (WTF::makeExpectedFromError): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Expected.cpp: Added. (WTF::operator<<): (TestWebKitAPI::TEST): (TestWebKitAPI::foo::foo): (TestWebKitAPI::foo::~foo): (TestWebKitAPI::foo::operator==): (TestWebKitAPI::operator<<): Canonical link: https://commits.webkit.org/182388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-13 19:28:36 +00:00
__EXPECTED_INLINE_VARIABLE constexpr auto& unexpect = std::experimental::unexpect;
Update std::expected to match libc++ coding style https://bugs.webkit.org/show_bug.cgi?id=180264 Reviewed by Alex Christensen. Source/JavaScriptCore: Update various uses of Expected. * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseImport): (JSC::Wasm::ModuleParser::parseTableHelper): (JSC::Wasm::ModuleParser::parseTable): (JSC::Wasm::ModuleParser::parseMemoryHelper): * wasm/WasmParser.h: * wasm/generateWasmValidateInlinesHeader.py: (loadMacro): (storeMacro): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::createStub): * wasm/js/JSWebAssemblyModule.h: Source/WebCore: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * Modules/cache/DOMCache.cpp: (WebCore::DOMCache::retrieveRecords): (WebCore::DOMCache::batchDeleteOperation): (WebCore::DOMCache::batchPutOperation): * Modules/cache/DOMCacheStorage.cpp: (WebCore::DOMCacheStorage::retrieveCaches): (WebCore::DOMCacheStorage::open): (WebCore::DOMCacheStorage::remove): * Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::WorkerCacheStorageConnection::doRemove): (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): (WebCore::recordsDataOrErrorFromRecords): (WebCore::recordsOrErrorFromRecordsData): * bindings/js/CachedScriptFetcher.cpp: (WebCore::CachedScriptFetcher::requestScriptWithCache const): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::getDomainList): (WebCore::ContentExtensions::loadTrigger): (WebCore::ContentExtensions::loadRule): (WebCore::ContentExtensions::loadEncodedRules): (WebCore::ContentExtensions::parseRuleList): * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::cachedFont): * css/CSSImageSetValue.cpp: (WebCore::CSSImageSetValue::loadBestFitImage): * css/CSSImageValue.cpp: (WebCore::CSSImageValue::loadImage): * css/StyleRuleImport.cpp: (WebCore::StyleRuleImport::requestStyleSheet): * dom/CallbackResult.h: (WebCore::CallbackResult<ReturnType>::type const): (WebCore::CallbackResult<ReturnType>::releaseReturnValue): * dom/Element.cpp: (WebCore::Element::getIntegralAttribute const): (WebCore::Element::getUnsignedIntegralAttribute const): * dom/ExceptionOr.h: (WebCore::ExceptionOr<ReturnType>::hasException const): (WebCore::ExceptionOr<void>::hasException const): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::checkStyleSheet): * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::maxLengthAttributeChanged): (WebCore::HTMLInputElement::minLengthAttributeChanged): * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): (WebCore::HTMLTextAreaElement::minLengthAttributeChanged): * html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLNonNegativeInteger): * html/parser/HTMLParserIdioms.h: (WebCore::limitToOnlyHTMLNonNegative): * loader/CrossOriginPreflightChecker.cpp: (WebCore::CrossOriginPreflightChecker::startPreflight): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::loadMainResource): * loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::loadRequest): * loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): * loader/LinkLoader.cpp: (WebCore::LinkLoader::preloadIfNeeded): (WebCore::LinkLoader::loadLink): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::load): * loader/cache/CachedSVGDocumentReference.cpp: (WebCore::CachedSVGDocumentReference::load): * loader/icon/IconLoader.cpp: (WebCore::IconLoader::startLoading): * platform/URLParser.cpp: (WebCore::URLParser::parseIPv4Host): * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp: (WebCore::WebCoreAVCFResourceLoader::startLoading): * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::WebCoreAVFResourceLoader::startLoading): * svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): * svg/SVGFontFaceUriElement.cpp: (WebCore::SVGFontFaceUriElement::loadFont): * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::updateExternalDocument): * xml/XSLImportRule.cpp: (WebCore::XSLImportRule::loadSheet): Source/WebKit: Update various uses of Expected, mostly renaming valueOr and hasValue to the STL naming convention. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::open): (WebKit::CacheStorage::Engine::retrieveCaches): (WebKit::CacheStorage::Engine::retrieveRecords): (WebKit::CacheStorage::Engine::putRecords): (WebKit::CacheStorage::Engine::deleteMatchingRecords): (WebKit::CacheStorage::Engine::fetchEntries): (WebKit::CacheStorage::Engine::clearMemoryRepresentation): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::ReadRecordTaskCounter::appendRecord): (WebKit::CacheStorage::Cache::updateRecordToDisk): * NetworkProcess/cache/CacheStorageEngineCaches.cpp: (WebKit::CacheStorage::Caches::initialize): (WebKit::CacheStorage::Caches::readCachesFromDisk): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::createResolver): * Platform/IPC/ArgumentCoders.h: Source/WTF: As of https://wg21.link/p0323r4 std::expected is on its way to the Library Fundamentals v3 TS (LEWG and EWG voted for this, but LWG hasn't done wording review yet, hence "on its way"). The API is therefore pretty close to what will be in the TS, and I've gotten requests for an easily usable implementation of std::expected. I talked to our clang team and they'll help me migrate our implementation to libc++, but our implementation has to look more like libc++ than it does now. Once in libc++ I'll maintain changes on both sides to make sure neither is out-of-date for too long. - Fork std::unexpected into its own header. - Add mild support for an exception-based implementation, but don't do noexcept yet. - Rename everything to follow STL style, and keep a global using or variable alias where possible to reduce WebKit code churn. - Minor API updates to remove things that aren't in the proposal anymore. * wtf/Expected.h: (std::experimental::fundamentals_v3::bad_expected_access<void>::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::bad_expected_access): (std::experimental::fundamentals_v3::bad_expected_access::error): (std::experimental::fundamentals_v3::bad_expected_access::error const): (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::__expected_detail::base::base): (std::experimental::fundamentals_v3::__expected_detail::base::~base): (std::experimental::fundamentals_v3::expected::expected): (std::experimental::fundamentals_v3::expected::operator=): (std::experimental::fundamentals_v3::expected::swap): (std::experimental::fundamentals_v3::expected::operator-> const): (std::experimental::fundamentals_v3::expected::operator->): (std::experimental::fundamentals_v3::expected::operator* const): (std::experimental::fundamentals_v3::expected::operator*): (std::experimental::fundamentals_v3::expected::has_value const): (std::experimental::fundamentals_v3::expected::value const): (std::experimental::fundamentals_v3::expected::value): (std::experimental::fundamentals_v3::expected::error const): (std::experimental::fundamentals_v3::expected::error): (std::experimental::fundamentals_v3::expected::value_or const): (std::experimental::fundamentals_v3::expected::value_or): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (std::experimental::fundamentals_v3::swap): (WTF::Unexpected::Unexpected): Deleted. (WTF::Unexpected::value const): Deleted. (WTF::Unexpected::value): Deleted. (WTF::operator==): Deleted. (WTF::operator!=): Deleted. (WTF::makeUnexpected): Deleted. (WTF::ExpectedDetail::Throw): Deleted. (WTF::ExpectedDetail::destroy): Deleted. (WTF::ExpectedDetail::std::is_trivially_destructible<T>::value): Deleted. (WTF::ExpectedDetail::ConstexprBase::ConstexprBase): Deleted. (WTF::ExpectedDetail::Base::Base): Deleted. (WTF::ExpectedDetail::Base::~Base): Deleted. (WTF::Expected::Expected): Deleted. (WTF::Expected::operator=): Deleted. (WTF::Expected::swap): Deleted. (WTF::Expected::operator-> const): Deleted. (WTF::Expected::operator->): Deleted. (WTF::Expected::operator* const): Deleted. (WTF::Expected::operator*): Deleted. (WTF::Expected::operator bool const): Deleted. (WTF::Expected::hasValue const): Deleted. (WTF::Expected::value const): Deleted. (WTF::Expected::value): Deleted. (WTF::Expected::error const): Deleted. (WTF::Expected::error): Deleted. (WTF::Expected::getUnexpected const): Deleted. (WTF::Expected::valueOr const): Deleted. (WTF::Expected::valueOr): Deleted. (WTF::swap): Deleted. (WTF::makeExpected): Deleted. (WTF::makeExpectedFromError): Deleted. * wtf/Forward.h: * wtf/Optional.h: * wtf/StdLibExtras.h: * wtf/Unexpected.h: Added. (std::experimental::fundamentals_v3::unexpected::unexpected): (std::experimental::fundamentals_v3::unexpected::value const): (std::experimental::fundamentals_v3::unexpected::value): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): (makeUnexpected): Tools: Update tests according to name changes as well as removal of now-gone APIs. * TestWebKitAPI/Tests/WTF/Expected.cpp: (std::experimental::fundamentals_v3::operator<<): (TestWebKitAPI::TEST): (WTF::operator<<): Deleted. * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp: (TestWebKitAPI::testParseHTMLInteger): (TestWebKitAPI::testParseHTMLNonNegativeInteger): Canonical link: https://commits.webkit.org/196343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-04 23:34:57 +00:00
template<class T, class E> using Expected = std::experimental::expected<T, E>;