Bug 1256419. Null-check our nsDOMWindowList before trying to get its length. r=smaug, a=ritu
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 16 Mar 2016 12:40:56 -0400
changeset 325449 dcc8b840bd8fe08b527a48fbfc4815eaa534fc88
parent 325448 ed6b7b0935413172df2267cf86007aefac058871
child 325450 20bc3ca96c291494b9cf128fa8680bc84d9a9d53
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, ritu
bugs1256419
milestone47.0a2
Bug 1256419. Null-check our nsDOMWindowList before trying to get its length. r=smaug, a=ritu
dom/base/WindowNamedPropertiesHandler.cpp
--- a/dom/base/WindowNamedPropertiesHandler.cpp
+++ b/dom/base/WindowNamedPropertiesHandler.cpp
@@ -175,32 +175,34 @@ WindowNamedPropertiesHandler::ownPropNam
 
   // Grab the DOM window.
   nsGlobalWindow* win = xpc::WindowOrNull(JS_GetGlobalForObject(aCx, aProxy));
   nsTArray<nsString> names;
   // The names live on the outer window, which might be null
   nsGlobalWindow* outer = win->GetOuterWindowInternal();
   if (outer) {
     nsDOMWindowList* childWindows = outer->GetWindowList();
-    uint32_t length = childWindows->GetLength();
-    for (uint32_t i = 0; i < length; ++i) {
-      nsCOMPtr<nsIDocShellTreeItem> item =
-        childWindows->GetDocShellTreeItemAt(i);
-      // This is a bit silly, since we could presumably just do
-      // item->GetWindow().  But it's not obvious whether this does the same
-      // thing as GetChildWindow() with the item's name (due to the complexity
-      // of FindChildWithName).  Since GetChildWindow is what we use in
-      // getOwnPropDescriptor, let's try to be consistent.
-      nsString name;
-      item->GetName(name);
-      if (!names.Contains(name)) {
-        // Make sure we really would expose it from getOwnPropDescriptor.
-        nsCOMPtr<nsPIDOMWindowOuter> childWin = win->GetChildWindow(name);
-        if (childWin && ShouldExposeChildWindow(name, childWin)) {
-          names.AppendElement(name);
+    if (childWindows) {
+      uint32_t length = childWindows->GetLength();
+      for (uint32_t i = 0; i < length; ++i) {
+        nsCOMPtr<nsIDocShellTreeItem> item =
+          childWindows->GetDocShellTreeItemAt(i);
+        // This is a bit silly, since we could presumably just do
+        // item->GetWindow().  But it's not obvious whether this does the same
+        // thing as GetChildWindow() with the item's name (due to the complexity
+        // of FindChildWithName).  Since GetChildWindow is what we use in
+        // getOwnPropDescriptor, let's try to be consistent.
+        nsString name;
+        item->GetName(name);
+        if (!names.Contains(name)) {
+          // Make sure we really would expose it from getOwnPropDescriptor.
+          nsCOMPtr<nsPIDOMWindowOuter> childWin = win->GetChildWindow(name);
+          if (childWin && ShouldExposeChildWindow(name, childWin)) {
+            names.AppendElement(name);
+          }
         }
       }
     }
   }
   if (!AppendNamedPropertyIds(aCx, aProxy, names, false, aProps)) {
     return false;
   }