Update std::expected to match libc++ coding style
authorjfbastien@apple.com <jfbastien@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Dec 2017 23:34:57 +0000 (23:34 +0000)
committerjfbastien@apple.com <jfbastien@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Dec 2017 23:34:57 +0000 (23:34 +0000)
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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225499 268f45cc-cd09-0410-ab3c-d52691b4dbfc

58 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/wasm/WasmModule.h
Source/JavaScriptCore/wasm/WasmModuleParser.cpp
Source/JavaScriptCore/wasm/WasmParser.h
Source/JavaScriptCore/wasm/generateWasmValidateInlinesHeader.py
Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.cpp
Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.h
Source/WTF/ChangeLog
Source/WTF/wtf/Expected.h
Source/WTF/wtf/Forward.h
Source/WTF/wtf/Optional.h
Source/WTF/wtf/StdLibExtras.h
Source/WTF/wtf/Unexpected.h [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/cache/DOMCache.cpp
Source/WebCore/Modules/cache/DOMCacheStorage.cpp
Source/WebCore/Modules/cache/WorkerCacheStorageConnection.cpp
Source/WebCore/bindings/js/CachedScriptFetcher.cpp
Source/WebCore/contentextensions/ContentExtensionCompiler.cpp
Source/WebCore/contentextensions/ContentExtensionParser.cpp
Source/WebCore/css/CSSFontFaceSrcValue.cpp
Source/WebCore/css/CSSImageSetValue.cpp
Source/WebCore/css/CSSImageValue.cpp
Source/WebCore/css/StyleRuleImport.cpp
Source/WebCore/dom/CallbackResult.h
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/ExceptionOr.h
Source/WebCore/dom/ProcessingInstruction.cpp
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLLinkElement.cpp
Source/WebCore/html/HTMLTextAreaElement.cpp
Source/WebCore/html/parser/HTMLParserIdioms.cpp
Source/WebCore/html/parser/HTMLParserIdioms.h
Source/WebCore/loader/CrossOriginPreflightChecker.cpp
Source/WebCore/loader/DocumentLoader.cpp
Source/WebCore/loader/DocumentThreadableLoader.cpp
Source/WebCore/loader/ImageLoader.cpp
Source/WebCore/loader/LinkLoader.cpp
Source/WebCore/loader/MediaResourceLoader.cpp
Source/WebCore/loader/TextTrackLoader.cpp
Source/WebCore/loader/cache/CachedSVGDocumentReference.cpp
Source/WebCore/loader/icon/IconLoader.cpp
Source/WebCore/platform/URLParser.cpp
Source/WebCore/platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp
Source/WebCore/platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm
Source/WebCore/svg/SVGFEImageElement.cpp
Source/WebCore/svg/SVGFontFaceUriElement.cpp
Source/WebCore/svg/SVGUseElement.cpp
Source/WebCore/xml/XSLImportRule.cpp
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp
Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.cpp
Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp
Source/WebKit/NetworkProcess/webrtc/NetworkRTCProvider.cpp
Source/WebKit/Platform/IPC/ArgumentCoders.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WTF/Expected.cpp
Tools/TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp

index e4eb93f..adb5c78 100644 (file)
@@ -1,3 +1,26 @@
+2017-12-04  JF Bastien  <jfbastien@apple.com>
+
+        Update std::expected to match libc++ coding style
+        https://bugs.webkit.org/show_bug.cgi?id=180264
+
+        Reviewed by Alex Christensen.
+
+        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:
+
 2017-12-04  Saam Barati  <sbarati@apple.com>
 
         We need to leave room on the top of the stack for the FTL TailCall slow path so it doesn't overwrite things we want to retrieve when doing a stack walk when throwing an exception
index a6ae29f..fa36a69 100644 (file)
@@ -45,7 +45,7 @@ using SignatureIndex = uint32_t;
 
 class Module : public ThreadSafeRefCounted<Module> {
 public:
-    using ValidationResult = WTF::Expected<RefPtr<Module>, String>;
+    using ValidationResult = Expected<RefPtr<Module>, String>;
     typedef void CallbackType(ValidationResult&&);
     using AsyncValidationCallback = RefPtr<SharedTask<CallbackType>>;
 
index 0c73d3f..a098789 100644 (file)
@@ -179,14 +179,14 @@ auto ModuleParser::parseImport() -> PartialResult
             bool isImport = true;
             PartialResult result = parseTableHelper(isImport);
             if (UNLIKELY(!result))
-                return result.getUnexpected();
+                return makeUnexpected(WTFMove(result.error()));
             break;
         }
         case ExternalKind::Memory: {
             bool isImport = true;
             PartialResult result = parseMemoryHelper(isImport);
             if (UNLIKELY(!result))
-                return result.getUnexpected();
+                return makeUnexpected(WTFMove(result.error()));
             break;
         }
         case ExternalKind::Global: {
@@ -263,7 +263,7 @@ auto ModuleParser::parseTableHelper(bool isImport) -> PartialResult
     std::optional<uint32_t> maximum;
     PartialResult limits = parseResizableLimits(initial, maximum);
     if (UNLIKELY(!limits))
-        return limits.getUnexpected();
+        return makeUnexpected(WTFMove(limits.error()));
     WASM_PARSER_FAIL_IF(initial > maxTableEntries, "Table's initial page count of ", initial, " is too big, maximum ", maxTableEntries);
 
     ASSERT(!maximum || *maximum >= initial);
@@ -285,7 +285,7 @@ auto ModuleParser::parseTable() -> PartialResult
     bool isImport = false;
     PartialResult result = parseTableHelper(isImport);
     if (UNLIKELY(!result))
-        return result.getUnexpected();
+        return makeUnexpected(WTFMove(result.error()));
 
     return { };
 }
@@ -303,7 +303,7 @@ auto ModuleParser::parseMemoryHelper(bool isImport) -> PartialResult
         std::optional<uint32_t> maximum;
         PartialResult limits = parseResizableLimits(initial, maximum);
         if (UNLIKELY(!limits))
-            return limits.getUnexpected();
+            return makeUnexpected(WTFMove(limits.error()));
         ASSERT(!maximum || *maximum >= initial);
         WASM_PARSER_FAIL_IF(!PageCount::isValid(initial), "Memory's initial page count of ", initial, " is invalid");
 
index 95f4db5..3c728b2 100644 (file)
@@ -97,10 +97,10 @@ protected:
         return fail(__VA_ARGS__);                \
     } while (0)
 
-#define WASM_FAIL_IF_HELPER_FAILS(helper) do {   \
-        auto helperResult = helper;              \
-        if (UNLIKELY(!helperResult))             \
-            return helperResult.getUnexpected(); \
+#define WASM_FAIL_IF_HELPER_FAILS(helper) do {                      \
+        auto helperResult = helper;                                 \
+        if (UNLIKELY(!helperResult))                                \
+            return makeUnexpected(WTFMove(helperResult.error()));   \
     } while (0)
 
 private:
index 18053d3..bc54a22 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-# Copyright (C) 2016 Apple Inc. All rights reserved.
+# Copyright (C) 2016-2017 Apple Inc. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -63,7 +63,7 @@ def unaryMacro(name):
 template<> auto Validate::addOp<OpType::""" + toCpp(name) + """>(ExpressionType value, ExpressionType& result) -> Result
 {
     if (UNLIKELY(value != """ + cppType(op["parameter"][0]) + """))
-        return Unexpected<Result::ErrorType>("validation failed: """ + name + """ value type mismatch");
+        return Unexpected<Result::error_type>("validation failed: """ + name + """ value type mismatch");
 
     result = """ + cppType(op["return"][0]) + """;
     return { };
@@ -77,10 +77,10 @@ def binaryMacro(name):
 template<> auto Validate::addOp<OpType::""" + toCpp(name) + """>(ExpressionType left, ExpressionType right, ExpressionType& result) -> Result
 {
     if (UNLIKELY(left != """ + cppType(op["parameter"][0]) + """))
-        return Unexpected<Result::ErrorType>("validation failed: """ + name + """ left value type mismatch");
+        return Unexpected<Result::error_type>("validation failed: """ + name + """ left value type mismatch");
 
     if (UNLIKELY(right != """ + cppType(op["parameter"][1]) + """))
-        return Unexpected<Result::ErrorType>("validation failed: """ + name + """ right value type mismatch");
+        return Unexpected<Result::error_type>("validation failed: """ + name + """ right value type mismatch");
 
     result = """ + cppType(op["return"][0]) + """;
     return { };
@@ -92,7 +92,7 @@ def loadMacro(name):
     return """
     case LoadOpType::""" + toCpp(name) + """: {
         if (UNLIKELY(pointer != """ + cppType(op["parameter"][0]) + """))
-            return Unexpected<Result::ErrorType>("validation failed: """ + name + """ pointer type mismatch");
+            return Unexpected<Result::error_type>("validation failed: """ + name + """ pointer type mismatch");
 
         result = """ + cppType(op["return"][0]) + """;
         return { };
@@ -104,10 +104,10 @@ def storeMacro(name):
     return """
     case StoreOpType::""" + toCpp(name) + """: {
         if (UNLIKELY(pointer != """ + cppType(op["parameter"][0]) + """))
-            return Unexpected<Result::ErrorType>("validation failed: """ + name + """ pointer type mismatch");
+            return Unexpected<Result::error_type>("validation failed: """ + name + """ pointer type mismatch");
 
         if (UNLIKELY(value != """ + cppType(op["parameter"][1]) + """))
-            return Unexpected<Result::ErrorType>("validation failed: """ + name + """ value type mismatch");
+            return Unexpected<Result::error_type>("validation failed: """ + name + """ value type mismatch");
 
         return { };
     }"""
@@ -139,7 +139,7 @@ namespace JSC { namespace Wasm {
 auto Validate::load(LoadOpType op, ExpressionType pointer, ExpressionType& result, uint32_t) -> Result
 {
     if (UNLIKELY(!hasMemory()))
-        return Unexpected<Result::ErrorType>("validation failed: load instruction without memory");
+        return Unexpected<Result::error_type>("validation failed: load instruction without memory");
 
     switch (op) {
 """ + loadCases + """
@@ -150,7 +150,7 @@ auto Validate::load(LoadOpType op, ExpressionType pointer, ExpressionType& resul
 auto Validate::store(StoreOpType op, ExpressionType pointer, ExpressionType value, uint32_t) -> Result
 {
     if (UNLIKELY(!hasMemory()))
-        return Unexpected<Result::ErrorType>("validation failed: store instruction without memory");
+        return Unexpected<Result::error_type>("validation failed: store instruction without memory");
 
     switch (op) {
 """ + storeCases + """
index 40c1006..23fef22 100644 (file)
@@ -47,7 +47,7 @@ const ClassInfo JSWebAssemblyModule::s_info = { "WebAssembly.Module", &Base::s_i
 JSWebAssemblyModule* JSWebAssemblyModule::createStub(VM& vm, ExecState* exec, Structure* structure, Wasm::Module::ValidationResult&& result)
 {
     auto scope = DECLARE_THROW_SCOPE(vm);
-    if (!result.hasValue()) {
+    if (!result.has_value()) {
         throwException(exec, scope, JSWebAssemblyCompileError::create(exec, vm, structure->globalObject()->WebAssemblyCompileErrorStructure(), result.error()));
         return nullptr;
     }
index 01b5d07..8fec6a0 100644 (file)
@@ -56,7 +56,7 @@ public:
 
     DECLARE_EXPORT_INFO;
 
-    JS_EXPORT_PRIVATE static JSWebAssemblyModule* createStub(VM&, ExecState*, Structure*, WTF::Expected<RefPtr<Wasm::Module>, String>&&);
+    JS_EXPORT_PRIVATE static JSWebAssemblyModule* createStub(VM&, ExecState*, Structure*, Expected<RefPtr<Wasm::Module>, String>&&);
     static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
 
     const Wasm::ModuleInformation& moduleInformation() const;
index 7a01ad2..bf8fa47 100644 (file)
@@ -1,3 +1,95 @@
+2017-12-04  JF Bastien  <jfbastien@apple.com>
+
+        Update std::expected to match libc++ coding style
+        https://bugs.webkit.org/show_bug.cgi?id=180264
+
+        Reviewed by Alex Christensen.
+
+        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):
+
 2017-12-03  Tomas Popela  <tpopela@redhat.com>
 
         Build fails on x86_64 and arm64 with BMalloc disabled
index 728b413..70a22ac 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-// WTF::Expected is based on std::expected, as described here: http://wg21.link/p0323r1
-// The specification expects to throw. This implementation doesn't support exceptions, uses RELEASE_ASSERT instead.
+// Implementation of Library Fundamentals v3's std::expected, as described here: http://wg21.link/p0323r4
 
 #pragma once
 
+/*
+    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
+        };
+    };
+
+}}}
+
+*/
+
 #include <cstdlib>
 #include <initializer_list>
 #include <type_traits>
 #include <utility>
 #include <wtf/Assertions.h>
+#include <wtf/Compiler.h>
 #include <wtf/Optional.h>
 #include <wtf/StdLibExtras.h>
+#include <wtf/Unexpected.h>
 
-namespace WTF {
-
-template<class E>
-class Unexpected {
-public:
-    Unexpected() = delete;
-    constexpr explicit Unexpected(const E& e) : val(e) { }
-    constexpr explicit Unexpected(E&& e) : val(std::forward<E>(e)) { }
-    constexpr const E& value() const & { return val; }
-    RELAXED_CONSTEXPR E& value() & { return val; }
-    RELAXED_CONSTEXPR E&& value() && { return WTFMove(val); }
+namespace std {
+namespace experimental {
+inline namespace fundamentals_v3 {
 
-private:
-    E val;
+struct unexpected_t {
+    unexpected_t() = default;
 };
+#if __cplusplus < 201703L
+#define __EXPECTED_INLINE_VARIABLE static const
+#else
+#define __EXPECTED_INLINE_VARIABLE inline
+#endif
 
-template<class E> constexpr bool operator==(const Unexpected<E>& lhs, const Unexpected<E>& rhs) { return lhs.value() == rhs.value(); }
-template<class E> constexpr bool operator!=(const Unexpected<E>& lhs, const Unexpected<E>& rhs) { return lhs.value() != rhs.value(); }
+__EXPECTED_INLINE_VARIABLE constexpr unexpected_t unexpect { };
 
-template<class E> constexpr Unexpected<std::decay_t<E>> makeUnexpected(E&& v) { return Unexpected<typename std::decay<E>::type>(std::forward<E>(v)); }
+template<class E> class bad_expected_access;
 
-struct UnexpectTag {
-    UnexpectTag() = default;
+template<>
+class bad_expected_access<void> : public std::exception {
+public:
+    explicit bad_expected_access() { }
 };
-constexpr UnexpectTag Unexpect { }; // FIXME This is an inline variable for C++17 and later.
 
-// FIXME this should just be std::in_place_t which we also define in optional and variant.
-struct InPlaceTag {
-    InPlaceTag() = default;
+template<class E>
+class bad_expected_access : public bad_expected_access<void> {
+public:
+    explicit bad_expected_access(E val) : val(val) { }
+    virtual const char* what() const noexcept override { return std::exception::what(); }
+    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;
 };
-constexpr InPlaceTag InPlace { };
 
-namespace ExpectedDetail {
+namespace __expected_detail {
 
-// Invoked where std::Expected would instead throw.
-inline NO_RETURN_DUE_TO_CRASH void Throw() { RELEASE_ASSERT_NOT_REACHED(); }
+#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
 
-static constexpr enum class ValueTagType { } ValueTag { };
-static constexpr enum class ErrorTagType { } ErrorTag { };
+__EXPECTED_INLINE_VARIABLE constexpr enum class value_tag_t { } value_tag { };
+__EXPECTED_INLINE_VARIABLE constexpr enum class error_tag_t { } error_tag { };
 
 template<class T, std::enable_if_t<std::is_trivially_destructible<T>::value>* = nullptr> void destroy(T&) { }
 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(); }
 
 template<class T, class E>
-union ConstexprStorage {
-    typedef T ValueType;
-    typedef E ErrorType;
-    typedef Unexpected<E> UnexpectedType;
+union constexpr_storage {
+    typedef T value_type;
+    typedef E error_type;
+    typedef unexpected<E> unexpected_type;
     char dummy;
-    ValueType val;
-    ErrorType err;
-    constexpr ConstexprStorage() : dummy() { }
-    constexpr ConstexprStorage(ValueTagType) : val() { }
-    constexpr ConstexprStorage(ErrorTagType) : err() { }
-    constexpr ConstexprStorage(ValueTagType, const ValueType& v) : val(v) { }
-    constexpr ConstexprStorage(ErrorTagType, const ErrorType& e) : err(e) { }
-    ~ConstexprStorage() = default;
+    value_type val;
+    error_type err;
+    constexpr constexpr_storage() : dummy() { }
+    constexpr constexpr_storage(value_tag_t) : val() { }
+    constexpr constexpr_storage(error_tag_t) : err() { }
+    constexpr constexpr_storage(value_tag_t, const value_type& v) : val(v) { }
+    constexpr constexpr_storage(error_tag_t, const error_type& e) : err(e) { }
+    ~constexpr_storage() = default;
 };
 
 template<class T, class E>
-union Storage {
-    typedef T ValueType;
-    typedef E ErrorType;
-    typedef Unexpected<E> UnexpectedType;
+union storage {
+    typedef T value_type;
+    typedef E error_type;
+    typedef unexpected<E> unexpected_type;
     char dummy;
-    ValueType val;
-    ErrorType err;
-    constexpr Storage() : dummy() { }
-    constexpr Storage(ValueTagType) : val() { }
-    constexpr Storage(ErrorTagType) : err() { }
-    constexpr Storage(ValueTagType, const ValueType& val) : val(val) { }
-    constexpr Storage(ValueTagType, ValueType&& val) : val(std::forward<ValueType>(val)) { }
-    constexpr Storage(ErrorTagType, const ErrorType& err) : err(err) { }
-    constexpr Storage(ErrorTagType, ErrorType&& err) : err(std::forward<ErrorType>(err)) { }
-    ~Storage() { }
+    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() { }
 };
 
 template<class E>
-union ConstexprStorage<void, E> {
-    typedef void ValueType;
-    typedef E ErrorType;
-    typedef Unexpected<E> UnexpectedType;
+union constexpr_storage<void, E> {
+    typedef void value_type;
+    typedef E error_type;
+    typedef unexpected<E> unexpected_type;
     char dummy;
-    ErrorType err;
-    constexpr ConstexprStorage() : dummy() { }
-    constexpr ConstexprStorage(ValueTagType) : dummy() { }
-    constexpr ConstexprStorage(ErrorTagType) : err() { }
-    constexpr ConstexprStorage(ErrorTagType, const ErrorType& e) : err(e) { }
-    ~ConstexprStorage() = default;
+    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;
 };
 
 template<class E>
-union Storage<void, E> {
-    typedef void ValueType;
-    typedef E ErrorType;
-    typedef Unexpected<E> UnexpectedType;
+union storage<void, E> {
+    typedef void value_type;
+    typedef E error_type;
+    typedef unexpected<E> unexpected_type;
     char dummy;
-    ErrorType err;
-    constexpr Storage() : dummy() { }
-    constexpr Storage(ValueTagType) : dummy() { }
-    constexpr Storage(ErrorTagType) : err() { }
-    constexpr Storage(ErrorTagType, const ErrorType& err) : err(err) { }
-    constexpr Storage(ErrorTagType, ErrorType&& err) : err(std::forward<ErrorType>(err)) { }
-    ~Storage() { }
+    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() { }
 };
 
 template<class T, class E>
-struct ConstexprBase {
-    typedef T ValueType;
-    typedef E ErrorType;
-    typedef Unexpected<E> UnexpectedType;
-    ConstexprStorage<ValueType, ErrorType> s;
+struct constexpr_base {
+    typedef T value_type;
+    typedef E error_type;
+    typedef unexpected<E> unexpected_type;
+    constexpr_storage<value_type, error_type> s;
     bool has;
-    constexpr ConstexprBase() : s(), has(true) { }
-    constexpr ConstexprBase(ValueTagType tag) : s(tag), has(true) { }
-    constexpr ConstexprBase(ErrorTagType tag) : s(tag), has(false) { }
-    constexpr ConstexprBase(ValueTagType tag, const ValueType& val) : s(tag, val), has(true) { }
-    constexpr ConstexprBase(ErrorTagType tag, const ErrorType& err) : s(tag, err), has(false) { }
-    ~ConstexprBase() = default;
+    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(value_tag_t tag, const value_type& val) : s(tag, val), has(true) { }
+    constexpr constexpr_base(error_tag_t tag, const error_type& err) : s(tag, err), has(false) { }
+    ~constexpr_base() = default;
 };
 
 template<class T, class E>
-struct Base {
-    typedef T ValueType;
-    typedef E ErrorType;
-    typedef Unexpected<E> UnexpectedType;
-    Storage<ValueType, ErrorType> s;
+struct base {
+    typedef T value_type;
+    typedef E error_type;
+    typedef unexpected<E> unexpected_type;
+    storage<value_type, error_type> s;
     bool has;
-    constexpr Base() : s(), has(true) { }
-    constexpr Base(ValueTagType tag) : s(tag), has(true) { }
-    constexpr Base(ErrorTagType tag) : s(tag), has(false) { }
-    constexpr Base(ValueTagType tag, const ValueType& val) : s(tag, val), has(true) { }
-    constexpr Base(ValueTagType tag, ValueType&& val) : s(tag, std::forward<ValueType>(val)), has(true) { }
-    constexpr Base(ErrorTagType tag, const ErrorType& err) : s(tag, err), has(false) { }
-    constexpr Base(ErrorTagType tag, ErrorType&& err) : s(tag, std::forward<ErrorType>(err)), has(false) { }
-    Base(const Base& o)
+    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)
         : has(o.has)
     {
         if (has)
-            ::new (&s.val) ValueType(o.s.val);
+            ::new (&s.val) value_type(o.s.val);
         else
-            ::new (&s.err) ErrorType(o.s.err);
+            ::new (&s.err) error_type(o.s.err);
     }
-    Base(Base&& o)
+    base(base&& o)
         : has(o.has)
     {
         if (has)
-            ::new (&s.val) ValueType(WTFMove(o.s.val));
+            ::new (&s.val) value_type(std::move(o.s.val));
         else
-            ::new (&s.err) ErrorType(WTFMove(o.s.err));
+            ::new (&s.err) error_type(std::move(o.s.err));
     }
-    ~Base()
+    ~base()
     {
         if (has)
             destroy(s.val);
@@ -197,45 +357,45 @@ struct Base {
 };
 
 template<class E>
-struct ConstexprBase<void, E> {
-    typedef void ValueType;
-    typedef E ErrorType;
-    typedef Unexpected<E> UnexpectedType;
-    ConstexprStorage<ValueType, ErrorType> s;
+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;
     bool has;
-    constexpr ConstexprBase() : s(), has(true) { }
-    constexpr ConstexprBase(ValueTagType tag) : s(tag), has(true) { }
-    constexpr ConstexprBase(ErrorTagType tag) : s(tag), has(false) { }
-    constexpr ConstexprBase(ErrorTagType tag, const ErrorType& err) : s(tag, err), has(false) { }
-    constexpr ConstexprBase(ErrorTagType tag, ErrorType&& err) : s(tag, std::forward<ErrorType>(err)), has(false) { }
-    ~ConstexprBase() = default;
+    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;
 };
 
 template<class E>
-struct Base<void, E> {
-    typedef void ValueType;
-    typedef E ErrorType;
-    typedef Unexpected<E> UnexpectedType;
-    Storage<ValueType, ErrorType> s;
+struct base<void, E> {
+    typedef void value_type;
+    typedef E error_type;
+    typedef unexpected<E> unexpected_type;
+    storage<value_type, error_type> s;
     bool has;
-    constexpr Base() : s(), has(true) { }
-    constexpr Base(ValueTagType tag) : s(tag), has(true) { }
-    constexpr Base(ErrorTagType tag) : s(tag), has(false) { }
-    constexpr Base(ErrorTagType tag, const ErrorType& err) : s(tag, err), has(false) { }
-    constexpr Base(ErrorTagType tag, ErrorType&& err) : s(tag, std::forward<ErrorType>(err)), has(false) { }
-    Base(const Base& o)
+    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)
         : has(o.has)
     {
         if (!has)
-            ::new (&s.err) ErrorType(o.s.err);
+            ::new (&s.err) error_type(o.s.err);
     }
-    Base(Base&& o)
+    base(base&& o)
         : has(o.has)
     {
         if (!has)
-            ::new (&s.err) ErrorType(WTFMove(o.s.err));
+            ::new (&s.err) error_type(std::move(o.s.err));
     }
-    ~Base()
+    ~base()
     {
         if (!has)
             destroy(s.err);
@@ -243,193 +403,175 @@ struct Base<void, E> {
 };
 
 template<class T, class E>
-using BaseSelect = typename std::conditional<
+using base_select = typename std::conditional<
     ((std::is_void<T>::value || std::is_trivially_destructible<T>::value)
         && std::is_trivially_destructible<E>::value),
-    ConstexprBase<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>
+    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>
 >::type;
 
-} // namespace ExpectedDetail
+} // namespace __expected_detail
 
 template<class T, class E>
-class Expected : private ExpectedDetail::BaseSelect<T, E> {
-    typedef ExpectedDetail::BaseSelect<T, E> base;
+class expected : private __expected_detail::base_select<T, E> {
+    typedef __expected_detail::base_select<T, E> base;
 
 public:
-    typedef typename base::ValueType ValueType;
-    typedef typename base::ErrorType ErrorType;
-    typedef typename base::UnexpectedType UnexpectedType;
+    typedef typename base::value_type value_type;
+    typedef typename base::error_type error_type;
+    typedef typename base::unexpected_type unexpected_type;
 
 private:
-    typedef Expected<ValueType, ErrorType> type;
+    typedef expected<value_type, error_type> type;
 
 public:
     template<class U> struct rebind {
-        using type = Expected<U, ErrorType>;
+        using type = expected<U, error_type>;
     };
 
-    constexpr Expected() : base(ExpectedDetail::ValueTag) { }
-    Expected(const Expected&) = default;
-    Expected(Expected&&) = default;
-
-    constexpr Expected(const ValueType& e) : base(ExpectedDetail::ValueTag, e) { }
-    constexpr Expected(ValueType&& e) : base(ExpectedDetail::ValueTag, std::forward<ValueType>(e)) { }
-    template<class... Args> constexpr explicit Expected(InPlaceTag, Args&&... args) : base(ExpectedDetail::ValueTag, ValueType(std::forward<Args>(args)...)) { }
-    // template<class U, class... Args> constexpr explicit Expected(in_place_t, std::initializer_list<U>, Args&&...);
-    constexpr Expected(const UnexpectedType& u) : base(ExpectedDetail::ErrorTag, u.value()) { }
-    constexpr Expected(UnexpectedType&& u) : base(ExpectedDetail::ErrorTag, std::forward<UnexpectedType>(u).value()) { }
-    template<class Err> constexpr Expected(const Unexpected<Err>& u) : base(ExpectedDetail::ErrorTag, u.value()) { }
-    template<class Err> constexpr Expected(Unexpected<Err>&& u) : base(ExpectedDetail::ErrorTag, std::forward<Err>(u.value())) { }
-    template<class... Args> constexpr explicit Expected(UnexpectTag, Args&&... args) : base(ExpectedDetail::ValueTag, UnexpectedType(std::forward<Args>(args)...)) { }
-    // template<class U, class... Args> constexpr explicit Expected(UnexpectTag, std::initializer_list<U>, Args&&...);
-
-    ~Expected() = default;
-
-    Expected& operator=(const Expected& e) { type(e).swap(*this); return *this; }
-    Expected& operator=(Expected&& e) { type(WTFMove(e)).swap(*this); return *this; }
-    template<class U> Expected& operator=(U&& u) { type(WTFMove(u)).swap(*this); return *this; }
-    Expected& operator=(const UnexpectedType& u) { type(u).swap(*this); return *this; }
-    Expected& operator=(UnexpectedType&& u) { type(WTFMove(u)).swap(*this); return *this; }
+    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::move(u)).swap(*this); return *this; }
+    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; }
     // template<class... Args> void emplace(Args&&...);
     // template<class U, class... Args> void emplace(std::initializer_list<U>, Args&&...);
 
-    void swap(Expected& o)
+    void swap(expected& o)
     {
         using std::swap;
         if (base::has && o.has)
             swap(base::s.val, o.s.val);
         else if (base::has && !o.has) {
-            ErrorType e(WTFMove(o.s.err));
-            ExpectedDetail::destroy(o.s.err);
-            ::new (&o.s.val) ValueType(WTFMove(base::s.val));
-            ExpectedDetail::destroy(base::s.val);
-            ::new (&base::s.err) ErrorType(WTFMove(e));
+            error_type e(std::move(o.s.err));
+            __expected_detail::destroy(o.s.err);
+            ::new (&o.s.val) value_type(std::move(base::s.val));
+            __expected_detail::destroy(base::s.val);
+            ::new (&base::s.err) error_type(std::move(e));
             swap(base::has, o.has);
         } else if (!base::has && o.has) {
-            ValueType v(WTFMove(o.s.val));
-            ExpectedDetail::destroy(o.s.val);
-            ::new (&o.s.err) ErrorType(WTFMove(base::s.err));
-            ExpectedDetail::destroy(base::s.err);
-            ::new (&base::s.val) ValueType(WTFMove(v));
+            value_type v(std::move(o.s.val));
+            __expected_detail::destroy(o.s.val);
+            ::new (&o.s.err) error_type(std::move(base::s.err));
+            __expected_detail::destroy(base::s.err);
+            ::new (&base::s.val) value_type(std::move(v));
             swap(base::has, o.has);
         } else
             swap(base::s.err, o.s.err);
     }
 
-    constexpr const ValueType* operator->() const { return &base::s.val; }
-    ValueType* operator->() { return &base::s.val; }
-    constexpr const ValueType& operator*() const & { return base::s.val; }
-    ValueType& operator*() & { return base::s.val; }
-    constexpr const ValueType&& operator*() const && { return WTFMove(base::s.val); }
-    RELAXED_CONSTEXPR ValueType&& operator*() && { return WTFMove(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 base::s.val; }
+    value_type& operator*() & { return base::s.val; }
+    constexpr const value_type&& operator*() const && { return std::move(base::s.val); }
+    RELAXED_CONSTEXPR value_type&& operator*() && { return std::move(base::s.val); }
     constexpr explicit operator bool() const { return base::has; }
-    constexpr bool hasValue() const { return base::has; }
-    constexpr const ValueType& value() const & { return base::has ? base::s.val : (ExpectedDetail::Throw(), base::s.val); }
-    RELAXED_CONSTEXPR ValueType& value() & { return base::has ? base::s.val : (ExpectedDetail::Throw(), base::s.val); }
-    constexpr const ValueType&& value() const && { return WTFMove(base::has ? base::s.val : (ExpectedDetail::Throw(), base::s.val)); }
-    RELAXED_CONSTEXPR ValueType&& value() && { return WTFMove(base::has ? base::s.val : (ExpectedDetail::Throw(), base::s.val)); }
-    constexpr const ErrorType& error() const & { return !base::has ? base::s.err : (ExpectedDetail::Throw(), base::s.err); }
-    ErrorType& error() & { return !base::has ? base::s.err : (ExpectedDetail::Throw(), base::s.err); }
-    RELAXED_CONSTEXPR ErrorType&& error() && { return WTFMove(!base::has ? base::s.err : (ExpectedDetail::Throw(), base::s.err)); }
-    constexpr const ErrorType&& error() const && { return WTFMove(!base::has ? base::s.err : (ExpectedDetail::Throw(), base::s.err)); }
-    constexpr UnexpectedType getUnexpected() const { return UnexpectedType(base::s.err); }
-    template<class U> constexpr ValueType valueOr(U&& u) const & { return base::has ? **this : static_cast<ValueType>(std::forward<U>(u)); }
-    template<class U> ValueType valueOr(U&& u) && { return base::has ? WTFMove(**this) : static_cast<ValueType>(std::forward<U>(u)); }
+    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); }
+    RELAXED_CONSTEXPR value_type& value() & { return base::has ? base::s.val : (__EXPECTED_THROW(bad_expected_access<error_type>(base::s.err)), base::s.val); }
+    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)); }
+    RELAXED_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)); }
+    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); }
+    RELAXED_CONSTEXPR error_type&& error() && { return std::move(!base::has ? base::s.err : (__EXPECTED_THROW(bad_expected_access<void>()), base::s.err)); }
+    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)); }
 };
 
 template<class E>
-class Expected<void, E> : private ExpectedDetail::BaseSelect<void, E> {
-    typedef ExpectedDetail::BaseSelect<void, E> base;
+class expected<void, E> : private __expected_detail::base_select<void, E> {
+    typedef __expected_detail::base_select<void, E> base;
 
 public:
-    typedef typename base::ValueType ValueType;
-    typedef typename base::ErrorType ErrorType;
-    typedef typename base::UnexpectedType UnexpectedType;
+    typedef typename base::value_type value_type;
+    typedef typename base::error_type error_type;
+    typedef typename base::unexpected_type unexpected_type;
 
 private:
-    typedef Expected<ValueType, ErrorType> type;
+    typedef expected<value_type, error_type> type;
 
 public:
     template<class U> struct rebind {
-        using type = Expected<U, ErrorType>;
+        using type = expected<U, error_type>;
     };
 
-    constexpr Expected() : base(ExpectedDetail::ValueTag) { }
-    Expected(const Expected&) = default;
-    Expected(Expected&&) = default;
-    // constexpr explicit Expected(in_place_t);
-    constexpr Expected(UnexpectedType const& u) : base(ExpectedDetail::ErrorTag, u.value()) { }
-    constexpr Expected(UnexpectedType&& u) : base(ExpectedDetail::ErrorTag, std::forward<UnexpectedType>(u).value()) { }
-    template<class Err> constexpr Expected(Unexpected<Err> const& u) : base(ExpectedDetail::ErrorTag, u.value()) { }
+    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()) { }
 
-    ~Expected() = default;
+    ~expected() = default;
 
-    Expected& operator=(const Expected& e) { type(e).swap(*this); return *this; }
-    Expected& operator=(Expected&& e) { type(WTFMove(e)).swap(*this); return *this; }
-    Expected& operator=(const UnexpectedType& u) { type(u).swap(*this); return *this; } // Not in the current paper.
-    Expected& operator=(UnexpectedType&& u) { type(WTFMove(u)).swap(*this); return *this; } // Not in the current paper.
+    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.
     // void emplace();
 
-    void swap(Expected& o)
+    void swap(expected& o)
     {
         using std::swap;
         if (base::has && o.has) {
             // Do nothing.
         } else if (base::has && !o.has) {
-            ErrorType e(WTFMove(o.s.err));
-            ::new (&base::s.err) ErrorType(e);
+            error_type e(std::move(o.s.err));
+            ::new (&base::s.err) error_type(e);
             swap(base::has, o.has);
         } else if (!base::has && o.has) {
-            ::new (&o.s.err) ErrorType(WTFMove(base::s.err));
+            ::new (&o.s.err) error_type(std::move(base::s.err));
             swap(base::has, o.has);
         } else
             swap(base::s.err, o.s.err);
     }
 
     constexpr explicit operator bool() const { return base::has; }
-    constexpr bool hasValue() const { return base::has; }
-    void value() const { !base::has ? ExpectedDetail::Throw() : void(); }
-    constexpr const E& error() const & { return !base::has ? base::s.err : (ExpectedDetail::Throw(), base::s.err); }
-    E& error() & { return !base::has ? base::s.err : (ExpectedDetail::Throw(), base::s.err); }
-    RELAXED_CONSTEXPR E&& error() && { return WTFMove(!base::has ? base::s.err : (ExpectedDetail::Throw(), base::s.err)); }
-    constexpr UnexpectedType getUnexpected() const { return UnexpectedType(base::s.err); }
+    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); }
+    RELAXED_CONSTEXPR E&& error() && { return std::move(!base::has ? base::s.err : (__EXPECTED_THROW(bad_expected_access<void>()), base::s.err)); }
 };
 
-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); }
-
-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()); }
-
-template<class T, class E> constexpr bool operator==(const Expected<T, E>& x, const T& y) { return x == Expected<T, E>(y); }
-template<class T, class E> constexpr bool operator==(const T& x, const Expected<T, E>& y) { return Expected<T, E>(x) == y; }
-template<class T, class E> constexpr bool operator!=(const Expected<T, E>& x, const T& y) { return x != Expected<T, E>(y); }
-template<class T, class E> constexpr bool operator!=(const T& x, const Expected<T, E>& y) { return Expected<T, E>(x) != y; }
+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); }
 
-template<class T, class E> constexpr bool operator==(const Expected<T, E>& x, const Unexpected<E>& y) { return x == Expected<T, E>(y); }
-template<class T, class E> constexpr bool operator==(const Unexpected<E>& x, const Expected<T, E>& y) { return Expected<T, E>(x) == y; }
-template<class T, class E> constexpr bool operator!=(const Expected<T, E>& x, const Unexpected<E>& y) { return x != Expected<T, E>(y); }
-template<class T, class E> constexpr bool operator!=(const Unexpected<E>& x, const Expected<T, E>& y) { return Expected<T, E>(x) != y; }
+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()); }
 
-template<typename T, typename E> void swap(Expected<T, E>& x, Expected<T, E>& y) { x.swap(y); }
+template<class T, class E> constexpr bool operator==(const expected<T, E>& x, const T& y) { return x == expected<T, E>(y); }
+template<class T, class E> constexpr bool operator==(const T& x, const expected<T, E>& y) { return expected<T, E>(x) == y; }
+template<class T, class E> constexpr bool operator!=(const expected<T, E>& x, const T& y) { return x != expected<T, E>(y); }
+template<class T, class E> constexpr bool operator!=(const T& x, const expected<T, E>& y) { return expected<T, E>(x) != y; }
 
-// Note: this isn't in the current proposal because it relies on C++17 deduction guides instead.
-template<class T, class E = std::nullopt_t> constexpr Expected<std::decay_t<T>, E> makeExpected(T&& v)
-{
-    return Expected<typename std::decay<T>::type, E>(std::forward<T>(v));
-}
-template<class T, class E> constexpr Expected<T, std::decay_t<E>> makeExpectedFromError(E&& e) { return Expected<T, std::decay_t<E>>(makeUnexpected(e)); }
-template<class T, class E, class U> constexpr Expected<T, E> makeExpectedFromError(U&& u) { return Expected<T, E>(makeUnexpected(E { std::forward<U>(u) } )); }
-// template<class F, class E = std::nullopt_t> constexpr Expected<typename std::result_of<F>::type, E> makeExpected_from_call(F f);
+template<class T, class E> constexpr bool operator==(const expected<T, E>& x, const unexpected<E>& y) { return x == expected<T, E>(y); }
+template<class T, class E> constexpr bool operator==(const unexpected<E>& x, const expected<T, E>& y) { return expected<T, E>(x) == y; }
+template<class T, class E> constexpr bool operator!=(const expected<T, E>& x, const unexpected<E>& y) { return x != expected<T, E>(y); }
+template<class T, class E> constexpr bool operator!=(const unexpected<E>& x, const expected<T, E>& y) { return expected<T, E>(x) != y; }
 
-inline Expected<void, std::nullopt_t> makeExpected() { return Expected<void, std::nullopt_t>(); }
+template<typename T, typename E> void swap(expected<T, E>& x, expected<T, E>& y) { x.swap(y); }
 
-} // namespace WTF
+}}} // namespace std::experimental::fundamentals_v3
 
-using WTF::InPlace;
-using WTF::Unexpected;
-using WTF::makeUnexpected;
-using WTF::Unexpect;
-using WTF::Expected;
-using WTF::makeExpected;
-using WTF::makeExpectedFromError;
+__EXPECTED_INLINE_VARIABLE constexpr std::experimental::unexpected_t& unexpect = std::experimental::unexpect;
+template<class T, class E> using Expected = std::experimental::expected<T, E>;
index 147a578..ef00c71 100644 (file)
@@ -60,7 +60,6 @@ template<typename> struct DefaultHash { using Hash = void; };
 template<typename> struct HashTraits;
 
 template<typename...> class Variant;
-template<class, class> class Expected;
 template<typename, size_t = 0, typename = CrashOnOverflow, size_t = 16, typename = FastMalloc> class Vector;
 template<typename Value, typename = typename DefaultHash<Value>::Hash, typename = HashTraits<Value>> class HashCountedSet;
 template<typename KeyArg, typename MappedArg, typename = typename DefaultHash<KeyArg>::Hash, typename = HashTraits<KeyArg>, typename = HashTraits<MappedArg>> class HashMap;
@@ -68,12 +67,18 @@ template<typename ValueArg, typename = typename DefaultHash<ValueArg>::Hash, typ
 
 }
 
+namespace std {
+namespace experimental {
+inline namespace fundamentals_v3 {
+template<class, class> class expected;
+template<class> class unexpected;
+}}} // namespace std::experimental::fundamentals_v3
+
 using WTF::AtomicString;
 using WTF::AtomicStringImpl;
 using WTF::BinarySemaphore;
 using WTF::CString;
 using WTF::CompletionHandler;
-using WTF::Expected;
 using WTF::Function;
 using WTF::FunctionDispatcher;
 using WTF::HashCountedSet;
@@ -97,3 +102,6 @@ using WTF::TextPosition;
 using WTF::TextStream;
 using WTF::Variant;
 using WTF::Vector;
+
+template<class T, class E> using Expected = std::experimental::expected<T, E>;
+template<class E> using Unexpected = std::experimental::unexpected<E>;
index d026e1f..d9e58d7 100644 (file)
@@ -282,10 +282,6 @@ constexpr U convert(U v) { return v; }
 constexpr struct trivial_init_t{} trivial_init{};
 
 
-// 20.5.6, In-place construction
-constexpr struct in_place_t{} in_place{};
-
-
 // 20.5.7, Disengaged state indicator
 struct nullopt_t
 {
index 12e393a..7fa1f14 100644 (file)
@@ -525,6 +525,29 @@ template<class B0, class B1, class B2, class... Bn> struct wtf_conjunction_impl<
 template<class... _Args> struct conjunction : wtf_conjunction_impl<_Args...> { };
 #endif
 
+#if __cplusplus < 201703L
+
+// These are inline variable for C++17 and later.
+#define __IN_PLACE_INLINE_VARIABLE static const
+
+struct in_place_t {
+    explicit in_place_t() = default;
+};
+__IN_PLACE_INLINE_VARIABLE constexpr in_place_t in_place { };
+
+template <class T> struct in_place_type_t {
+    explicit in_place_type_t() = default;
+};
+template <class T>
+__IN_PLACE_INLINE_VARIABLE constexpr in_place_type_t<T> in_place_type { };
+
+template <size_t I> struct in_place_index_t {
+    explicit in_place_index_t() = default;
+};
+template <size_t I>
+__IN_PLACE_INLINE_VARIABLE constexpr in_place_index_t<I> in_place_index { };
+#endif // __cplusplus < 201703L
+
 } // namespace std
 
 #define WTFMove(value) std::move<WTF::CheckMoveParameter>(value)
diff --git a/Source/WTF/wtf/Unexpected.h b/Source/WTF/wtf/Unexpected.h
new file mode 100644 (file)
index 0000000..a653b3c
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
+ *
+ * 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.
+ */
+
+// Implementation of Library Fundamentals v3's std::expected, as described here: http://wg21.link/p0323r4
+
+#pragma once
+
+/*
+    unexpected synopsis
+
+namespace std {
+namespace experimental {
+inline namespace fundamentals_v3 {
+    // ?.?.3, Unexpected object type
+    template <class E>
+      class unexpected;
+
+    // ?.?.4, Unexpected relational operators
+    template <class E>
+        constexpr bool
+        operator==(const unexpected<E>&, const unexpected<E>&);
+    template <class E>
+        constexpr bool
+        operator!=(const unexpected<E>&, const unexpected<E>&);
+
+    template <class E>
+    class unexpected {
+    public:
+        unexpected() = delete;
+        constexpr explicit unexpected(const E&);
+        constexpr explicit unexpected(E&&);
+        constexpr const E& value() const &;
+        constexpr E& value() &;
+        constexpr E&& value() &&;
+        constexpr E const&& value() const&&;
+    private:
+        E val; // exposition only
+    };
+
+}}}
+
+*/
+
+#include <cstdlib>
+#include <utility>
+#include <wtf/StdLibExtras.h>
+
+namespace std {
+namespace experimental {
+inline namespace fundamentals_v3 {
+
+template<class E>
+class unexpected {
+public:
+    unexpected() = delete;
+    constexpr explicit unexpected(const E& e) : val(e) { }
+    constexpr explicit unexpected(E&& e) : val(std::forward<E>(e)) { }
+    constexpr const E& value() const & { return val; }
+    RELAXED_CONSTEXPR E& value() & { return val; }
+    RELAXED_CONSTEXPR E&& value() && { return WTFMove(val); }
+    RELAXED_CONSTEXPR const E&& value() const && { return WTFMove(val); }
+
+private:
+    E val;
+};
+
+template<class E> constexpr bool operator==(const unexpected<E>& lhs, const unexpected<E>& rhs) { return lhs.value() == rhs.value(); }
+template<class E> constexpr bool operator!=(const unexpected<E>& lhs, const unexpected<E>& rhs) { return lhs.value() != rhs.value(); }
+
+}}} // namespace std::experimental::fundamentals_v3
+
+template<class E> using Unexpected = std::experimental::unexpected<E>;
+
+// Not in the std::expected spec, but useful to work around lack of C++17 deduction guides.
+template<class E> constexpr Unexpected<std::decay_t<E>> makeUnexpected(E&& v) { return Unexpected<typename std::decay<E>::type>(std::forward<E>(v)); }
index 987e97d..f879432 100644 (file)
@@ -1,3 +1,101 @@
+2017-12-04  JF Bastien  <jfbastien@apple.com>
+
+        Update std::expected to match libc++ coding style
+        https://bugs.webkit.org/show_bug.cgi?id=180264
+
+        Reviewed by Alex Christensen.
+
+        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):
+
 2017-12-04  Zalan Bujtas  <zalan@apple.com>
 
         REGRESSION (r211531): Text flow changes and overlaps other text after double-click selecting paragraph
index 5ea220b..78fe010 100644 (file)
@@ -420,12 +420,12 @@ void DOMCache::retrieveRecords(const URL& url, WTF::Function<void(std::optional<
 
     m_connection->retrieveRecords(m_identifier, retrieveURL, [this, callback = WTFMove(callback)](RecordsOrError&& result) {
         if (!m_isStopped) {
-            if (!result.hasValue()) {
+            if (!result.has_value()) {
                 callback(DOMCacheEngine::errorToException(result.error()));
                 return;
             }
 
-            if (result.hasValue())
+            if (result.has_value())
                 updateRecords(WTFMove(result.value()));
             callback(std::nullopt);
         }
@@ -469,7 +469,7 @@ void DOMCache::batchDeleteOperation(const FetchRequest& request, CacheQueryOptio
     setPendingActivity(this);
     m_connection->batchDeleteOperation(m_identifier, request.internalRequest(), WTFMove(options), [this, callback = WTFMove(callback)](RecordIdentifiersOrError&& result) {
         if (!m_isStopped) {
-            if (!result.hasValue())
+            if (!result.has_value())
                 callback(DOMCacheEngine::errorToException(result.error()));
             else
                 callback(!result.value().isEmpty());
@@ -512,7 +512,7 @@ void DOMCache::batchPutOperation(Vector<Record>&& records, WTF::Function<void(Ex
     setPendingActivity(this);
     m_connection->batchPutOperation(m_identifier, WTFMove(records), [this, callback = WTFMove(callback)](RecordIdentifiersOrError&& result) {
         if (!m_isStopped) {
-            if (!result.hasValue())
+            if (!result.has_value())
                 callback(DOMCacheEngine::errorToException(result.error()));
             else
                 callback({ });
index 46e6f2b..8599589 100644 (file)
@@ -142,7 +142,7 @@ void DOMCacheStorage::retrieveCaches(WTF::Function<void(std::optional<Exception>
     setPendingActivity(this);
     m_connection->retrieveCaches(origin, m_updateCounter, [this, callback = WTFMove(callback)](CacheInfosOrError&& result) mutable {
         if (!m_isStopped) {
-            if (!result.hasValue()) {
+            if (!result.has_value()) {
                 callback(DOMCacheEngine::errorToException(result.error()));
                 return;
             }
@@ -191,7 +191,7 @@ void DOMCacheStorage::open(const String& name, DOMPromiseDeferred<IDLInterface<D
         setPendingActivity(this);
         m_connection->open(origin, name, [this, name, promise = WTFMove(promise)](const CacheIdentifierOrError& result) mutable {
             if (!m_isStopped) {
-                if (!result.hasValue())
+                if (!result.has_value())
                     promise.reject(DOMCacheEngine::errorToException(result.error()));
                 else {
                     if (result.value().hadStorageError)
@@ -227,7 +227,7 @@ void DOMCacheStorage::remove(const String& name, DOMPromiseDeferred<IDLBoolean>&
         setPendingActivity(this);
         m_connection->remove(m_caches[position]->identifier(), [this, name, promise = WTFMove(promise)](const CacheIdentifierOrError& result) mutable {
             if (!m_isStopped) {
-                if (!result.hasValue())
+                if (!result.has_value())
                     promise.reject(DOMCacheEngine::errorToException(result.error()));
                 else {
                     if (result.value().hadStorageError)
index f0db13b..f9e5471 100644 (file)
@@ -124,7 +124,7 @@ void WorkerCacheStorageConnection::doRemove(uint64_t requestIdentifier, uint64_t
 {
     callOnMainThread([workerThread = makeRef(m_scope.thread()), mainThreadConnection = m_mainThreadConnection, requestIdentifier, cacheIdentifier] () mutable {
         mainThreadConnection->remove(cacheIdentifier, [workerThread = WTFMove(workerThread), requestIdentifier, cacheIdentifier] (const CacheIdentifierOrError& result) mutable {
-            ASSERT_UNUSED(cacheIdentifier, !result.hasValue() || result.value().identifier == cacheIdentifier);
+            ASSERT_UNUSED(cacheIdentifier, !result.has_value() || result.value().identifier == cacheIdentifier);
             workerThread->runLoop().postTaskForMode([requestIdentifier, result] (auto& scope) mutable {
                 downcast<WorkerGlobalScope>(scope).cacheStorageConnection().removeCompleted(requestIdentifier, result);
             }, WorkerRunLoop::defaultMode());
@@ -137,7 +137,7 @@ void WorkerCacheStorageConnection::doRetrieveCaches(uint64_t requestIdentifier,
     callOnMainThread([workerThread = makeRef(m_scope.thread()), mainThreadConnection = m_mainThreadConnection, requestIdentifier, origin = origin.isolatedCopy(), updateCounter] () mutable {
         mainThreadConnection->retrieveCaches(origin, updateCounter, [workerThread = WTFMove(workerThread), requestIdentifier] (CacheInfosOrError&& result) mutable {
             CacheInfosOrError isolatedResult;
-            if (!result.hasValue())
+            if (!result.has_value())
                 isolatedResult = WTFMove(result);
             else
                 isolatedResult = result.value().isolatedCopy();
@@ -170,7 +170,7 @@ static inline Vector<CrossThreadRecordData> recordsDataFromRecords(const Vector<
 
 static inline Expected<Vector<CrossThreadRecordData>, Error> recordsDataOrErrorFromRecords(const RecordsOrError& result)
 {
-    if (!result.hasValue())
+    if (!result.has_value())
         return makeUnexpected(result.error());
 
     return recordsDataFromRecords(result.value());
@@ -183,7 +183,7 @@ static inline Vector<Record> recordsFromRecordsData(Vector<CrossThreadRecordData
 
 static inline RecordsOrError recordsOrErrorFromRecordsData(Expected<Vector<CrossThreadRecordData>, Error>&& recordsData)
 {
-    if (!recordsData.hasValue())
+    if (!recordsData.has_value())
         return makeUnexpected(recordsData.error());
     return recordsFromRecordsData(WTFMove(recordsData.value()));
 }
index ee068f6..d662139 100644 (file)
@@ -63,7 +63,7 @@ CachedResourceHandle<CachedScript> CachedScriptFetcher::requestScriptWithCache(D
     if (!m_initiatorName.isNull())
         request.setInitiator(m_initiatorName);
 
-    return document.cachedResourceLoader().requestScript(WTFMove(request)).valueOr(nullptr);
+    return document.cachedResourceLoader().requestScript(WTFMove(request)).value_or(nullptr);
 }
 
 }
index 56dff6a..ef63409 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -287,7 +287,7 @@ static void compileToBytecode(CombinedURLFilters&& filters, UniversalActionSet&&
 std::error_code compileRuleList(ContentExtensionCompilationClient& client, String&& ruleJSON)
 {
     auto ruleList = parseRuleList(WTFMove(ruleJSON));
-    if (!ruleList.hasValue())
+    if (!ruleList.has_value())
         return ruleList.error();
     Vector<ContentExtensionRule> parsedRuleList = WTFMove(ruleList.value());
 
index 16614c5..ccdb262 100644 (file)
@@ -86,7 +86,7 @@ static Expected<Vector<String>, std::error_code> getStringList(ExecState& exec,
 static Expected<Vector<String>, std::error_code> getDomainList(ExecState& exec, const JSObject* arrayObject)
 {
     auto strings = getStringList(exec, arrayObject);
-    if (!strings.hasValue())
+    if (!strings.has_value())
         return strings;
     for (auto& domain : strings.value()) {
         // Domains should be punycode encoded lower case.
@@ -175,7 +175,7 @@ static Expected<Trigger, std::error_code> loadTrigger(ExecState& exec, const JSO
     const JSValue ifDomainValue = triggerObject.get(&exec, Identifier::fromString(&exec, "if-domain"));
     if (!scope.exception() && ifDomainValue.isObject()) {
         auto ifDomain = getDomainList(exec, asObject(ifDomainValue));
-        if (!ifDomain.hasValue())
+        if (!ifDomain.has_value())
             return makeUnexpected(ifDomain.error());
         trigger.conditions = WTFMove(ifDomain.value());
         if (trigger.conditions.isEmpty())
@@ -190,7 +190,7 @@ static Expected<Trigger, std::error_code> loadTrigger(ExecState& exec, const JSO
         if (trigger.conditionType != Trigger::ConditionType::None)
             return makeUnexpected(ContentExtensionError::JSONMultipleConditions);
         auto unlessDomain = getDomainList(exec, asObject(unlessDomainValue));
-        if (!unlessDomain.hasValue())
+        if (!unlessDomain.has_value())
             return makeUnexpected(unlessDomain.error());
         trigger.conditions = WTFMove(unlessDomain.value());
         if (trigger.conditions.isEmpty())
@@ -204,7 +204,7 @@ static Expected<Trigger, std::error_code> loadTrigger(ExecState& exec, const JSO
         if (trigger.conditionType != Trigger::ConditionType::None)
             return makeUnexpected(ContentExtensionError::JSONMultipleConditions);
         auto ifTopURL = getStringList(exec, asObject(ifTopURLValue));
-        if (!ifTopURL.hasValue())
+        if (!ifTopURL.has_value())
             return makeUnexpected(ifTopURL.error());
         trigger.conditions = WTFMove(ifTopURL.value());
         if (trigger.conditions.isEmpty())
@@ -218,7 +218,7 @@ static Expected<Trigger, std::error_code> loadTrigger(ExecState& exec, const JSO
         if (trigger.conditionType != Trigger::ConditionType::None)
             return makeUnexpected(ContentExtensionError::JSONMultipleConditions);
         auto unlessTopURL = getStringList(exec, asObject(unlessTopURLValue));
-        if (!unlessTopURL.hasValue())
+        if (!unlessTopURL.has_value())
             return makeUnexpected(unlessTopURL.error());
         trigger.conditions = WTFMove(unlessTopURL.value());
         if (trigger.conditions.isEmpty())
@@ -288,11 +288,11 @@ static Expected<std::optional<Action>, std::error_code> loadAction(ExecState& ex
 static Expected<std::optional<ContentExtensionRule>, std::error_code> loadRule(ExecState& exec, const JSObject& ruleObject)
 {
     auto trigger = loadTrigger(exec, ruleObject);
-    if (!trigger.hasValue())
+    if (!trigger.has_value())
         return makeUnexpected(trigger.error());
 
     auto action = loadAction(exec, ruleObject);
-    if (!action.hasValue())
+    if (!action.has_value())
         return makeUnexpected(action.error());
 
     if (action.value())
@@ -340,7 +340,7 @@ static Expected<Vector<ContentExtensionRule>, std::error_code> loadEncodedRules(
             return makeUnexpected(ContentExtensionError::JSONInvalidRule);
 
         auto rule = loadRule(exec, *ruleObject);
-        if (!rule.hasValue())
+        if (!rule.has_value())
             return makeUnexpected(rule.error());
         if (rule.value())
             ruleList.append(*rule.value());
@@ -364,7 +364,7 @@ Expected<Vector<ContentExtensionRule>, std::error_code> parseRuleList(String&& r
 
     vm = nullptr;
 
-    if (!ruleList.hasValue())
+    if (!ruleList.has_value())
         return makeUnexpected(ruleList.error());
 
     if (ruleList->isEmpty())
index 8acd9af..81d8a75 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -101,7 +101,7 @@ CachedFont* CSSFontFaceSrcValue::cachedFont(Document* document, bool isSVG, bool
 
     CachedResourceRequest request(ResourceRequest(document->completeURL(m_resource)), options);
     request.setInitiator(cachedResourceRequestInitiators().css);
-    m_cachedFont = document->cachedResourceLoader().requestFont(WTFMove(request), isSVG).valueOr(nullptr);
+    m_cachedFont = document->cachedResourceLoader().requestFont(WTFMove(request), isSVG).value_or(nullptr);
     return m_cachedFont.get();
 }
 
index a681b8b..a97dc21 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -103,7 +103,7 @@ std::pair<CachedImage*, float> CSSImageSetValue::loadBestFitImage(CachedResource
         if (options.mode == FetchOptions::Mode::Cors)
             request.updateForAccessControl(*document);
 
-        m_cachedImage = loader.requestImage(WTFMove(request)).valueOr(nullptr);
+        m_cachedImage = loader.requestImage(WTFMove(request)).value_or(nullptr);
         m_bestFitImageScaleFactor = image.scaleFactor;
     }
     return { m_cachedImage.get(), m_bestFitImageScaleFactor };
index 37363d0..c191ecc 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
- * Copyright (C) 2004, 2005, 2006, 2008, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2004-2017 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -72,7 +72,7 @@ CachedImage* CSSImageValue::loadImage(CachedResourceLoader& loader, const Resour
             ASSERT(loader.document());
             request.updateForAccessControl(*loader.document());
         }
-        m_cachedImage = loader.requestImage(WTFMove(request)).valueOr(nullptr);
+        m_cachedImage = loader.requestImage(WTFMove(request)).value_or(nullptr);
     }
     return m_cachedImage.get();
 }
index c00ff2e..0498aa6 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
  * (C) 2002-2003 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2002, 2005, 2006, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2002-2017 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -123,7 +123,7 @@ void StyleRuleImport::requestStyleSheet()
         request.setOptions(ResourceLoaderOptions(DoNotSendCallbacks, SniffContent, BufferData, StoredCredentialsPolicy::Use, ClientCredentialPolicy::MayAskClientForCredentials, FetchOptions::Credentials::Include, SkipSecurityCheck, FetchOptions::Mode::NoCors, DoNotIncludeCertificateInfo, ContentSecurityPolicyImposition::SkipPolicyCheck, DefersLoadingPolicy::AllowDefersLoading, CachingPolicy::AllowCaching));
         m_cachedSheet = document->cachedResourceLoader().requestUserCSSStyleSheet(WTFMove(request));
     } else
-        m_cachedSheet = document->cachedResourceLoader().requestCSSStyleSheet(WTFMove(request)).valueOr(nullptr);
+        m_cachedSheet = document->cachedResourceLoader().requestCSSStyleSheet(WTFMove(request)).value_or(nullptr);
     if (m_cachedSheet) {
         // if the import rule is issued dynamically, the sheet may be
         // removed from the pending sheet count, so let the doc know
index 3bebfe1..878fe42 100644 (file)
@@ -71,12 +71,12 @@ template<typename ReturnType> inline CallbackResult<ReturnType>::CallbackResult(
 
 template<typename ReturnType> inline CallbackResultType CallbackResult<ReturnType>::type() const
 {
-    return m_value.hasValue() ? CallbackResultType::Success : m_value.error();
+    return m_value.has_value() ? CallbackResultType::Success : m_value.error();
 }
 
 template<typename ReturnType> inline auto CallbackResult<ReturnType>::releaseReturnValue() -> ReturnType&&
 {
-    ASSERT(m_value.hasValue());
+    ASSERT(m_value.has_value());
     return WTFMove(m_value.value());
 }
 
index 82942bb..42cb34a 100644 (file)
@@ -3041,7 +3041,7 @@ URL Element::getNonEmptyURLAttribute(const QualifiedName& name) const
 
 int Element::getIntegralAttribute(const QualifiedName& attributeName) const
 {
-    return parseHTMLInteger(getAttribute(attributeName)).valueOr(0);
+    return parseHTMLInteger(getAttribute(attributeName)).value_or(0);
 }
 
 void Element::setIntegralAttribute(const QualifiedName& attributeName, int value)
@@ -3051,7 +3051,7 @@ void Element::setIntegralAttribute(const QualifiedName& attributeName, int value
 
 unsigned Element::getUnsignedIntegralAttribute(const QualifiedName& attributeName) const
 {
-    return parseHTMLNonNegativeInteger(getAttribute(attributeName)).valueOr(0);
+    return parseHTMLNonNegativeInteger(getAttribute(attributeName)).value_or(0);
 }
 
 void Element::setUnsignedIntegralAttribute(const QualifiedName& attributeName, unsigned value)
index ff95522..73c8d91 100644 (file)
@@ -1,6 +1,6 @@
 /*
 
-Copyright (C) 2016 Apple Inc. All rights reserved.
+Copyright (C) 2016-2017 Apple Inc. All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
@@ -95,7 +95,7 @@ template<typename ReturnType> template<typename OtherType> inline ExceptionOr<Re
 
 template<typename ReturnType> inline bool ExceptionOr<ReturnType>::hasException() const
 {
-    return !m_value.hasValue();
+    return !m_value.has_value();
 }
 
 template<typename ReturnType> inline const Exception& ExceptionOr<ReturnType>::exception() const
@@ -160,7 +160,7 @@ inline ExceptionOr<void>::ExceptionOr(Exception&& exception)
 
 inline bool ExceptionOr<void>::hasException() const
 {
-    return !m_value.hasValue();
+    return !m_value.has_value();
 }
 
 inline const Exception& ExceptionOr<void>::exception() const
index 15a2b15..95ce7cd 100644 (file)
@@ -158,14 +158,14 @@ void ProcessingInstruction::checkStyleSheet()
             if (m_isXSL) {
                 auto options = CachedResourceLoader::defaultCachedResourceOptions();
                 options.mode = FetchOptions::Mode::SameOrigin;
-                m_cachedSheet = document().cachedResourceLoader().requestXSLStyleSheet({ResourceRequest(document().completeURL(href)), options}).valueOr(nullptr);
+                m_cachedSheet = document().cachedResourceLoader().requestXSLStyleSheet({ResourceRequest(document().completeURL(href)), options}).value_or(nullptr);
             } else
 #endif
             {
                 String charset = attributes->get("charset");
                 CachedResourceRequest request(document().completeURL(href), CachedResourceLoader::defaultCachedResourceOptions(), std::nullopt, charset.isEmpty() ? document().charset() : WTFMove(charset));
 
-                m_cachedSheet = document().cachedResourceLoader().requestCSSStyleSheet(WTFMove(request)).valueOr(nullptr);
+                m_cachedSheet = document().cachedResourceLoader().requestCSSStyleSheet(WTFMove(request)).value_or(nullptr);
             }
             if (m_cachedSheet)
                 m_cachedSheet->addClient(*this);
index e5b92b4..3d86c7e 100644 (file)
@@ -1802,7 +1802,7 @@ bool HTMLInputElement::isEmptyValue() const
 void HTMLInputElement::maxLengthAttributeChanged(const AtomicString& newValue)
 {
     unsigned oldEffectiveMaxLength = effectiveMaxLength();
-    internalSetMaxLength(parseHTMLNonNegativeInteger(newValue).valueOr(-1));
+    internalSetMaxLength(parseHTMLNonNegativeInteger(newValue).value_or(-1));
     if (oldEffectiveMaxLength != effectiveMaxLength())
         updateValueIfNeeded();
 
@@ -1814,7 +1814,7 @@ void HTMLInputElement::maxLengthAttributeChanged(const AtomicString& newValue)
 void HTMLInputElement::minLengthAttributeChanged(const AtomicString& newValue)
 {
     int oldMinLength = minLength();
-    internalSetMinLength(parseHTMLNonNegativeInteger(newValue).valueOr(-1));
+    internalSetMinLength(parseHTMLNonNegativeInteger(newValue).value_or(-1));
     if (oldMinLength != minLength())
         updateValueIfNeeded();
 
index 9d3dce3..1584014 100644 (file)
@@ -315,7 +315,7 @@ void HTMLLinkElement::process()
         request.setAsPotentiallyCrossOrigin(crossOrigin(), document());
 
         ASSERT_WITH_SECURITY_IMPLICATION(!m_cachedSheet);
-        m_cachedSheet = document().cachedResourceLoader().requestCSSStyleSheet(WTFMove(request)).valueOr(nullptr);
+        m_cachedSheet = document().cachedResourceLoader().requestCSSStyleSheet(WTFMove(request)).value_or(nullptr);
 
         if (m_cachedSheet)
             m_cachedSheet->addClient(*this);
index 60f7016..d73f9cc 100644 (file)
@@ -202,13 +202,13 @@ void HTMLTextAreaElement::parseAttribute(const QualifiedName& name, const Atomic
 
 void HTMLTextAreaElement::maxLengthAttributeChanged(const AtomicString& newValue)
 {
-    internalSetMaxLength(parseHTMLNonNegativeInteger(newValue).valueOr(-1));
+    internalSetMaxLength(parseHTMLNonNegativeInteger(newValue).value_or(-1));
     updateValidity();
 }
 
 void HTMLTextAreaElement::minLengthAttributeChanged(const AtomicString& newValue)
 {
-    internalSetMinLength(parseHTMLNonNegativeInteger(newValue).valueOr(-1));
+    internalSetMinLength(parseHTMLNonNegativeInteger(newValue).value_or(-1));
     updateValidity();
 }
 
index 10ebb0b..6c86148 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -209,7 +209,7 @@ Expected<unsigned, HTMLIntegerParsingError> parseHTMLNonNegativeInteger(StringVi
 {
     auto optionalSignedResult = parseHTMLInteger(input);
     if (!optionalSignedResult)
-        return optionalSignedResult.getUnexpected();
+        return makeUnexpected(WTFMove(optionalSignedResult.error()));
 
     if (optionalSignedResult.value() < 0)
         return makeUnexpected(HTMLIntegerParsingError::NegativeOverflow);
index 269cc62..dcccc26 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -158,7 +158,7 @@ inline unsigned limitToOnlyHTMLNonNegative(unsigned value, unsigned defaultValue
 inline unsigned limitToOnlyHTMLNonNegative(StringView stringValue, unsigned defaultValue = 0)
 {
     ASSERT(defaultValue <= maxHTMLNonNegativeInteger);
-    unsigned value = parseHTMLNonNegativeInteger(stringValue).valueOr(defaultValue);
+    unsigned value = parseHTMLNonNegativeInteger(stringValue).value_or(defaultValue);
     ASSERT(value <= maxHTMLNonNegativeInteger);
     return value;
 }
index 122f0d9..91ac39e 100644 (file)
@@ -107,7 +107,7 @@ void CrossOriginPreflightChecker::startPreflight()
         preflightRequest.setInitiator(m_loader.options().initiator);
 
     ASSERT(!m_resource);
-    m_resource = m_loader.document().cachedResourceLoader().requestRawResource(WTFMove(preflightRequest)).valueOr(nullptr);
+    m_resource = m_loader.document().cachedResourceLoader().requestRawResource(WTFMove(preflightRequest)).value_or(nullptr);
     if (m_resource)
         m_resource->addClient(*this);
 }
index ac88590..c8944f8 100644 (file)
@@ -1531,7 +1531,7 @@ void DocumentLoader::loadMainResource(ResourceRequest&& request)
     mainResourceRequest.setNavigationServiceWorkerRegistrationData(m_serviceWorkerRegistrationData);
 #endif
 
-    m_mainResource = m_cachedResourceLoader->requestMainResource(WTFMove(mainResourceRequest)).valueOr(nullptr);
+    m_mainResource = m_cachedResourceLoader->requestMainResource(WTFMove(mainResourceRequest)).value_or(nullptr);
 
 #if ENABLE(CONTENT_EXTENSIONS)
     if (m_mainResource && m_mainResource->errorOccurred() && m_frame->page() && m_mainResource->resourceError().domain() == ContentExtensions::WebKitContentBlockerDomain) {
index bf1fb44..9903f5e 100644 (file)
@@ -469,7 +469,7 @@ void DocumentThreadableLoader::loadRequest(ResourceRequest&& request, SecurityCh
         }
 
         auto cachedResource = m_document.cachedResourceLoader().requestRawResource(WTFMove(newRequest));
-        m_resource = cachedResource.valueOr(nullptr);
+        m_resource = cachedResource.value_or(nullptr);
         if (m_resource)
             m_resource->addClient(*this);
         else
index bbd464c..627271f 100644 (file)
@@ -192,7 +192,7 @@ void ImageLoader::updateFromElement()
             document.cachedResourceLoader().m_documentResources.set(newImage->url(), newImage.get());
             document.cachedResourceLoader().setAutoLoadImages(autoLoadOtherImages);
         } else
-            newImage = document.cachedResourceLoader().requestImage(WTFMove(request)).valueOr(nullptr);
+            newImage = document.cachedResourceLoader().requestImage(WTFMove(request)).value_or(nullptr);
 
         // If we do not have an image here, it means that a cross-site
         // violation occurred, or that the image was blocked via Content
index eb80e84..895f1c3 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2011 Google Inc. All rights reserved.
- * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -231,7 +231,7 @@ std::unique_ptr<LinkPreloadResourceClient> LinkLoader::preloadIfNeeded(const Lin
     linkRequest.setIsLinkPreload();
 
     linkRequest.setAsPotentiallyCrossOrigin(crossOriginMode, document);
-    auto cachedLinkResource = document.cachedResourceLoader().preload(type.value(), WTFMove(linkRequest)).valueOr(nullptr);
+    auto cachedLinkResource = document.cachedResourceLoader().preload(type.value(), WTFMove(linkRequest)).value_or(nullptr);
 
     if (cachedLinkResource && loader)
         return createLinkPreloadResourceClient(*cachedLinkResource, *loader, type.value());
@@ -298,7 +298,7 @@ bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const URL& href,
         }
         ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions();
         options.contentSecurityPolicyImposition = ContentSecurityPolicyImposition::SkipPolicyCheck;
-        m_cachedLinkResource = document.cachedResourceLoader().requestLinkResource(type, CachedResourceRequest(ResourceRequest(document.completeURL(href)), options, priority)).valueOr(nullptr);
+        m_cachedLinkResource = document.cachedResourceLoader().requestLinkResource(type, CachedResourceRequest(ResourceRequest(document.completeURL(href)), options, priority)).value_or(nullptr);
         if (m_cachedLinkResource)
             m_cachedLinkResource->addClient(*this);
     }
index 841d8f1..467456d 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2014 Igalia S.L
- * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -81,7 +81,7 @@ RefPtr<PlatformMediaResource> MediaResourceLoader::requestResource(ResourceReque
     if (m_mediaElement)
         cacheRequest.setInitiator(*m_mediaElement.get());
 
-    auto resource = m_document->cachedResourceLoader().requestMedia(WTFMove(cacheRequest)).valueOr(nullptr);
+    auto resource = m_document->cachedResourceLoader().requestMedia(WTFMove(cacheRequest)).value_or(nullptr);
     if (!resource)
         return nullptr;
 
index 8040b78..ff1436d 100644 (file)
@@ -155,7 +155,7 @@ bool TextTrackLoader::load(const URL& url, const String& crossOriginMode, bool i
     CachedResourceRequest cueRequest(ResourceRequest(document->completeURL(url)), options);
     cueRequest.setAsPotentiallyCrossOrigin(crossOriginMode, *document);
 
-    m_resource = document->cachedResourceLoader().requestTextTrack(WTFMove(cueRequest)).valueOr(nullptr);
+    m_resource = document->cachedResourceLoader().requestTextTrack(WTFMove(cueRequest)).value_or(nullptr);
     if (!m_resource)
         return false;
 
index 2e08ee2..12e6063 100644 (file)
@@ -56,7 +56,7 @@ void CachedSVGDocumentReference::load(CachedResourceLoader& loader, const Resour
     fetchOptions.mode = FetchOptions::Mode::SameOrigin;
     CachedResourceRequest request(ResourceRequest(loader.document()->completeURL(m_url)), fetchOptions);
     request.setInitiator(cachedResourceRequestInitiators().css);
-    m_document = loader.requestSVGDocument(WTFMove(request)).valueOr(nullptr);
+    m_document = loader.requestSVGDocument(WTFMove(request)).value_or(nullptr);
     if (m_document)
         m_document->addClient(*this);
 
index 15d44f5..d82d3ad 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006 Apple Inc.  All rights reserved.
+ * Copyright (C) 2006-2017 Apple Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -76,7 +76,7 @@ void IconLoader::startLoading()
     request.setInitiator(cachedResourceRequestInitiators().icon);
 
     auto cachedResource = frame->document()->cachedResourceLoader().requestIcon(WTFMove(request));
-    m_resource = cachedResource.valueOr(nullptr);
+    m_resource = cachedResource.value_or(nullptr);
     if (m_resource)
         m_resource->addClient(*this);
     else
index 6728612..6b4ca61 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -2314,11 +2314,11 @@ Expected<URLParser::IPv4Address, URLParser::IPv4ParsingError> URLParser::parseIP
     if (!iterator.atEnd() || !items.size() || items.size() > 4)
         return makeUnexpected(IPv4ParsingError::NotIPv4);
     for (const auto& item : items) {
-        if (!item.hasValue() && item.error() == IPv4PieceParsingError::Failure)
+        if (!item.has_value() && item.error() == IPv4PieceParsingError::Failure)
             return makeUnexpected(IPv4ParsingError::NotIPv4);
     }
     for (const auto& item : items) {
-        if (!item.hasValue() && item.error() == IPv4PieceParsingError::Overflow)
+        if (!item.has_value() && item.error() == IPv4PieceParsingError::Overflow)
             return makeUnexpected(IPv4ParsingError::Failure);
     }
     if (items.size() > 1) {
index d951882..52eb744 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -77,7 +77,7 @@ void WebCoreAVCFResourceLoader::startLoading()
     CachedResourceRequest request(WTFMove(resourceRequest), ResourceLoaderOptions(SendCallbacks, DoNotSniffContent, BufferData, StoredCredentialsPolicy::DoNotUse, ClientCredentialPolicy::CannotAskClientForCredentials, FetchOptions::Credentials::Omit, DoSecurityCheck, FetchOptions::Mode::NoCors, DoNotIncludeCertificateInfo, ContentSecurityPolicyImposition::DoPolicyCheck, DefersLoadingPolicy::AllowDefersLoading, CachingPolicy::DisallowCaching));
 
     CachedResourceLoader* loader = m_parent->player()->cachedResourceLoader();
-    m_resource = loader ? loader->requestRawResource(WTFMove(request)).valueOr(nullptr) : nullptr;
+    m_resource = loader ? loader->requestRawResource(WTFMove(request)).value_or(nullptr) : nullptr;
     if (m_resource)
         m_resource->addClient(*this);
     else {
index 847a4f9..971c831 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -74,7 +74,7 @@ void WebCoreAVFResourceLoader::startLoading()
     // is in a user-agent shadow tree. See <https://bugs.webkit.org/show_bug.cgi?id=173498>.
     CachedResourceRequest request(WTFMove(resourceRequest), ResourceLoaderOptions(SendCallbacks, DoNotSniffContent, BufferData, StoredCredentialsPolicy::DoNotUse, ClientCredentialPolicy::CannotAskClientForCredentials, FetchOptions::Credentials::Omit, DoSecurityCheck, FetchOptions::Mode::NoCors, DoNotIncludeCertificateInfo, ContentSecurityPolicyImposition::DoPolicyCheck, DefersLoadingPolicy::AllowDefersLoading, CachingPolicy::DisallowCaching));
     if (auto* loader = m_parent->player()->cachedResourceLoader())
-        m_resource = loader->requestMedia(WTFMove(request)).valueOr(nullptr);
+        m_resource = loader->requestMedia(WTFMove(request)).value_or(nullptr);
 
     if (m_resource)
         m_resource->addClient(*this);
index c4c9d05..3c70bbd 100644 (file)
@@ -89,7 +89,7 @@ void SVGFEImageElement::requestImageResource()
 
     CachedResourceRequest request(ResourceRequest(document().completeURL(href())), options);
     request.setInitiator(*this);
-    m_cachedImage = document().cachedResourceLoader().requestImage(WTFMove(request)).valueOr(nullptr);
+    m_cachedImage = document().cachedResourceLoader().requestImage(WTFMove(request)).value_or(nullptr);
 
     if (m_cachedImage)
         m_cachedImage->addClient(*this);
index 9d76105..60a99ef 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
- * Copyright (C) 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2009-2017 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -106,7 +106,7 @@ void SVGFontFaceUriElement::loadFont()
         CachedResourceLoader& cachedResourceLoader = document().cachedResourceLoader();
         CachedResourceRequest request(ResourceRequest(document().completeURL(href)), options);
         request.setInitiator(*this);
-        m_cachedFont = cachedResourceLoader.requestFont(WTFMove(request), isSVGFontTarget(*this)).valueOr(nullptr);
+        m_cachedFont = cachedResourceLoader.requestFont(WTFMove(request), isSVGFontTarget(*this)).value_or(nullptr);
         if (m_cachedFont) {
             m_cachedFont->addClient(*this);
             m_cachedFont->beginLoadIfNeeded(cachedResourceLoader);
index eedf866..058813a 100644 (file)
@@ -5,7 +5,7 @@
  * Copyright (C) 2011 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
  * Copyright (C) 2012 University of Szeged
  * Copyright (C) 2012 Renata Hodovan <reni@webkit.org>
- * Copyright (C) 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2017 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -590,7 +590,7 @@ void SVGUseElement::updateExternalDocument()
         options.mode = FetchOptions::Mode::SameOrigin;
         CachedResourceRequest request { ResourceRequest { externalDocumentURL }, options };
         request.setInitiator(*this);
-        m_externalDocument = document().cachedResourceLoader().requestSVGDocument(WTFMove(request)).valueOr(nullptr);
+        m_externalDocument = document().cachedResourceLoader().requestSVGDocument(WTFMove(request)).value_or(nullptr);
         if (m_externalDocument)
             m_externalDocument->addClient(*this);
     }
index 7ad3994..84ca40f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the XSL implementation.
  *
- * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004-2017 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -103,7 +103,7 @@ void XSLImportRule::loadSheet()
 
     auto options = CachedResourceLoader::defaultCachedResourceOptions();
     options.mode = FetchOptions::Mode::SameOrigin;
-    m_cachedSheet = cachedResourceLoader->requestXSLStyleSheet({ResourceRequest(cachedResourceLoader->document()->completeURL(absHref)), options}).valueOr(nullptr);
+    m_cachedSheet = cachedResourceLoader->requestXSLStyleSheet({ResourceRequest(cachedResourceLoader->document()->completeURL(absHref)), options}).value_or(nullptr);
 
     if (m_cachedSheet) {
         m_cachedSheet->addClient(*this);
index 552d614..f09f902 100644 (file)
@@ -1,3 +1,31 @@
+2017-12-04  JF Bastien  <jfbastien@apple.com>
+
+        Update std::expected to match libc++ coding style
+        https://bugs.webkit.org/show_bug.cgi?id=180264
+
+        Reviewed by Alex Christensen.
+
+        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:
+
 2017-12-04  Brady Eidson  <beidson@apple.com>
 
         Get a directory path to SWServers for storing ServiceWorker registrations.
index 6794935..ada4140 100644 (file)
@@ -119,7 +119,7 @@ Engine::Engine(String&& rootPath)
 void Engine::open(const String& origin, const String& cacheName, CacheIdentifierCallback&& callback)
 {
     readCachesFromDisk(origin, [cacheName, callback = WTFMove(callback)](CachesOrError&& cachesOrError) mutable {
-        if (!cachesOrError.hasValue()) {
+        if (!cachesOrError.has_value()) {
             callback(makeUnexpected(cachesOrError.error()));
             return;
         }
@@ -149,7 +149,7 @@ void Engine::remove(uint64_t cacheIdentifier, CacheIdentifierCallback&& callback
 void Engine::retrieveCaches(const String& origin, uint64_t updateCounter, CacheInfosCallback&& callback)
 {
     readCachesFromDisk(origin, [updateCounter, callback = WTFMove(callback)](CachesOrError&& cachesOrError) mutable {
-        if (!cachesOrError.hasValue()) {
+        if (!cachesOrError.has_value()) {
             callback(makeUnexpected(cachesOrError.error()));
             return;
         }
@@ -161,7 +161,7 @@ void Engine::retrieveCaches(const String& origin, uint64_t updateCounter, CacheI
 void Engine::retrieveRecords(uint64_t cacheIdentifier, WebCore::URL&& url, RecordsCallback&& callback)
 {
     readCache(cacheIdentifier, [url = WTFMove(url), callback = WTFMove(callback)](CacheOrError&& result) mutable {
-        if (!result.hasValue()) {
+        if (!result.has_value()) {
             callback(makeUnexpected(result.error()));
             return;
         }
@@ -172,7 +172,7 @@ void Engine::retrieveRecords(uint64_t cacheIdentifier, WebCore::URL&& url, Recor
 void Engine::putRecords(uint64_t cacheIdentifier, Vector<Record>&& records, RecordIdentifiersCallback&& callback)
 {
     readCache(cacheIdentifier, [records = WTFMove(records), callback = WTFMove(callback)](CacheOrError&& result) mutable {
-        if (!result.hasValue()) {
+        if (!result.has_value()) {
             callback(makeUnexpected(result.error()));
             return;
         }
@@ -184,7 +184,7 @@ void Engine::putRecords(uint64_t cacheIdentifier, Vector<Record>&& records, Reco
 void Engine::deleteMatchingRecords(uint64_t cacheIdentifier, WebCore::ResourceRequest&& request, WebCore::CacheQueryOptions&& options, RecordIdentifiersCallback&& callback)
 {
     readCache(cacheIdentifier, [request = WTFMove(request), options = WTFMove(options), callback = WTFMove(callback)](CacheOrError&& result) mutable {
-        if (!result.hasValue()) {
+        if (!result.has_value()) {
             callback(makeUnexpected(result.error()));
             return;
         }
@@ -397,7 +397,7 @@ void Engine::fetchEntries(bool shouldComputeSize, WTF::CompletionHandler<void(Ve
 
             auto cacheOrigin = origin->securityOrigin()->toString();
             protectedThis->readCachesFromDisk(cacheOrigin, [origin = WTFMove(origin.value()), taskCounter = WTFMove(taskCounter)] (CachesOrError&& result) mutable {
-                if (!result.hasValue())
+                if (!result.has_value())
                     return;
                 taskCounter->addOrigin(WTFMove(origin), result.value().get().storageSize());
 
@@ -440,7 +440,7 @@ void Engine::clearCachesForOrigin(const String& origin, CallbackAggregator& task
 void Engine::clearMemoryRepresentation(const String& origin, WebCore::DOMCacheEngine::CompletionCallback&& callback)
 {
     readCachesFromDisk(origin, [callback = WTFMove(callback)](CachesOrError&& result) {
-        if (!result.hasValue()) {
+        if (!result.has_value()) {
             callback(result.error());
             return;
         }
index a69c3aa..7b3aaa2 100644 (file)
@@ -256,7 +256,7 @@ public:
     void appendRecord(Expected<Record, Error>&& result, uint64_t recordIdentifier, uint64_t updateCounter)
     {
         ASSERT(RunLoop::isMain());
-        if (!result.hasValue()) {
+        if (!result.has_value()) {
             m_failedRecords.append(recordIdentifier);
             return;
         }
@@ -492,7 +492,7 @@ void Cache::updateRecordToDisk(RecordInformation& existingRecord, Record&& recor
 {
     ++existingRecord.updateResponseCounter;
     readRecordFromDisk(existingRecord, [caches = makeRef(m_caches), identifier = m_identifier, recordIdentifier = existingRecord.identifier, record = WTFMove(record), taskCounter = WTFMove(taskCounter)](Expected<Record, Error>&& result) mutable {
-        if (!result.hasValue())
+        if (!result.has_value())
             return;
 
         auto* cache = caches->find(identifier);
index 3c4e777..4689845 100644 (file)
@@ -142,7 +142,7 @@ void Caches::initialize(WebCore::DOMCacheEngine::CompletionCallback&& callback)
         readCachesFromDisk([this, callback = WTFMove(callback)](Expected<Vector<Cache>, Error>&& result) mutable {
             makeDirty();
 
-            if (!result.hasValue()) {
+            if (!result.has_value()) {
                 callback(result.error());
 
                 auto pendingCallbacks = WTFMove(m_pendingInitializationCallbacks);
@@ -350,7 +350,7 @@ void Caches::readCachesFromDisk(WTF::Function<void(Expected<Vector<Cache>, Error
         }
 
         auto result = decodeCachesNames(data, error);
-        if (!result.hasValue()) {
+        if (!result.has_value()) {
             callback(makeUnexpected(result.error()));
             return;
         }
index b6eadcd..a520404 100644 (file)
@@ -165,7 +165,7 @@ void NetworkRTCProvider::didReceiveNetworkRTCSocketMessage(IPC::Connection& conn
 void NetworkRTCProvider::createResolver(uint64_t identifier, const String& address)
 {
     auto resolver = std::make_unique<NetworkRTCResolver>([this, identifier](NetworkRTCResolver::AddressesOrError&& result) mutable {
-        if (!result.hasValue()) {
+        if (!result.has_value()) {
             if (result.error() != NetworkRTCResolver::Error::Cancelled)
                 m_connection->connection().send(Messages::WebRTCResolver::ResolvedAddressError(1), identifier);
             return;
index 8357eab..8384525 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2010-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -482,10 +482,10 @@ template<typename KeyArg, typename HashArg, typename KeyTraitsArg> struct Argume
     }
 };
 
-template<typename ValueType, typename ErrorType> struct ArgumentCoder<WTF::Expected<ValueType, ErrorType>> {
-    static void encode(Encoder& encoder, const WTF::Expected<ValueType, ErrorType>& expected)
+template<typename ValueType, typename ErrorType> struct ArgumentCoder<Expected<ValueType, ErrorType>> {
+    static void encode(Encoder& encoder, const Expected<ValueType, ErrorType>& expected)
     {
-        if (!expected.hasValue()) {
+        if (!expected.has_value()) {
             encoder << false;
             encoder << expected.error();
             return;
@@ -494,7 +494,7 @@ template<typename ValueType, typename ErrorType> struct ArgumentCoder<WTF::Expec
         encoder << expected.value();
     }
 
-    static std::optional<WTF::Expected<ValueType, ErrorType>> decode(Decoder& decoder)
+    static std::optional<Expected<ValueType, ErrorType>> decode(Decoder& decoder)
     {
         std::optional<bool> hasValue;
         decoder >> hasValue;
@@ -507,7 +507,7 @@ template<typename ValueType, typename ErrorType> struct ArgumentCoder<WTF::Expec
             if (!value)
                 return std::nullopt;
             
-            WTF::Expected<ValueType, ErrorType> expected(WTFMove(*value));
+            Expected<ValueType, ErrorType> expected(WTFMove(*value));
             return WTFMove(expected);
         }
         std::optional<ErrorType> error;
index deff6e5..e6d964a 100644 (file)
@@ -1,3 +1,21 @@
+2017-12-04  JF Bastien  <jfbastien@apple.com>
+
+        Update std::expected to match libc++ coding style
+        https://bugs.webkit.org/show_bug.cgi?id=180264
+
+        Reviewed by Alex Christensen.
+
+        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):
+
 2017-12-04  Ross Kirsling  <ross.kirsling@sony.com>
 
         download-latest-github-release.py should use existing release ANY time latest is not found
index ac8016b..3bd48d3 100644 (file)
 #include <string>
 
 #include <wtf/Expected.h>
+#include <wtf/Unexpected.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/Ref.h>
 
-namespace WTF {
+namespace std {
 
 template<typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const std::pair<T0, T1>& p)
 {
     return os << '(' << p.first << ", " << p.second << ')';
 }
 
+namespace experimental {
+inline namespace fundamentals_v3 {
+
 template<class E> std::ostream& operator<<(std::ostream& os, const Unexpected<E>& u)
 {
     return os << u.value();
@@ -48,19 +52,20 @@ template<class E> std::ostream& operator<<(std::ostream& os, const Unexpected<E>
 
 template<class T, class E> std::ostream& operator<<(std::ostream& os, const Expected<T, E>& e)
 {
-    if (e.hasValue())
+    if (e.has_value())
         return os << e.value();
     return os << e.error();
 }
 
 template<class E> std::ostream& operator<<(std::ostream& os, const Expected<void, E>& e)
 {
-    if (e.hasValue())
+    if (e.has_value())
         return os << "";
     return os << e.error();
 }
 
-}
+}}} // namespace std::experimental::fundamentals_v3
+
 
 namespace TestWebKitAPI {
 
@@ -111,79 +116,62 @@ TEST(WTF_Expected, expected)
     typedef Expected<foo, std::string> FooString;
     {
         auto e = E();
-        EXPECT_TRUE(e.hasValue());
+        EXPECT_TRUE(e.has_value());
         EXPECT_EQ(e.value(), 0);
-        EXPECT_EQ(e.valueOr(3.14), 0);
+        EXPECT_EQ(e.value_or(3.14), 0);
     }
     {
         constexpr E e;
-        EXPECT_TRUE(e.hasValue());
+        EXPECT_TRUE(e.has_value());
         EXPECT_EQ(e.value(), 0);
-        EXPECT_EQ(e.valueOr(3.14), 0);
+        EXPECT_EQ(e.value_or(3.14), 0);
     }
     {
         auto e = E(42);
-        EXPECT_TRUE(e.hasValue());
+        EXPECT_TRUE(e.has_value());
         EXPECT_EQ(e.value(), 42);
-        EXPECT_EQ(e.valueOr(3.14), 42);
+        EXPECT_EQ(e.value_or(3.14), 42);
         const auto e2(e);
-        EXPECT_TRUE(e2.hasValue());
+        EXPECT_TRUE(e2.has_value());
         EXPECT_EQ(e2.value(), 42);
-        EXPECT_EQ(e2.valueOr(3.14), 42);
+        EXPECT_EQ(e2.value_or(3.14), 42);
         E e3;
         e3 = e2;
-        EXPECT_TRUE(e3.hasValue());
+        EXPECT_TRUE(e3.has_value());
         EXPECT_EQ(e3.value(), 42);
-        EXPECT_EQ(e3.valueOr(3.14), 42);
+        EXPECT_EQ(e3.value_or(3.14), 42);
         const E e4 = e2;
-        EXPECT_TRUE(e4.hasValue());
+        EXPECT_TRUE(e4.has_value());
         EXPECT_EQ(e4.value(), 42);
-        EXPECT_EQ(e4.valueOr(3.14), 42);
+        EXPECT_EQ(e4.value_or(3.14), 42);
     }
     {
         constexpr E c(42);
-        EXPECT_TRUE(c.hasValue());
+        EXPECT_TRUE(c.has_value());
         EXPECT_EQ(c.value(), 42);
-        EXPECT_EQ(c.valueOr(3.14), 42);
+        EXPECT_EQ(c.value_or(3.14), 42);
         constexpr const auto c2(c);
-        EXPECT_TRUE(c2.hasValue());
+        EXPECT_TRUE(c2.has_value());
         EXPECT_EQ(c2.value(), 42);
-        EXPECT_EQ(c2.valueOr(3.14), 42);
+        EXPECT_EQ(c2.value_or(3.14), 42);
     }
     {
         auto u = E(makeUnexpected(oops));
-        EXPECT_FALSE(u.hasValue());
+        EXPECT_FALSE(u.has_value());
         EXPECT_EQ(u.error(), oops);
-        EXPECT_EQ(u.getUnexpected().value(), oops);
-        EXPECT_EQ(u.valueOr(3.14), 3);
+        EXPECT_EQ(u.value_or(3.14), 3);
     }
     {
         auto uv = EV(makeUnexpected(oops));
-        EXPECT_FALSE(uv.hasValue());
+        EXPECT_FALSE(uv.has_value());
         EXPECT_EQ(uv.error(), oops);
-        EXPECT_EQ(uv.getUnexpected().value(), oops);
-        EXPECT_EQ(uv.valueOr(3.14), 3);
+        EXPECT_EQ(uv.value_or(3.14), 3);
     }
     {
         E e = makeUnexpected(oops);
-        EXPECT_FALSE(e.hasValue());
-        EXPECT_EQ(e.error(), oops);
-        EXPECT_EQ(e.getUnexpected().value(), oops);
-        EXPECT_EQ(e.valueOr(3.14), 3);
-    }
-    {
-        auto e = makeExpectedFromError<int, const char*>(oops);
-        EXPECT_FALSE(e.hasValue());
+        EXPECT_FALSE(e.has_value());
         EXPECT_EQ(e.error(), oops);
-        EXPECT_EQ(e.getUnexpected().value(), oops);
-        EXPECT_EQ(e.valueOr(3.14), 3);
-    }
-    {
-        auto e = makeExpectedFromError<int, const void*>(oops);
-        EXPECT_FALSE(e.hasValue());
-        EXPECT_EQ(e.error(), oops);
-        EXPECT_EQ(e.getUnexpected().value(), oops);
-        EXPECT_EQ(e.valueOr(3.14), 3);
+        EXPECT_EQ(e.value_or(3.14), 3);
     }
     {
         auto e = FooChar(42);
@@ -236,51 +224,36 @@ TEST(WTF_Expected, void)
     typedef Expected<void, std::string> String;
     {
         auto e = E();
-        EXPECT_TRUE(e.hasValue());
+        EXPECT_TRUE(e.has_value());
         const auto e2(e);
-        EXPECT_TRUE(e2.hasValue());
+        EXPECT_TRUE(e2.has_value());
         EXPECT_EQ(e, e2);
         E e3;
         e3 = e2;
-        EXPECT_TRUE(e3.hasValue());
+        EXPECT_TRUE(e3.has_value());
         EXPECT_EQ(e, e3);
     }
     {
         constexpr E c;
-        EXPECT_TRUE(c.hasValue());
+        EXPECT_TRUE(c.has_value());
         constexpr const auto c2(c);
-        EXPECT_TRUE(c2.hasValue());
+        EXPECT_TRUE(c2.has_value());
         EXPECT_EQ(c, c2);
     }
     {
         auto u = E(makeUnexpected(oops));
-        EXPECT_FALSE(u.hasValue());
+        EXPECT_FALSE(u.has_value());
         EXPECT_EQ(u.error(), oops);
-        EXPECT_EQ(u.getUnexpected().value(), oops);
     }
     {
         auto uv = EV(makeUnexpected(oops));
-        EXPECT_FALSE(uv.hasValue());
+        EXPECT_FALSE(uv.has_value());
         EXPECT_EQ(uv.error(), oops);
-        EXPECT_EQ(uv.getUnexpected().value(), oops);
     }
     {
         E e = makeUnexpected(oops);
-        EXPECT_FALSE(e.hasValue());
-        EXPECT_EQ(e.error(), oops);
-        EXPECT_EQ(e.getUnexpected().value(), oops);
-    }
-    {
-        auto e = makeExpectedFromError<void, const char*>(oops);
-        EXPECT_FALSE(e.hasValue());
-        EXPECT_EQ(e.error(), oops);
-        EXPECT_EQ(e.getUnexpected().value(), oops);
-    }
-    {
-        auto e = makeExpectedFromError<void, const void*>(oops);
-        EXPECT_FALSE(e.hasValue());
+        EXPECT_FALSE(e.has_value());
         EXPECT_EQ(e.error(), oops);
-        EXPECT_EQ(e.getUnexpected().value(), oops);
     }
     {
         auto e0 = E();
@@ -312,7 +285,7 @@ TEST(WTF_Expected, void)
     }
     {
         typedef Expected<std::pair<int, int>, std::string> Et;
-        EXPECT_EQ(Et(WTF::InPlace, 1, 2), Et(WTF::InPlace, 1, 2));
+        EXPECT_EQ(Et(std::in_place, 1, 2), Et(std::in_place, 1, 2));
     }
 }
 
@@ -465,7 +438,7 @@ TEST(WTF_Expected, Ref)
     {
         RefLogger a("a");
         Expected<Ref<RefLogger>, int> expected = Ref<RefLogger>(a);
-        EXPECT_TRUE(expected.hasValue());
+        EXPECT_TRUE(expected.has_value());
         EXPECT_EQ(&a, expected.value().ptr());
     }
 
@@ -473,8 +446,8 @@ TEST(WTF_Expected, Ref)
 
     {
         RefLogger a("a");
-        Expected<Ref<RefLogger>, int> expected = makeExpected<Ref<RefLogger>, int>(Ref<RefLogger>(a));
-        EXPECT_TRUE(expected.hasValue());
+        Expected<Ref<RefLogger>, int> expected = Expected<Ref<RefLogger>, int>(Ref<RefLogger>(a));
+        EXPECT_TRUE(expected.has_value());
         EXPECT_EQ(&a, expected.value().ptr());
     }
 
@@ -483,7 +456,7 @@ TEST(WTF_Expected, Ref)
     {
         RefLogger a("a");
         Expected<int, Ref<RefLogger>> expected = makeUnexpected(Ref<RefLogger>(a));
-        EXPECT_FALSE(expected.hasValue());
+        EXPECT_FALSE(expected.has_value());
         EXPECT_EQ(&a, expected.error().ptr());
     }
 
@@ -492,7 +465,7 @@ TEST(WTF_Expected, Ref)
     {
         RefLogger a("a");
         Expected<void, Ref<RefLogger>> expected = makeUnexpected(Ref<RefLogger>(a));
-        EXPECT_FALSE(expected.hasValue());
+        EXPECT_FALSE(expected.has_value());
         EXPECT_EQ(&a, expected.error().ptr());
     }
 
index 0f1c02d..418607a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -37,7 +37,7 @@ static int testParseHTMLInteger(const String& input)
 {
     auto optionalResult = parseHTMLInteger(input);
     EXPECT_TRUE(!!optionalResult);
-    return optionalResult.valueOr(0);
+    return optionalResult.value_or(0);
 }
 
 static bool parseHTMLIntegerFails(const String& input)
@@ -101,7 +101,7 @@ static unsigned testParseHTMLNonNegativeInteger(const String& input)
 {
     auto optionalResult = parseHTMLNonNegativeInteger(input);
     EXPECT_TRUE(!!optionalResult);
-    return optionalResult.valueOr(0);
+    return optionalResult.value_or(0);
 }
 
 static bool parseHTMLNonNegativeIntegerFails(const String& input)