Fix problems caught by replacing WTF::Optional with std::optional
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 May 2020 05:46:28 +0000 (05:46 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 May 2020 05:46:28 +0000 (05:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=211703

Reviewed by Chris Dumez.

Source/JavaScriptCore:

* runtime/MachineContext.h:
(JSC::MachineContext::instructionPointer): Use explcit makeOptional here,
to work around the fact that MacroAssemblerCodePtr uses an unusual technique
to disable conversions to everything except bool.

Source/WebCore:

* editing/EditorCommand.cpp:
(WebCore::executeSelectToMark): Remove erroneous code that converts
a live range to a SimpleRange and then back again.

* inspector/agents/InspectorNetworkAgent.cpp:
(WebCore::InspectorNetworkAgent::willSendRequest): Pass a pointer to
a ResourceRequest.
(WebCore::InspectorNetworkAgent::didLoadResourceFromMemoryCache): Ditto.
(WebCore::InspectorNetworkAgent::buildInitiatorObject): Take a const*
to a ResourceRequest instead of an Optional<const ResourceRequest&>
because std::optional does not work with reference types.
* inspector/agents/InspectorNetworkAgent.h: Update for the change above.

* layout/floats/FloatingContext.cpp:
(WebCore::Layout::Iterator::operator++): Fix code that was accidentally
comparing two optionals, after already checking them for null. Instead
we should compare their values.

* platform/PlatformScreen.cpp:
(WebCore::screenData): Return a const* instead of an Optional<const&>
because std::optonal does not work with reference types.
* platform/PlatformScreen.h: Updated for the above. Also removed both
the unneeded include of Optional.h (could have included Forward.h) and
of HashMap.h and put the Mac-specific type IORegistryGPUID inside a
PLATFORM(MAC) #if statement.

* platform/ScreenProperties.h: Moved the HashMap.h include here, since
this is the header that uses it. Changed the EncodedColorSpaceDataType
enum to an enum class and gave it much shorter names.
(WebCore::ScreenData::encode const): Updated for the enum class change.
Also fixed a mistake where the code would use operator<< instead of
encodeEnum for the color space type of Null. This would lead to some
kind of decoding error, rather than a null cgColorSpace.
(WebCore::ScreenData::decode): Ditto.

* platform/ios/PlatformScreenIOS.mm:
(WebCore::screenIsMonochrome): Updated since screenData returns a pointer.
(WebCore::screenHasInvertedColors): Ditto.
(WebCore::screenSupportsExtendedColor): Ditto.
(WebCore::screenSize): Ditto.
(WebCore::availableScreenSize): Ditto.

* platform/mac/PlatformScreenMac.mm: Moved declaration of
CGDisplayUsesForceToGray to CoreGraphicsSPI.h. Removed unused declaration
of CGDisplayUsesInvertedPolarity.
(WebCore::primaryOpenGLDisplayMask): Updated since screendData returns a pointer.
(WebCore::displayMaskForDisplay): Ditto.
(WebCore::gpuIDForDisplay): Ditto.
(WebCore::screenProperties): Ditto. Also renamed from getScreenProperties to
adhere to WebKit coding style.
(WebCore::screenIsMonochrome): Ditto.
(WebCore::screenHasInvertedColors): Ditto.
(WebCore::screenDepth): Ditto.
(WebCore::screenDepthPerComponent): Ditto.
(WebCore::screenRectForDisplay): Ditto.
(WebCore::screenRect): Ditto.
(WebCore::screenAvailableRect): Ditto.
(WebCore::screenColorSpace): Ditto.
(WebCore::screenSupportsExtendedColor): Ditto.
(WebCore::screenSupportsHighDynamicRange): Ditto.

* workers/service/context/ServiceWorkerThread.cpp:
(WebCore::ServiceWorkerThread::queueTaskToFireInstallEvent):
Removed capture of unused jobDataIdentifier.

Source/WebCore/PAL:

* pal/spi/cg/CoreGraphicsSPI.h: Moved definition of CGDisplayUsesForceToGray
here from PlatformScreenMac.mm and also added include of the private header
it's from when compiling with the Apple internal SDK for the additional
checking that we get from using both.

Source/WebKit:

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::plainTextForContext): Clarified ambiguous overload resolution by writing
the conversion from a live range to a SimpleRange out explicitly. Also fixed a typo
where there was a missing "&" in a "const&" argument.

Source/WTF:

* wtf/URLHelpers.cpp:
(WTF::URLHelpers::mapHostName): Make URLDecodeFunction a function
pointer and use nullptr instead of trying to use Optional<> with
a function reference.
(WTF::URLHelpers::collectRangesThatNeedMapping): Ditto.
(WTF::URLHelpers::applyHostNameFunctionToMailToURLString): Ditto.
(WTF::URLHelpers::applyHostNameFunctionToURLString): Ditto.
(WTF::URLHelpers::mapHostNames): Ditto.
(WTF::URLHelpers::userVisibleURL): Ditto.
* wtf/URLHelpers.h: Ditto.

* wtf/cocoa/NSURLExtras.mm:
(WTF::decodeHostName): Pass nullptr for URLDecodeFunction.

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

21 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/MachineContext.h
Source/WTF/ChangeLog
Source/WTF/wtf/URLHelpers.cpp
Source/WTF/wtf/URLHelpers.h
Source/WTF/wtf/cocoa/NSURLExtras.mm
Source/WebCore/ChangeLog
Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h
Source/WebCore/editing/EditorCommand.cpp
Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp
Source/WebCore/inspector/agents/InspectorNetworkAgent.h
Source/WebCore/layout/floats/FloatingContext.cpp
Source/WebCore/platform/PlatformScreen.cpp
Source/WebCore/platform/PlatformScreen.h
Source/WebCore/platform/ScreenProperties.h
Source/WebCore/platform/ios/PlatformScreenIOS.mm
Source/WebCore/platform/mac/PlatformScreenMac.mm
Source/WebCore/workers/service/context/ServiceWorkerThread.cpp
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

index dbb09b1..6ee970e 100644 (file)
@@ -1,3 +1,15 @@
+2020-05-11  Darin Adler  <darin@apple.com>
+
+        Fix problems caught by replacing WTF::Optional with std::optional
+        https://bugs.webkit.org/show_bug.cgi?id=211703
+
+        Reviewed by Chris Dumez.
+
+        * runtime/MachineContext.h:
+        (JSC::MachineContext::instructionPointer): Use explcit makeOptional here,
+        to work around the fact that MacroAssemblerCodePtr uses an unusual technique
+        to disable conversions to everything except bool.
+
 2020-05-11  Yoshiaki JITSUKAWA  <yoshiaki.jitsukawa@sony.com>
 
         Fix build errors after r260992
index c505252..e546633 100644 (file)
@@ -454,11 +454,11 @@ inline Optional<MacroAssemblerCodePtr<PlatformRegistersPCPtrTag>> instructionPoi
     void* value = instructionPointerImpl(const_cast<PlatformRegisters&>(regs));
 #endif
     if (!value)
-        return MacroAssemblerCodePtr<PlatformRegistersPCPtrTag>(nullptr);
+        return makeOptional(MacroAssemblerCodePtr<PlatformRegistersPCPtrTag>(nullptr));
     if (!usesPointerTagging())
-        return MacroAssemblerCodePtr<PlatformRegistersPCPtrTag>(value);
+        return makeOptional(MacroAssemblerCodePtr<PlatformRegistersPCPtrTag>(value));
     if (isTaggedWith(value, PlatformRegistersPCPtrTag))
-        return MacroAssemblerCodePtr<PlatformRegistersPCPtrTag>(value);
+        return makeOptional(MacroAssemblerCodePtr<PlatformRegistersPCPtrTag>(value));
     return WTF::nullopt;
 }
 
index 0a36341..04c8178 100644 (file)
@@ -1,3 +1,24 @@
+2020-05-11  Darin Adler  <darin@apple.com>
+
+        Fix problems caught by replacing WTF::Optional with std::optional
+        https://bugs.webkit.org/show_bug.cgi?id=211703
+
+        Reviewed by Chris Dumez.
+
+        * wtf/URLHelpers.cpp:
+        (WTF::URLHelpers::mapHostName): Make URLDecodeFunction a function
+        pointer and use nullptr instead of trying to use Optional<> with
+        a function reference.
+        (WTF::URLHelpers::collectRangesThatNeedMapping): Ditto.
+        (WTF::URLHelpers::applyHostNameFunctionToMailToURLString): Ditto.
+        (WTF::URLHelpers::applyHostNameFunctionToURLString): Ditto.
+        (WTF::URLHelpers::mapHostNames): Ditto.
+        (WTF::URLHelpers::userVisibleURL): Ditto.
+        * wtf/URLHelpers.h: Ditto.
+
+        * wtf/cocoa/NSURLExtras.mm:
+        (WTF::decodeHostName): Pass nullptr for URLDecodeFunction.
+
 2020-05-11  Yusuke Suzuki  <ysuzuki@apple.com>
 
         AtomString::init should temporarily disable checks via `isMainThread` due to WebThread's inconsistent state
index 36f8089..51c5de0 100644 (file)
@@ -543,7 +543,7 @@ static bool allCharactersAllowedByTLDRules(const UChar* buffer, int32_t length)
 }
 
 // Return value of null means no mapping is necessary.
-Optional<String> mapHostName(const String& hostName, const Optional<URLDecodeFunction>& decodeFunction)
+Optional<String> mapHostName(const String& hostName, URLDecodeFunction decodeFunction)
 {
     if (hostName.length() > hostNameBufferLength)
         return String();
@@ -580,7 +580,7 @@ Optional<String> mapHostName(const String& hostName, const Optional<URLDecodeFun
 
 using MappingRangesVector = Optional<Vector<std::tuple<unsigned, unsigned, String>>>;
 
-static void collectRangesThatNeedMapping(const String& string, unsigned location, unsigned length, MappingRangesVector& array, const Optional<URLDecodeFunction>& decodeFunction)
+static void collectRangesThatNeedMapping(const String& string, unsigned location, unsigned length, MappingRangesVector& array, URLDecodeFunction decodeFunction)
 {
     // Generally, we want to optimize for the case where there is one host name that does not need mapping.
     // Therefore, we use null to indicate no mapping here and an empty array to indicate error.
@@ -598,7 +598,7 @@ static void collectRangesThatNeedMapping(const String& string, unsigned location
         array->constructAndAppend(location, length, *host);
 }
 
-static void applyHostNameFunctionToMailToURLString(const String& string, const Optional<URLDecodeFunction>& decodeFunction, MappingRangesVector& array)
+static void applyHostNameFunctionToMailToURLString(const String& string, URLDecodeFunction decodeFunction, MappingRangesVector& array)
 {
     // In a mailto: URL, host names come after a '@' character and end with a '>' or ',' or '?' character.
     // Skip quoted strings so that characters in them don't confuse us.
@@ -670,7 +670,7 @@ static void applyHostNameFunctionToMailToURLString(const String& string, const O
     }
 }
 
-static void applyHostNameFunctionToURLString(const String& string, const Optional<URLDecodeFunction>& decodeFunction, MappingRangesVector& array)
+static void applyHostNameFunctionToURLString(const String& string, URLDecodeFunction decodeFunction, MappingRangesVector& array)
 {
     // Find hostnames. Too bad we can't use any real URL-parsing code to do this,
     // but we have to do it before doing all the %-escaping, and this is the only
@@ -713,7 +713,7 @@ static void applyHostNameFunctionToURLString(const String& string, const Optiona
     collectRangesThatNeedMapping(string, hostNameStart, hostNameEnd - hostNameStart, array, decodeFunction);
 }
 
-String mapHostNames(const String& string, const Optional<URLDecodeFunction>& decodeFunction)
+String mapHostNames(const String& string, URLDecodeFunction decodeFunction)
 {
     // Generally, we want to optimize for the case where there is one host name that does not need mapping.
     
@@ -869,7 +869,7 @@ String userVisibleURL(const CString& url)
 
     if (mayNeedHostNameDecoding) {
         // FIXME: Is it good to ignore the failure of mapHostNames and keep result intact?
-        auto mappedResult = mapHostNames(result, nullopt);
+        auto mappedResult = mapHostNames(result, nullptr);
         if (!!mappedResult)
             result = mappedResult;
     }
index 73f28d4..0ac0b3d 100644 (file)
 namespace WTF {
 namespace URLHelpers {
 
-using URLDecodeFunction = String(&)(const String&);
+using URLDecodeFunction = String(*)(const String&);
 
 WTF_EXPORT_PRIVATE String userVisibleURL(const CString& URL);
 void loadIDNScriptWhiteList();
 void whiteListIDNScript(const char* scriptName);
 void initializeDefaultIDNScriptWhiteList();
-Optional<String> mapHostName(const String&, const Optional<URLDecodeFunction>&);
-String mapHostNames(const String&, const Optional<URLDecodeFunction>&);
+Optional<String> mapHostName(const String&, URLDecodeFunction);
+String mapHostNames(const String&, URLDecodeFunction);
 
 } // namespace URLHelpers
 } // namespace WTF
index 4631f27..7b64ced 100644 (file)
@@ -102,7 +102,7 @@ static String decodePercentEscapes(const String& string)
 
 NSString *decodeHostName(NSString *string)
 {
-    Optional<String> host = mapHostName(string, nullopt);
+    Optional<String> host = mapHostName(string, nullptr);
     if (!host)
         return nil;
     return !*host ? string : (NSString *)*host;
index fcc440c..3b3b13a 100644 (file)
@@ -1,3 +1,75 @@
+2020-05-11  Darin Adler  <darin@apple.com>
+
+        Fix problems caught by replacing WTF::Optional with std::optional
+        https://bugs.webkit.org/show_bug.cgi?id=211703
+
+        Reviewed by Chris Dumez.
+
+        * editing/EditorCommand.cpp:
+        (WebCore::executeSelectToMark): Remove erroneous code that converts
+        a live range to a SimpleRange and then back again.
+
+        * inspector/agents/InspectorNetworkAgent.cpp:
+        (WebCore::InspectorNetworkAgent::willSendRequest): Pass a pointer to
+        a ResourceRequest.
+        (WebCore::InspectorNetworkAgent::didLoadResourceFromMemoryCache): Ditto.
+        (WebCore::InspectorNetworkAgent::buildInitiatorObject): Take a const*
+        to a ResourceRequest instead of an Optional<const ResourceRequest&>
+        because std::optional does not work with reference types.
+        * inspector/agents/InspectorNetworkAgent.h: Update for the change above.
+
+        * layout/floats/FloatingContext.cpp:
+        (WebCore::Layout::Iterator::operator++): Fix code that was accidentally
+        comparing two optionals, after already checking them for null. Instead
+        we should compare their values.
+
+        * platform/PlatformScreen.cpp:
+        (WebCore::screenData): Return a const* instead of an Optional<const&>
+        because std::optonal does not work with reference types.
+        * platform/PlatformScreen.h: Updated for the above. Also removed both
+        the unneeded include of Optional.h (could have included Forward.h) and
+        of HashMap.h and put the Mac-specific type IORegistryGPUID inside a
+        PLATFORM(MAC) #if statement.
+
+        * platform/ScreenProperties.h: Moved the HashMap.h include here, since
+        this is the header that uses it. Changed the EncodedColorSpaceDataType
+        enum to an enum class and gave it much shorter names.
+        (WebCore::ScreenData::encode const): Updated for the enum class change.
+        Also fixed a mistake where the code would use operator<< instead of
+        encodeEnum for the color space type of Null. This would lead to some
+        kind of decoding error, rather than a null cgColorSpace.
+        (WebCore::ScreenData::decode): Ditto.
+
+        * platform/ios/PlatformScreenIOS.mm:
+        (WebCore::screenIsMonochrome): Updated since screenData returns a pointer.
+        (WebCore::screenHasInvertedColors): Ditto.
+        (WebCore::screenSupportsExtendedColor): Ditto.
+        (WebCore::screenSize): Ditto.
+        (WebCore::availableScreenSize): Ditto.
+
+        * platform/mac/PlatformScreenMac.mm: Moved declaration of
+        CGDisplayUsesForceToGray to CoreGraphicsSPI.h. Removed unused declaration
+        of CGDisplayUsesInvertedPolarity.
+        (WebCore::primaryOpenGLDisplayMask): Updated since screendData returns a pointer.
+        (WebCore::displayMaskForDisplay): Ditto.
+        (WebCore::gpuIDForDisplay): Ditto.
+        (WebCore::screenProperties): Ditto. Also renamed from getScreenProperties to
+        adhere to WebKit coding style.
+        (WebCore::screenIsMonochrome): Ditto.
+        (WebCore::screenHasInvertedColors): Ditto.
+        (WebCore::screenDepth): Ditto.
+        (WebCore::screenDepthPerComponent): Ditto.
+        (WebCore::screenRectForDisplay): Ditto.
+        (WebCore::screenRect): Ditto.
+        (WebCore::screenAvailableRect): Ditto.
+        (WebCore::screenColorSpace): Ditto.
+        (WebCore::screenSupportsExtendedColor): Ditto.
+        (WebCore::screenSupportsHighDynamicRange): Ditto.
+
+        * workers/service/context/ServiceWorkerThread.cpp:
+        (WebCore::ServiceWorkerThread::queueTaskToFireInstallEvent):
+        Removed capture of unused jobDataIdentifier.
+
 2020-05-11  James Darpinian  <jdarpinian@chromium.org>
 
         WebGLLayer clobbers TEXTURE_2D binding on iOS
index f9e5a7c..cebe213 100644 (file)
@@ -1,3 +1,15 @@
+2020-05-11  Darin Adler  <darin@apple.com>
+
+        Fix problems caught by replacing WTF::Optional with std::optional
+        https://bugs.webkit.org/show_bug.cgi?id=211703
+
+        Reviewed by Chris Dumez.
+
+        * pal/spi/cg/CoreGraphicsSPI.h: Moved definition of CGDisplayUsesForceToGray
+        here from PlatformScreenMac.mm and also added include of the private header
+        it's from when compiling with the Apple internal SDK for the additional
+        checking that we get from using both.
+
 2020-05-11  Andres Gonzalez  <andresg_22@apple.com>
 
         Add mechanism to turn on accessibility isolated tree mode from WebKitTestRunner.
index 4a9c5da..08badcf 100644 (file)
 
 #if USE(APPLE_INTERNAL_SDK)
 
-#if PLATFORM(MAC)
-#include <ColorSync/ColorSyncPriv.h>
-#endif
 #include <CoreGraphics/CGFontCache.h>
 #include <CoreGraphics/CGPathPrivate.h>
 #include <CoreGraphics/CoreGraphicsPrivate.h>
 
+#if PLATFORM(MAC)
+#include <ColorSync/ColorSyncPriv.h>
+#include <CoreGraphics/CGAccessibility.h>
+#endif
+
 #else
 
 struct CGFontHMetrics {
@@ -309,6 +311,9 @@ void CGContextSetFocusRingWithColor(CGContextRef, CGFloat blur, CGColorRef, cons
 #endif // PLATFORM(WIN)
 
 #if PLATFORM(MAC)
+
+bool CGDisplayUsesForceToGray(void);
+
 void CGSShutdownServerConnections(void);
 
 CGSConnectionID CGSMainConnectionID(void);
@@ -324,6 +329,7 @@ size_t CGDisplayModeGetPixelsWide(CGDisplayModeRef);
 size_t CGDisplayModeGetPixelsHigh(CGDisplayModeRef);
 
 #if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
+
 CGError CGSSetDenyWindowServerConnections(bool);
 
 typedef int32_t CGSDisplayID;
index 93ae77d..dcf3dce 100644 (file)
@@ -1056,7 +1056,7 @@ static bool executeSelectToMark(Frame& frame, Event*, EditorCommandSource, const
         PAL::systemBeep();
         return false;
     }
-    frame.selection().setSelectedRange(unionDOMRanges(createLiveRange(*mark), createLiveRange(*selection)).get(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes);
+    frame.selection().setSelectedRange(unionDOMRanges(createLiveRange(*mark), *selection).get(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes);
     return true;
 }
 
index 4bdee30..afcdd2a 100644 (file)
@@ -456,7 +456,7 @@ void InspectorNetworkAgent::willSendRequest(unsigned long identifier, DocumentLo
     auto protocolResourceType = InspectorPageAgent::resourceTypeJSON(type);
 
     Document* document = loader && loader->frame() ? loader->frame()->document() : nullptr;
-    auto initiatorObject = buildInitiatorObject(document, request);
+    auto initiatorObject = buildInitiatorObject(document, &request);
 
     String url = loader ? loader->url().string() : request.url().string();
     m_frontendDispatcher->requestWillBeSent(requestId, frameId, loaderId, url, buildObjectForResourceRequest(request), sendTimestamp, walltime.secondsSinceEpoch().seconds(), initiatorObject, buildObjectForResourceResponse(redirectResponse, nullptr), type != InspectorPageAgent::OtherResource ? &protocolResourceType : nullptr, targetId.isEmpty() ? nullptr : &targetId);
@@ -636,7 +636,7 @@ void InspectorNetworkAgent::didLoadResourceFromMemoryCache(DocumentLoader* loade
 
     m_resourcesData->resourceCreated(requestId, loaderId, resource);
 
-    auto initiatorObject = buildInitiatorObject(loader->frame() ? loader->frame()->document() : nullptr, resource.resourceRequest());
+    auto initiatorObject = buildInitiatorObject(loader->frame() ? loader->frame()->document() : nullptr, &resource.resourceRequest());
 
     // FIXME: It would be ideal to generate the Network.Response with the MemoryCache source
     // instead of whatever ResourceResponse::Source the CachedResources's response has.
@@ -706,7 +706,7 @@ void InspectorNetworkAgent::didScheduleStyleRecalculation(Document& document)
         m_styleRecalculationInitiator = buildInitiatorObject(&document);
 }
 
-RefPtr<Inspector::Protocol::Network::Initiator> InspectorNetworkAgent::buildInitiatorObject(Document* document, Optional<const ResourceRequest&> resourceRequest)
+RefPtr<Inspector::Protocol::Network::Initiator> InspectorNetworkAgent::buildInitiatorObject(Document* document, const ResourceRequest* resourceRequest)
 {
     // FIXME: Worker support.
     if (!isMainThread()) {
index b038a18..bfd131e 100644 (file)
@@ -145,7 +145,7 @@ private:
 
     WebSocket* webSocketForRequestId(const String& requestId);
 
-    RefPtr<Inspector::Protocol::Network::Initiator> buildInitiatorObject(Document*, Optional<const ResourceRequest&> = WTF::nullopt);
+    RefPtr<Inspector::Protocol::Network::Initiator> buildInitiatorObject(Document*, const ResourceRequest* = nullptr);
     Ref<Inspector::Protocol::Network::ResourceTiming> buildObjectForTiming(const NetworkLoadMetrics*, ResourceLoader&);
     Ref<Inspector::Protocol::Network::Metrics> buildObjectForMetrics(const NetworkLoadMetrics&);
     RefPtr<Inspector::Protocol::Network::Response> buildObjectForResourceResponse(const ResourceResponse&, ResourceLoader*);
index 2b7edb3..e829f65 100644 (file)
@@ -595,8 +595,8 @@ Iterator& Iterator::operator++()
     auto leftBottom = m_current.left() ? Optional<PositionInContextRoot>(m_current.left()->bottom()) : WTF::nullopt;
     auto rightBottom = m_current.right() ? Optional<PositionInContextRoot>(m_current.right()->bottom()) : WTF::nullopt;
 
-    auto updateLeft = (leftBottom == rightBottom) || (!rightBottom || (leftBottom && leftBottom < rightBottom)); 
-    auto updateRight = (leftBottom == rightBottom) || (!leftBottom || (rightBottom && leftBottom > rightBottom)); 
+    auto updateLeft = (leftBottom == rightBottom) || (!rightBottom || (leftBottom && *leftBottom < *rightBottom));
+    auto updateRight = (leftBottom == rightBottom) || (!leftBottom || (rightBottom && *leftBottom > *rightBottom));
 
     if (updateLeft) {
         ASSERT(m_current.m_floatPair.left);
index cdcd668..9a0d8f5 100644 (file)
@@ -48,21 +48,20 @@ void setScreenProperties(const ScreenProperties& properties)
     screenProperties() = properties;
 }
 
-Optional<const ScreenData&> screenData(PlatformDisplayID screendisplayID)
+const ScreenData* screenData(PlatformDisplayID screenDisplayID)
 {
     if (screenProperties().screenDataMap.isEmpty())
-        return WTF::nullopt;
+        return nullptr;
 
     // Return property of the first screen if the screen is not found in the map.
-    auto displayID = screendisplayID ? screendisplayID : primaryScreenDisplayID();
-    if (displayID) {
-        auto screenPropertiesForDisplay = screenProperties().screenDataMap.find(displayID);
-        if (screenPropertiesForDisplay != screenProperties().screenDataMap.end())
-            return screenPropertiesForDisplay->value;
+    if (auto displayID = screenDisplayID ? screenDisplayID : primaryScreenDisplayID()) {
+        auto properties = screenProperties().screenDataMap.find(displayID);
+        if (properties != screenProperties().screenDataMap.end())
+            return &properties->value;
     }
 
     // Last resort: use the first item in the screen list.
-    return screenProperties().screenDataMap.begin()->value;
+    return &screenProperties().screenDataMap.begin()->value;
 }
 
 } // namespace WebCore
index e35774d..b913add 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006-2018 Apple Inc.  All rights reserved.
+ * Copyright (C) 2006-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 #pragma once
 
-#include <wtf/Optional.h>
-
 #if USE(GLIB)
 #include <wtf/Function.h>
 #endif
 
 #if PLATFORM(MAC)
-#include <wtf/HashMap.h>
-
 OBJC_CLASS NSScreen;
 OBJC_CLASS NSWindow;
 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
@@ -60,13 +56,19 @@ class FloatSize;
 class Widget;
 
 using PlatformDisplayID = uint32_t;
+
+#if PLATFORM(MAC)
+
 using IORegistryGPUID = int64_t; // Global IOKit I/O registryID that can match a GPU across process boundaries.
 
+#endif
+
 int screenDepth(Widget*);
 int screenDepthPerComponent(Widget*);
 bool screenIsMonochrome(Widget*);
 
 bool screenHasInvertedColors();
+
 #if USE(GLIB)
 double screenDPI();
 void setScreenDPIObserverHandler(Function<void()>&&, void*);
@@ -92,10 +94,11 @@ struct ScreenData;
     
 WEBCORE_EXPORT ScreenProperties collectScreenProperties();
 WEBCORE_EXPORT void setScreenProperties(const ScreenProperties&);
-Optional<const ScreenData&> screenData(PlatformDisplayID screendisplayID);
+const ScreenData* screenData(PlatformDisplayID screendisplayID);
 WEBCORE_EXPORT PlatformDisplayID primaryScreenDisplayID();
     
 #if PLATFORM(MAC)
+
 WEBCORE_EXPORT PlatformDisplayID displayID(NSScreen *);
 
 WEBCORE_EXPORT NSScreen *screen(NSWindow *);
index bf42016..16deaf0 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "FloatRect.h"
 #include "PlatformScreen.h"
+#include <wtf/HashMap.h>
 #include <wtf/RetainPtr.h>
 #include <wtf/text/WTFString.h>
 
@@ -48,12 +49,8 @@ struct ScreenData {
     uint32_t displayMask { 0 };
     IORegistryGPUID gpuID { 0 };
 #endif
-    enum EncodedColorSpaceDataType {
-        Null,
-        ColorSpaceName,
-        ColorSpaceData,
-    };
 
+    enum class ColorSpaceType : uint8_t { None, Name, Data };
     template<class Encoder> void encode(Encoder&) const;
     template<class Decoder> static Optional<ScreenData> decode(Decoder&);
 };
@@ -103,25 +100,24 @@ void ScreenData::encode(Encoder& encoder) const
     if (colorSpace) {
         // Try to encode the name.
         if (auto name = adoptCF(CGColorSpaceCopyName(colorSpace.get()))) {
-            encoder.encodeEnum(ColorSpaceName);
+            encoder.encodeEnum(ColorSpaceType::Name);
             encoder << String(name.get());
             return;
         }
 
         // Failing that, just encode the ICC data.
         if (auto profileData = adoptCF(CGColorSpaceCopyICCData(colorSpace.get()))) {
-            encoder.encodeEnum(ColorSpaceData);
-
             Vector<uint8_t> iccData;
             iccData.append(CFDataGetBytePtr(profileData.get()), CFDataGetLength(profileData.get()));
 
+            encoder.encodeEnum(ColorSpaceType::Data);
             encoder << iccData;
             return;
         }
     }
 
     // The color space was null or failed to be encoded.
-    encoder << Null;
+    encoder.encodeEnum(ColorSpaceType::None);
 }
 
 template<class Decoder>
@@ -179,15 +175,15 @@ Optional<ScreenData> ScreenData::decode(Decoder& decoder)
         return WTF::nullopt;
 #endif
 
-    EncodedColorSpaceDataType dataType;
+    ColorSpaceType dataType;
     if (!decoder.decodeEnum(dataType))
         return WTF::nullopt;
 
     RetainPtr<CGColorSpaceRef> cgColorSpace;
     switch (dataType) {
-    case Null:
+    case ColorSpaceType::None:
         break;
-    case ColorSpaceName: {
+    case ColorSpaceType::Name: {
         Optional<String> colorSpaceName;
         decoder >> colorSpaceName;
         ASSERT(colorSpaceName);
@@ -197,7 +193,7 @@ Optional<ScreenData> ScreenData::decode(Decoder& decoder)
         cgColorSpace = adoptCF(CGColorSpaceCreateWithName(colorSpaceName->createCFString().get()));
         break;
     }
-    case ColorSpaceData: {
+    case ColorSpaceType::Data: {
         Optional<Vector<uint8_t>> iccData;
         decoder >> iccData;
         ASSERT(iccData);
index 7ecdd84..2df85f8 100644 (file)
@@ -60,27 +60,24 @@ int screenDepthPerComponent(Widget*)
 
 bool screenIsMonochrome(Widget*)
 {
-    auto v = screenData(primaryScreenDisplayID());
-    if (v.hasValue())
-        return v->screenIsMonochrome;
+    if (auto data = screenData(primaryScreenDisplayID()))
+        return data->screenIsMonochrome;
     
     return PAL::softLinkUIKitUIAccessibilityIsGrayscaleEnabled();
 }
 
 bool screenHasInvertedColors()
 {
-    auto v = screenData(primaryScreenDisplayID());
-    if (v.hasValue())
-        return v->screenHasInvertedColors;
+    if (auto data = screenData(primaryScreenDisplayID()))
+        return data->screenHasInvertedColors;
     
     return PAL::softLinkUIKitUIAccessibilityIsInvertColorsEnabled();
 }
 
 bool screenSupportsExtendedColor(Widget*)
 {
-    auto v = screenData(primaryScreenDisplayID());
-    if (v.hasValue())
-        return v->screenSupportsExtendedColor;
+    if (auto data = screenData(primaryScreenDisplayID()))
+        return data->screenSupportsExtendedColor;
 
     return MGGetBoolAnswer(kMGQHasExtendedColorDisplay);
 }
@@ -155,9 +152,8 @@ FloatSize screenSize()
     if (deviceHasIPadCapability() && [[PAL::getUIApplicationClass() sharedApplication] _isClassic])
         return { 320, 480 };
 
-    auto v = screenData(primaryScreenDisplayID());
-    if (v.hasValue())
-        return v->screenRect.size();
+    if (auto data = screenData(primaryScreenDisplayID()))
+        return data->screenRect.size();
 
     return FloatSize([[PAL::getUIScreenClass() mainScreen] _referenceBounds].size);
 }
@@ -167,9 +163,8 @@ FloatSize availableScreenSize()
     if (deviceHasIPadCapability() && [[PAL::getUIApplicationClass() sharedApplication] _isClassic])
         return { 320, 480 };
 
-    auto v = screenData(primaryScreenDisplayID());
-    if (v.hasValue())
-        return v->screenAvailableRect.size();
+    if (auto data = screenData(primaryScreenDisplayID()))
+        return data->screenAvailableRect.size();
 
     return FloatSize([PAL::getUIScreenClass() mainScreen].bounds.size);
 }
index 59cb7b3..03684e2 100644 (file)
 #import <pal/cocoa/MediaToolboxSoftLink.h>
 #endif
 
-extern "C" {
-bool CGDisplayUsesInvertedPolarity(void);
-bool CGDisplayUsesForceToGray(void);
-}
-
 namespace WebCore {
 
 // These functions scale between screen and page coordinates because JavaScript/DOM operations
@@ -148,18 +143,16 @@ void setShouldOverrideScreenSupportsHighDynamicRange(bool shouldOverride, bool s
 
 uint32_t primaryOpenGLDisplayMask()
 {
-    auto v = screenData(primaryScreenDisplayID());
-    if (v.hasValue())
-        return v->displayMask;
+    if (auto data = screenData(primaryScreenDisplayID()))
+        return data->displayMask;
 
     return 0;
 }
 
 uint32_t displayMaskForDisplay(PlatformDisplayID displayID)
 {
-    auto v = screenData(displayID);
-    if (v.hasValue())
-        return v->displayMask;
+    if (auto data = screenData(displayID))
+        return data->displayMask;
 
     ASSERT_NOT_REACHED();
     return 0;
@@ -173,13 +166,12 @@ IORegistryGPUID primaryGPUID()
 IORegistryGPUID gpuIDForDisplay(PlatformDisplayID displayID)
 {
 #if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
-    auto v = screenData(displayID);
-    if (v.hasValue())
-        return v->gpuID;
+    if (auto data = screenData(displayID))
+        return data->gpuID;
+    return 0;
 #else
     return gpuIDForDisplayMask(CGDisplayIDToOpenGLDisplayMask(displayID));
 #endif
-    return 0;
 }
 
 IORegistryGPUID gpuIDForDisplayMask(GLuint displayMask)
@@ -217,16 +209,15 @@ IORegistryGPUID gpuIDForDisplayMask(GLuint displayMask)
     return (IORegistryGPUID) gpuIDHigh << 32 | gpuIDLow;
 }
 
-static Optional<const ScreenData&> getScreenProperties(Widget* widget)
+static const ScreenData* screenProperties(Widget* widget)
 {
     return screenData(displayID(widget));
 }
 
 bool screenIsMonochrome(Widget* widget)
 {
-    auto v = getScreenProperties(widget);
-    if (v.hasValue())
-        return v->screenIsMonochrome;
+    if (auto data = screenProperties(widget))
+        return data->screenIsMonochrome;
 
     // This is a system-wide accessibility setting, same on all screens.
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
@@ -235,9 +226,8 @@ bool screenIsMonochrome(Widget* widget)
 
 bool screenHasInvertedColors()
 {
-    auto v = screenData(primaryScreenDisplayID());
-    if (v.hasValue())
-        return v->screenHasInvertedColors;
+    if (auto data = screenData(primaryScreenDisplayID()))
+        return data->screenHasInvertedColors;
 
     // This is a system-wide accessibility setting, same on all screens.
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
@@ -246,11 +236,9 @@ bool screenHasInvertedColors()
 
 int screenDepth(Widget* widget)
 {
-    auto v = getScreenProperties(widget);
-    if (v.hasValue()) {
-        auto screenDepth = v->screenDepth;
-        ASSERT(screenDepth);
-        return screenDepth;
+    if (auto data = screenProperties(widget)) {
+        ASSERT(data->screenDepth);
+        return data->screenDepth;
     }
 
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
@@ -259,11 +247,9 @@ int screenDepth(Widget* widget)
 
 int screenDepthPerComponent(Widget* widget)
 {
-    auto v = getScreenProperties(widget);
-    if (v.hasValue()) {
-        auto depthPerComponent = v->screenDepthPerComponent;
-        ASSERT(depthPerComponent);
-        return depthPerComponent;
+    if (auto data = screenProperties(widget)) {
+        ASSERT(data->screenDepthPerComponent);
+        return data->screenDepthPerComponent;
     }
 
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
@@ -272,11 +258,9 @@ int screenDepthPerComponent(Widget* widget)
 
 FloatRect screenRectForDisplay(PlatformDisplayID displayID)
 {
-    auto v = screenData(displayID);
-    if (v.hasValue()) {
-        auto screenRect = v->screenRect;
-        ASSERT(!screenRect.isEmpty());
-        return screenRect;
+    if (auto data = screenData(displayID)) {
+        ASSERT(!data->screenRect.isEmpty());
+        return data->screenRect;
     }
 
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
@@ -290,9 +274,8 @@ FloatRect screenRectForPrimaryScreen()
 
 FloatRect screenRect(Widget* widget)
 {
-    auto v = getScreenProperties(widget);
-    if (v.hasValue())
-        return v->screenRect;
+    if (auto data = screenProperties(widget))
+        return data->screenRect;
 
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
     return toUserSpace([screen(widget) frame], window(widget));
@@ -300,9 +283,8 @@ FloatRect screenRect(Widget* widget)
 
 FloatRect screenAvailableRect(Widget* widget)
 {
-    auto v = getScreenProperties(widget);
-    if (v.hasValue())
-        return v->screenAvailableRect;
+    if (auto data = screenProperties(widget))
+        return data->screenAvailableRect;
 
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
     return toUserSpace([screen(widget) visibleFrame], window(widget));
@@ -326,9 +308,8 @@ NSScreen *screen(PlatformDisplayID displayID)
 
 CGColorSpaceRef screenColorSpace(Widget* widget)
 {
-    auto v = getScreenProperties(widget);
-    if (v.hasValue())
-        return v->colorSpace.get();
+    if (auto data = screenProperties(widget))
+        return data->colorSpace.get();
 
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
     return screen(widget).colorSpace.CGColorSpace;
@@ -336,9 +317,8 @@ CGColorSpaceRef screenColorSpace(Widget* widget)
 
 bool screenSupportsExtendedColor(Widget* widget)
 {
-    auto v = getScreenProperties(widget);
-    if (v.hasValue())
-        return v->screenSupportsExtendedColor;
+    if (auto data = screenProperties(widget))
+        return data->screenSupportsExtendedColor;
 
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
     return [screen(widget) canRepresentDisplayGamut:NSDisplayGamutP3];
@@ -346,9 +326,8 @@ bool screenSupportsExtendedColor(Widget* widget)
 
 bool screenSupportsHighDynamicRange(Widget* widget)
 {
-    auto v = getScreenProperties(widget);
-    if (v.hasValue())
-        return v->screenSupportsHighDynamicRange;
+    if (auto data = screenProperties(widget))
+        return data->screenSupportsHighDynamicRange;
 
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
 #if USE(MEDIATOOLBOX)
index dcb0a4e..3369d30 100644 (file)
@@ -144,11 +144,11 @@ void ServiceWorkerThread::queueTaskToPostMessage(MessageWithMessagePorts&& messa
 void ServiceWorkerThread::queueTaskToFireInstallEvent()
 {
     auto serviceWorkerGlobalScope = makeRef(downcast<ServiceWorkerGlobalScope>(*workerGlobalScope()));
-    serviceWorkerGlobalScope->eventLoop().queueTask(TaskSource::DOMManipulation, [serviceWorkerGlobalScope = serviceWorkerGlobalScope.copyRef(), jobDataIdentifier = m_data.jobDataIdentifier, serviceWorkerIdentifier = this->identifier()] {
+    serviceWorkerGlobalScope->eventLoop().queueTask(TaskSource::DOMManipulation, [serviceWorkerGlobalScope = serviceWorkerGlobalScope.copyRef(), serviceWorkerIdentifier = this->identifier()] {
         auto installEvent = ExtendableEvent::create(eventNames().installEvent, { }, ExtendableEvent::IsTrusted::Yes);
         serviceWorkerGlobalScope->dispatchEvent(installEvent);
 
-        installEvent->whenAllExtendLifetimePromisesAreSettled([jobDataIdentifier, serviceWorkerIdentifier](HashSet<Ref<DOMPromise>>&& extendLifetimePromises) {
+        installEvent->whenAllExtendLifetimePromisesAreSettled([serviceWorkerIdentifier](HashSet<Ref<DOMPromise>>&& extendLifetimePromises) {
             bool hasRejectedAnyPromise = false;
             for (auto& promise : extendLifetimePromises) {
                 if (promise->status() == DOMPromise::Status::Rejected) {
index bb64d29..3447748 100644 (file)
@@ -1,3 +1,15 @@
+2020-05-11  Darin Adler  <darin@apple.com>
+
+        Fix problems caught by replacing WTF::Optional with std::optional
+        https://bugs.webkit.org/show_bug.cgi?id=211703
+
+        Reviewed by Chris Dumez.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::plainTextForContext): Clarified ambiguous overload resolution by writing
+        the conversion from a live range to a SimpleRange out explicitly. Also fixed a typo
+        where there was a missing "&" in a "const&" argument.
+
 2020-05-11  Simon Fraser  <simon.fraser@apple.com>
 
         [ macOS ] scrollingcoordinator/mac/latching/scrolling-select-should-not-latch-mainframe.html is a flaky failure
index ef4d257..e88d487 100644 (file)
@@ -150,14 +150,14 @@ static String plainTextForContext(const SimpleRange& range)
     return WebCore::plainTextReplacingNoBreakSpace(range);
 }
 
-static String plainTextForContext(const Optional<SimpleRange> range)
+static String plainTextForContext(const Optional<SimpleRange>& range)
 {
     return range ? plainTextForContext(*range) : emptyString();
 }
 
 static String plainTextForContext(const Range* range)
 {
-    return range ? plainTextForContext(*range) : emptyString();
+    return range ? plainTextForContext(SimpleRange { *range }) : emptyString();
 }
 
 static String plainTextForDisplay(const SimpleRange& range)