protect against exception being thrown when trying to remove a native menu item from a menu it isn't in. b=420640 r=smichaud sr=roc
authorjoshmoz@gmail.com
Tue, 04 Mar 2008 00:11:29 -0800
changeset 12537 164c5b3f4bfe6dcf1cc2c24b40fce3482438cf03
parent 12536 0e2909026df1119e0a9ff955ef6e79193010e971
child 12538 ca9734086a62ccf9b9da3489175a026c35f9996d
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherdermozilla-central@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmichaud, roc
bugs420640
milestone1.9b5pre
protect against exception being thrown when trying to remove a native menu item from a menu it isn't in. b=420640 r=smichaud sr=roc
widget/src/cocoa/nsMenuX.mm
--- a/widget/src/cocoa/nsMenuX.mm
+++ b/widget/src/cocoa/nsMenuX.mm
@@ -1041,17 +1041,20 @@ nsMenuX::ObserveAttributeChanged(nsIDocu
     if (contentIsHiddenOrCollapsed) {
       void *clientData = nsnull;
       if (menubarParent)
         menubarParent->GetNativeData(clientData);
       else if (menuParent)
         menuParent->GetNativeData(&clientData);
       if (clientData) {
         NSMenu* parentMenu = reinterpret_cast<NSMenu*>(clientData);
-        [parentMenu removeItem:mNativeMenuItem];
+        // An exception will get thrown if we try to remove an item that isn't
+        // in the menu.
+        if ([parentMenu indexOfItem:mNativeMenuItem] != -1)
+          [parentMenu removeItem:mNativeMenuItem];
         mVisible = PR_FALSE;
       }
     }
     else {
       PRUint32 insertAfter = 0;
       if (NS_SUCCEEDED(CountVisibleBefore(&insertAfter))) {
         void *clientData = nsnull;
         if (menubarParent)