Streamline test-and-clear operation for ContextMenu
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 May 2019 21:28:06 +0000 (21:28 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 May 2019 21:28:06 +0000 (21:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=197795
<rdar://problem/50473746>

Reviewed by Wenson Hsieh.

Rather than performing a check when entering the function, doing work,
then clearing the member variable, perform the check and clear in
a single operation. Only perform the selection if the menu exists.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::didSelectItemFromActiveContextMenu):

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

Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebPage/WebPage.cpp

index ac08c1b..a40a2d4 100644 (file)
@@ -1,3 +1,18 @@
+2019-05-10  Brent Fulgham  <bfulgham@apple.com>
+
+        Streamline test-and-clear operation for ContextMenu
+        https://bugs.webkit.org/show_bug.cgi?id=197795
+        <rdar://problem/50473746>
+
+        Reviewed by Wenson Hsieh.
+
+        Rather than performing a check when entering the function, doing work,
+        then clearing the member variable, perform the check and clear in
+        a single operation. Only perform the selection if the menu exists.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::didSelectItemFromActiveContextMenu):
+
 2019-05-10  Megan Gardner  <megan_gardner@apple.com>
 
         Returning incorrect marked text rects
index 8af7315..0104e00 100644 (file)
@@ -4236,11 +4236,8 @@ void WebPage::failedToShowPopupMenu()
 #if ENABLE(CONTEXT_MENUS)
 void WebPage::didSelectItemFromActiveContextMenu(const WebContextMenuItemData& item)
 {
-    if (!m_contextMenu)
-        return;
-
-    m_contextMenu->itemSelected(item);
-    m_contextMenu = nullptr;
+    if (auto contextMenu = std::exchange(m_contextMenu, nullptr))
+        contextMenu->itemSelected(item);
 }
 #endif