Bug 1154183 part.5 Make nsXBLWindowKeyHandler::GetElementForHandler() use early return style r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 19 Mar 2016 23:12:39 +0900
changeset 290010 b0733a06e7f14481ced69b8e3690d79ba7a2c88a
parent 290009 6c650c359c8e65904805108b1996a56f08c2a372
child 290011 a12f5a5fff6789823af34028da2d4a6bb62b2e70
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1154183
milestone48.0a1
Bug 1154183 part.5 Make nsXBLWindowKeyHandler::GetElementForHandler() use early return style r=smaug MozReview-Commit-ID: CezO0rZBOEl
dom/xbl/nsXBLWindowKeyHandler.cpp
--- a/dom/xbl/nsXBLWindowKeyHandler.cpp
+++ b/dom/xbl/nsXBLWindowKeyHandler.cpp
@@ -700,48 +700,54 @@ nsXBLWindowKeyHandler::GetElement(bool* 
 bool
 nsXBLWindowKeyHandler::GetElementForHandler(nsXBLPrototypeHandler* aHandler,
                                             Element** aElementForHandler)
 {
   MOZ_ASSERT(aElementForHandler);
   *aElementForHandler = nullptr;
 
   nsCOMPtr<nsIContent> keyContent = aHandler->GetHandlerElement();
+  if (!keyContent) {
+    return true; // XXX Even though no key element?
+  }
 
-  // See if we're in a XUL doc.
   nsCOMPtr<Element> chromeHandlerElement = GetElement();
-  if (chromeHandlerElement && keyContent) {
-    // We are.  Obtain our command attribute.
-    nsAutoString command;
-    keyContent->GetAttr(kNameSpaceID_None, nsGkAtoms::command, command);
-    if (!command.IsEmpty()) {
-      // Locate the command element in question.  Note that we
-      // know "keyContent" is in a doc if we're dealing with it here.
-      NS_ASSERTION(keyContent->IsInDoc(),
-                   "the key element must be in document");
-      nsIDocument* doc = keyContent->GetCurrentDoc();
-      if (NS_WARN_IF(!doc)) {
-        return false;
-      }
-      nsCOMPtr<Element> commandElement =
-        do_QueryInterface(doc->GetElementById(command));
-      if (!commandElement) {
-        NS_ERROR("A XUL <key> is observing a command that doesn't exist. "
-                 "Unable to execute key binding!");
-        return false;
-      }
-      commandElement.swap(*aElementForHandler);
-    }
+  if (!chromeHandlerElement) {
+    NS_WARN_IF(!keyContent->IsInDoc());
+    nsCOMPtr<Element> keyElement = do_QueryInterface(keyContent);
+    keyElement.swap(*aElementForHandler);
+    return true;
   }
 
-  if (!*aElementForHandler) {
+  // We are in a XUL doc.  Obtain our command attribute.
+  nsAutoString command;
+  keyContent->GetAttr(kNameSpaceID_None, nsGkAtoms::command, command);
+  if (command.IsEmpty()) {
+    // There is no command element associated with the key element.
+    NS_WARN_IF(!keyContent->IsInDoc());
     nsCOMPtr<Element> keyElement = do_QueryInterface(keyContent);
     keyElement.swap(*aElementForHandler);
+    return true;
+  }
+
+  // XXX Shouldn't we check this earlier?
+  nsIDocument* doc = keyContent->GetCurrentDoc();
+  if (NS_WARN_IF(!doc)) {
+    return false;
   }
 
+  nsCOMPtr<Element> commandElement =
+    do_QueryInterface(doc->GetElementById(command));
+  if (!commandElement) {
+    NS_ERROR("A XUL <key> is observing a command that doesn't exist. "
+             "Unable to execute key binding!");
+    return false;
+  }
+
+  commandElement.swap(*aElementForHandler);
   return true;
 }
 
 ///////////////////////////////////////////////////////////////////////////////////
 
 already_AddRefed<nsXBLWindowKeyHandler>
 NS_NewXBLWindowKeyHandler(nsIDOMElement* aElement, EventTarget* aTarget)
 {