Bug 1513332, add some null-pointer checks on elements in XULListboxAccessible, r=marcoz
☠☠ backed out by 303797fd3722 ☠ ☠
authorNeil Deakin <neil@mozilla.com>
Mon, 17 Dec 2018 15:43:51 -0500
changeset 508152 003adae62f33b0425e68c6aafa3c255fc8611c06
parent 508151 015d0bde6d9047c668d579fbfb30e468627dd573
child 508153 648648a60190278663379270879e053c9d767f70
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarcoz
bugs1513332
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1513332, add some null-pointer checks on elements in XULListboxAccessible, r=marcoz
accessible/xul/XULListboxAccessible.cpp
--- a/accessible/xul/XULListboxAccessible.cpp
+++ b/accessible/xul/XULListboxAccessible.cpp
@@ -106,19 +106,23 @@ uint64_t XULListboxAccessible::NativeSta
 void XULListboxAccessible::Value(nsString& aValue) const {
   aValue.Truncate();
 
   nsCOMPtr<nsIDOMXULSelectControlElement> select = Elm()->AsXULSelectControl();
   if (select) {
     RefPtr<Element> element;
     select->GetSelectedItem(getter_AddRefs(element));
 
-    nsCOMPtr<nsIDOMXULSelectControlItemElement> selectedItem =
-        element->AsXULSelectControlItem();
-    if (selectedItem) selectedItem->GetLabel(aValue);
+    if (element) {
+      nsCOMPtr<nsIDOMXULSelectControlItemElement> selectedItem =
+          element->AsXULSelectControlItem();
+      if (selectedItem) {
+        selectedItem->GetLabel(aValue);
+      }
+    }
   }
 }
 
 role XULListboxAccessible::NativeRole() const {
   // A richlistbox is used with the new autocomplete URL bar, and has a parent
   // popup <panel>.
   if (mContent->GetParent() &&
       mContent->GetParent()->IsXULElement(nsGkAtoms::panel))
@@ -171,16 +175,19 @@ bool XULListboxAccessible::IsColSelected
 
 bool XULListboxAccessible::IsRowSelected(uint32_t aRowIdx) {
   nsCOMPtr<nsIDOMXULSelectControlElement> control = Elm()->AsXULSelectControl();
   NS_ASSERTION(control, "Doesn't implement nsIDOMXULSelectControlElement.");
 
   RefPtr<Element> element;
   nsresult rv = control->GetItemAtIndex(aRowIdx, getter_AddRefs(element));
   NS_ENSURE_SUCCESS(rv, false);
+  if (!element) {
+    return false;
+  }
 
   nsCOMPtr<nsIDOMXULSelectControlItemElement> item =
       element->AsXULSelectControlItem();
 
   bool isSelected = false;
   item->GetSelected(&isSelected);
   return isSelected;
 }
@@ -332,30 +339,36 @@ void XULListboxAccessible::SelectedRowIn
 void XULListboxAccessible::SelectRow(uint32_t aRowIdx) {
   nsCOMPtr<nsIDOMXULMultiSelectControlElement> control =
       Elm()->AsXULMultiSelectControl();
   NS_ASSERTION(control,
                "Doesn't implement nsIDOMXULMultiSelectControlElement.");
 
   RefPtr<Element> item;
   control->GetItemAtIndex(aRowIdx, getter_AddRefs(item));
+  if (!item) {
+    return;
+  }
 
   nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm =
       item->AsXULSelectControlItem();
   control->SelectItem(itemElm);
 }
 
 void XULListboxAccessible::UnselectRow(uint32_t aRowIdx) {
   nsCOMPtr<nsIDOMXULMultiSelectControlElement> control =
       Elm()->AsXULMultiSelectControl();
   NS_ASSERTION(control,
                "Doesn't implement nsIDOMXULMultiSelectControlElement.");
 
   RefPtr<Element> item;
   control->GetItemAtIndex(aRowIdx, getter_AddRefs(item));
+  if (!item) {
+    return;
+  }
 
   nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm =
       item->AsXULSelectControlItem();
   control->RemoveItemFromSelection(itemElm);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // XULListboxAccessible: Widgets