Bug 899894 - Don't null check nsStyleSet::ResolveBlah return values. r=dbaron
authorCameron McCormack <cam@mcc.id.au>
Sat, 03 Aug 2013 14:11:06 +1000
changeset 141253 c732306ad9afd92ec78ee0503b209c5e1923fa3b
parent 141252 5b3ec8bf8bbca03033a924805d8979f44b3f78c3
child 141254 6c032632b9052e652b70eb63224490dedc97d5b6
push id32037
push usercmccormack@mozilla.com
push dateSat, 03 Aug 2013 04:12:04 +0000
treeherdermozilla-inbound@dc5bce83d801 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs899894
milestone25.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 899894 - Don't null check nsStyleSet::ResolveBlah return values. r=dbaron
layout/base/RestyleManager.cpp
layout/base/nsCSSFrameConstructor.cpp
layout/forms/nsComboboxControlFrame.cpp
layout/forms/nsGfxButtonControlFrame.cpp
layout/generic/nsFirstLetterFrame.cpp
layout/generic/nsImageFrame.cpp
layout/mathml/nsMathMLFrame.cpp
layout/style/nsRuleNode.cpp
--- a/layout/base/RestyleManager.cpp
+++ b/layout/base/RestyleManager.cpp
@@ -2261,19 +2261,17 @@ ElementRestyler::RestyleSelf(nsRestyleHi
       TreeMatchContext::AutoFlexItemStyleFixupSkipper
         flexFixupSkipper(mTreeMatchContext,
                          element->IsRootOfNativeAnonymousSubtree());
       newContext = styleSet->ResolveStyleFor(element, parentContext,
                                              mTreeMatchContext);
     }
   }
 
-  if (!newContext) {
-    NS_RUNTIMEABORT("couldn't allocate new style context");
-  }
+  MOZ_ASSERT(newContext);
 
   if (!parentContext) {
     if (oldContext->RuleNode() == newContext->RuleNode() &&
         oldContext->IsLinkContext() == newContext->IsLinkContext() &&
         oldContext->RelevantLinkVisited() ==
           newContext->RelevantLinkVisited()) {
       // We're the root of the style context tree and the new style
       // context returned has the same rule node.  This means that
@@ -2321,22 +2319,23 @@ ElementRestyler::RestyleSelf(nsRestyleHi
       // all.
       NS_ASSERTION(extraPseudoType <
                      nsCSSPseudoElements::ePseudo_PseudoElementCount,
                    "Unexpected type");
       newExtraContext = styleSet->ResolvePseudoElementStyle(mContent->AsElement(),
                                                             extraPseudoType,
                                                             newContext);
     }
-    if (newExtraContext) {
-      if (oldExtraContext != newExtraContext) {
-        CaptureChange(oldExtraContext, newExtraContext, assumeDifferenceHint);
-        if (!(mHintsHandled & nsChangeHint_ReconstructFrame)) {
-          mFrame->SetAdditionalStyleContext(contextIndex, newExtraContext);
-        }
+
+    MOZ_ASSERT(newExtraContext);
+
+    if (oldExtraContext != newExtraContext) {
+      CaptureChange(oldExtraContext, newExtraContext, assumeDifferenceHint);
+      if (!(mHintsHandled & nsChangeHint_ReconstructFrame)) {
+        mFrame->SetAdditionalStyleContext(contextIndex, newExtraContext);
       }
     }
   }
 }
 
 void
 ElementRestyler::RestyleChildren(nsRestyleHint aChildRestyleHint)
 {
@@ -2443,29 +2442,27 @@ ElementRestyler::RestyleUndisplayedChild
                                     mFrame->StyleContext(),
                                     mTreeMatchContext);
       } else {
         undisplayedContext =
           styleSet->ReparentStyleContext(undisplayed->mStyle,
                                          mFrame->StyleContext(),
                                          undisplayed->mContent->AsElement());
       }
-      if (undisplayedContext) {
-        const nsStyleDisplay* display = undisplayedContext->StyleDisplay();
-        if (display->mDisplay != NS_STYLE_DISPLAY_NONE) {
-          NS_ASSERTION(undisplayed->mContent,
-                       "Must have undisplayed content");
-          mChangeList->AppendChange(nullptr, undisplayed->mContent,
-                                    NS_STYLE_HINT_FRAMECHANGE);
-          // The node should be removed from the undisplayed map when
-          // we reframe it.
-        } else {
-          // update the undisplayed node with the new context
-          undisplayed->mStyle = undisplayedContext;
-        }
+      const nsStyleDisplay* display = undisplayedContext->StyleDisplay();
+      if (display->mDisplay != NS_STYLE_DISPLAY_NONE) {
+        NS_ASSERTION(undisplayed->mContent,
+                     "Must have undisplayed content");
+        mChangeList->AppendChange(nullptr, undisplayed->mContent,
+                                  NS_STYLE_HINT_FRAMECHANGE);
+        // The node should be removed from the undisplayed map when
+        // we reframe it.
+      } else {
+        // update the undisplayed node with the new context
+        undisplayed->mStyle = undisplayedContext;
       }
     }
   }
 }
 
 void
 ElementRestyler::RestyleBeforePseudo()
 {
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -2189,19 +2189,16 @@ nsCSSFrameConstructor::PropagateScrollTo
   }
 
   Element* docElement = mDocument->GetRootElement();
 
   // Check the style on the document root element
   nsStyleSet *styleSet = mPresShell->StyleSet();
   nsRefPtr<nsStyleContext> rootStyle;
   rootStyle = styleSet->ResolveStyleFor(docElement, nullptr);
-  if (!rootStyle) {
-    return nullptr;
-  }
   if (CheckOverflow(presContext, rootStyle->StyleDisplay())) {
     // tell caller we stole the overflow style from the root element
     return docElement;
   }
   
   // Don't look in the BODY for non-HTML documents or HTML documents
   // with non-HTML roots
   // XXX this should be earlier; we shouldn't even look at the document root
@@ -2220,19 +2217,16 @@ nsCSSFrameConstructor::PropagateScrollTo
   if (!bodyElement ||
       !bodyElement->NodeInfo()->Equals(nsGkAtoms::body)) {
     // The body is not a <body> tag, it's a <frameset>.
     return nullptr;
   }
 
   nsRefPtr<nsStyleContext> bodyStyle;
   bodyStyle = styleSet->ResolveStyleFor(bodyElement->AsElement(), rootStyle);
-  if (!bodyStyle) {
-    return nullptr;
-  }
 
   if (CheckOverflow(presContext, bodyStyle->StyleDisplay())) {
     // tell caller we stole the overflow style from the body element
     return bodyElement;
   }
 
   return nullptr;
 }
@@ -5830,17 +5824,16 @@ nsCSSFrameConstructor::IsValidSibling(ns
       nsIFrame* styleParent = aSibling->GetParentStyleContextFrame();
       if (!styleParent) {
         NS_NOTREACHED("Shouldn't happen");
         return false;
       }
       // XXXbz when this code is killed, the state argument to
       // ResolveStyleContext can be made non-optional.
       styleContext = ResolveStyleContext(styleParent, aContent, nullptr);
-      if (!styleContext) return false;
       const nsStyleDisplay* display = styleContext->StyleDisplay();
       aDisplay = display->mDisplay;
     }
     if (nsGkAtoms::menuFrame == parentType) {
       return
         (NS_STYLE_DISPLAY_POPUP == aDisplay) ==
         (NS_STYLE_DISPLAY_POPUP == siblingDisplay);
     }
@@ -9601,19 +9594,17 @@ nsCSSFrameConstructor::CreateFloatingLet
     // Create continuation
     nextTextFrame =
       CreateContinuingFrame(aState.mPresContext, aTextFrame, aParentFrame);
     // Repair the continuations style context
     nsStyleContext* parentStyleContext = aStyleContext->GetParent();
     if (parentStyleContext) {
       nsRefPtr<nsStyleContext> newSC;
       newSC = styleSet->ResolveStyleForNonElement(parentStyleContext);
-      if (newSC) {
-        nextTextFrame->SetStyleContext(newSC);
-      }
+      nextTextFrame->SetStyleContext(newSC);
     }
   }
 
   NS_ASSERTION(aResult.IsEmpty(), "aResult should be an empty nsFrameItems!");
   // Put the new float before any of the floats in the block we're doing
   // first-letter for, that is, before any floats whose parent is
   // containingBlock.
   nsFrameList::FrameLinkEnumerator link(aState.mFloatedItems);
@@ -9851,19 +9842,16 @@ nsCSSFrameConstructor::RemoveFloatingFir
   // (and probably continued elsewhere).
   nsStyleContext* parentSC = parentFrame->StyleContext();
   nsIContent* textContent = textFrame->GetContent();
   if (!textContent) {
     return NS_OK;
   }
   nsRefPtr<nsStyleContext> newSC;
   newSC = aPresShell->StyleSet()->ResolveStyleForNonElement(parentSC);
-  if (!newSC) {
-    return NS_OK;
-  }
   nsIFrame* newTextFrame = NS_NewTextFrame(aPresShell, newSC);
   newTextFrame->Init(textContent, parentFrame, nullptr);
 
   // Destroy the old text frame's continuations (the old text frame
   // will be destroyed when its letter frame is destroyed).
   nsIFrame* frameToDelete = textFrame->GetLastContinuation();
   while (frameToDelete != textFrame) {
     nsIFrame* nextFrameToDelete = frameToDelete->GetPrevContinuation();
@@ -9922,19 +9910,16 @@ nsCSSFrameConstructor::RemoveFirstLetter
         break;
       }
       nsIContent* textContent = textFrame->GetContent();
       if (!textContent) {
         break;
       }
       nsRefPtr<nsStyleContext> newSC;
       newSC = aPresShell->StyleSet()->ResolveStyleForNonElement(parentSC);
-      if (!newSC) {
-        break;
-      }
       textFrame = NS_NewTextFrame(aPresShell, newSC);
       textFrame->Init(textContent, aFrame, nullptr);
 
       // Next rip out the kid and replace it with the text frame
       RemoveFrame(kPrincipalList, kid);
 
       // Now that the old frames are gone, we can start pointing to our
       // new primary frame.
--- a/layout/forms/nsComboboxControlFrame.cpp
+++ b/layout/forms/nsComboboxControlFrame.cpp
@@ -1321,25 +1321,19 @@ nsComboboxControlFrame::CreateFrameFor(n
   nsIPresShell *shell = PresContext()->PresShell();
   nsStyleSet *styleSet = shell->StyleSet();
 
   // create the style contexts for the anonymous block frame and text frame
   nsRefPtr<nsStyleContext> styleContext;
   styleContext = styleSet->
     ResolveAnonymousBoxStyle(nsCSSAnonBoxes::mozDisplayComboboxControlFrame,
                              mStyleContext);
-  if (MOZ_UNLIKELY(!styleContext)) {
-    return nullptr;
-  }
 
   nsRefPtr<nsStyleContext> textStyleContext;
   textStyleContext = styleSet->ResolveStyleForNonElement(mStyleContext);
-  if (MOZ_UNLIKELY(!textStyleContext)) {
-    return nullptr;
-  }
 
   // Start by by creating our anonymous block frame
   mDisplayFrame = new (shell) nsComboboxDisplayFrame(styleContext, this);
   if (MOZ_UNLIKELY(!mDisplayFrame)) {
     return nullptr;
   }
 
   mDisplayFrame->Init(mContent, this, nullptr);
--- a/layout/forms/nsGfxButtonControlFrame.cpp
+++ b/layout/forms/nsGfxButtonControlFrame.cpp
@@ -94,23 +94,21 @@ nsGfxButtonControlFrame::CreateFrameFor(
   if (aContent == mTextContent) {
     nsIFrame * parentFrame = mFrames.FirstChild();
 
     nsPresContext* presContext = PresContext();
     nsRefPtr<nsStyleContext> textStyleContext;
     textStyleContext = presContext->StyleSet()->
       ResolveStyleForNonElement(mStyleContext);
 
-    if (textStyleContext) {
-      newFrame = NS_NewTextFrame(presContext->PresShell(), textStyleContext);
-      if (newFrame) {
-        // initialize the text frame
-        newFrame->Init(mTextContent, parentFrame, nullptr);
-        mTextContent->SetPrimaryFrame(newFrame);
-      }
+    newFrame = NS_NewTextFrame(presContext->PresShell(), textStyleContext);
+    if (newFrame) {
+      // initialize the text frame
+      newFrame->Init(mTextContent, parentFrame, nullptr);
+      mTextContent->SetPrimaryFrame(newFrame);
     }
   }
 
   return newFrame;
 }
 
 NS_QUERYFRAME_HEAD(nsGfxButtonControlFrame)
   NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
--- a/layout/generic/nsFirstLetterFrame.cpp
+++ b/layout/generic/nsFirstLetterFrame.cpp
@@ -65,18 +65,17 @@ nsFirstLetterFrame::Init(nsIContent*    
   if (aPrevInFlow) {
     // Get proper style context for ourselves.  We're creating the frame
     // that represents everything *except* the first letter, so just create
     // a style context like we would for a text node.
     nsStyleContext* parentStyleContext = mStyleContext->GetParent();
     if (parentStyleContext) {
       newSC = PresContext()->StyleSet()->
         ResolveStyleForNonElement(parentStyleContext);
-      if (newSC)
-        SetStyleContextWithoutNotification(newSC);
+      SetStyleContextWithoutNotification(newSC);
     }
   }
 
   nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
 }
 
 NS_IMETHODIMP
 nsFirstLetterFrame::SetInitialChildList(ChildListID  aListID,
@@ -323,19 +322,17 @@ nsFirstLetterFrame::CreateContinuationFo
 
   // The continuation will have gotten the first letter style from it's
   // prev continuation, so we need to repair the style context so it
   // doesn't have the first letter styling.
   nsStyleContext* parentSC = this->StyleContext()->GetParent();
   if (parentSC) {
     nsRefPtr<nsStyleContext> newSC;
     newSC = presShell->StyleSet()->ResolveStyleForNonElement(parentSC);
-    if (newSC) {
-      continuation->SetStyleContext(newSC);
-    }
+    continuation->SetStyleContext(newSC);
   }
 
   //XXX Bidi may not be involved but we have to use the list name
   // kNoReflowPrincipalList because this is just like creating a continuation
   // except we have to insert it in a different place and we don't want a
   // reflow command to try to be issued.
   nsFrameList temp(continuation, continuation);
   rv = parent->InsertFrames(kNoReflowPrincipalList, placeholderFrame, temp);
@@ -376,19 +373,17 @@ nsFirstLetterFrame::DrainOverflowFrames(
   nsIFrame* kid = mFrames.FirstChild();
   if (kid) {
     nsRefPtr<nsStyleContext> sc;
     nsIContent* kidContent = kid->GetContent();
     if (kidContent) {
       NS_ASSERTION(kidContent->IsNodeOfType(nsINode::eTEXT),
                    "should contain only text nodes");
       sc = aPresContext->StyleSet()->ResolveStyleForNonElement(mStyleContext);
-      if (sc) {
-        kid->SetStyleContext(sc);
-      }
+      kid->SetStyleContext(sc);
     }
   }
 }
 
 nscoord
 nsFirstLetterFrame::GetBaseline() const
 {
   return mBaseline;
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -1696,24 +1696,22 @@ nsImageFrame::GetCursor(const nsPoint& a
       // Use the cursor from the style of the *area* element.
       // XXX Using the image as the parent style context isn't
       // technically correct, but it's probably the right thing to do
       // here, since it means that areas on which the cursor isn't
       // specified will inherit the style from the image.
       nsRefPtr<nsStyleContext> areaStyle = 
         PresContext()->PresShell()->StyleSet()->
           ResolveStyleFor(area->AsElement(), StyleContext());
-      if (areaStyle) {
-        FillCursorInformationFromStyle(areaStyle->StyleUserInterface(),
-                                       aCursor);
-        if (NS_STYLE_CURSOR_AUTO == aCursor.mCursor) {
-          aCursor.mCursor = NS_STYLE_CURSOR_DEFAULT;
-        }
-        return NS_OK;
+      FillCursorInformationFromStyle(areaStyle->StyleUserInterface(),
+                                     aCursor);
+      if (NS_STYLE_CURSOR_AUTO == aCursor.mCursor) {
+        aCursor.mCursor = NS_STYLE_CURSOR_DEFAULT;
       }
+      return NS_OK;
     }
   }
   return nsFrame::GetCursor(aPoint, aCursor);
 }
 
 NS_IMETHODIMP
 nsImageFrame::AttributeChanged(int32_t aNameSpaceID,
                                nsIAtom* aAttribute,
--- a/layout/mathml/nsMathMLFrame.cpp
+++ b/layout/mathml/nsMathMLFrame.cpp
@@ -128,18 +128,17 @@ nsMathMLFrame::ResolveMathMLCharStyle(ns
   nsCSSPseudoElements::Type pseudoType = (aIsMutableChar) ?
     nsCSSPseudoElements::ePseudo_mozMathStretchy :
     nsCSSPseudoElements::ePseudo_mozMathAnonymous; // savings
   nsRefPtr<nsStyleContext> newStyleContext;
   newStyleContext = aPresContext->StyleSet()->
     ResolvePseudoElementStyle(aContent->AsElement(), pseudoType,
                               aParentStyleContext);
 
-  if (newStyleContext)
-    aMathMLChar->SetStyleContext(newStyleContext);
+  aMathMLChar->SetStyleContext(newStyleContext);
 }
 
 /* static */ void
 nsMathMLFrame::GetEmbellishDataFrom(nsIFrame*        aFrame,
                                     nsEmbellishData& aEmbellishData)
 {
   // initialize OUT params
   aEmbellishData.flags = 0;
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -382,19 +382,17 @@ static nscoord CalcLengthWith(const nsCS
         // than font size, so rem is relative to the root element's font size.
         nsRefPtr<nsStyleContext> rootStyle;
         const nsStyleFont *rootStyleFont = styleFont;
         Element* docElement = aPresContext->Document()->GetRootElement();
 
         if (docElement) {
           rootStyle = aPresContext->StyleSet()->ResolveStyleFor(docElement,
                                                                 nullptr);
-          if (rootStyle) {
-            rootStyleFont = rootStyle->StyleFont();
-          }
+          rootStyleFont = rootStyle->StyleFont();
         }
 
         rootFontSize = rootStyleFont->mFont.size;
       }
 
       return ScaleCoord(aValue, float(rootFontSize));
     }
     default: