Bug 654369 - Part 9: Remove OOM checks from layout/generic r=bz
authorCraig Topper <craig.topper@gmail.com>
Thu, 28 Apr 2011 22:02:16 -0700
changeset 71799 acec89b9786bb24df059210436ff7db4ab1e1cf7
parent 71798 605c1bfa4ad2b2101c22bf24ee474b30bc488817
child 71800 8027b37a9b32c6df9f729fcb99c9fad5f0e75852
push idunknown
push userunknown
push dateunknown
reviewersbz
bugs654369
milestone7.0a1
Bug 654369 - Part 9: Remove OOM checks from layout/generic r=bz
layout/generic/nsAutoCopyListener.h
layout/generic/nsBlockReflowContext.cpp
layout/generic/nsFrame.cpp
layout/generic/nsFrameUtil.cpp
layout/generic/nsGfxScrollFrame.cpp
layout/generic/nsImageFrame.cpp
layout/generic/nsLineBox.cpp
layout/generic/nsObjectFrame.cpp
layout/generic/nsSelection.cpp
--- a/layout/generic/nsAutoCopyListener.h
+++ b/layout/generic/nsAutoCopyListener.h
@@ -52,18 +52,16 @@ public:
       NS_ASSERTION(aSelection, "Null selection passed to Listen()");
       aSelection->AddSelectionListener(this);
   }
 
   static nsAutoCopyListener* GetInstance()
   {
     if (!sInstance) {
       sInstance = new nsAutoCopyListener();
-      if (!sInstance)
-        return nsnull;
 
       NS_ADDREF(sInstance);
     }
 
     return sInstance;
   }
 
   static void Shutdown()
--- a/layout/generic/nsBlockReflowContext.cpp
+++ b/layout/generic/nsBlockReflowContext.cpp
@@ -168,18 +168,16 @@ nsBlockReflowContext::ComputeCollapsedTo
             // one extra reflow state.
             const nsHTMLReflowState* outerReflowState = &aRS;
             if (frame != aRS.frame) {
               NS_ASSERTION(frame->GetParent() == aRS.frame,
                            "Can only drill through one level of block wrapper");
               nsSize availSpace(aRS.ComputedWidth(), aRS.ComputedHeight());
               outerReflowState = new nsHTMLReflowState(prescontext,
                                                        aRS, frame, availSpace);
-              if (!outerReflowState)
-                goto done;
             }
             {
               nsSize availSpace(outerReflowState->ComputedWidth(),
                                 outerReflowState->ComputedHeight());
               nsHTMLReflowState innerReflowState(prescontext,
                                                  *outerReflowState, kid,
                                                  availSpace);
               // Record that we're being optimistic by assuming the kid
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -1885,17 +1885,17 @@ nsFrame::GetContentForEvent(nsPresContex
 void
 nsFrame::FireDOMEvent(const nsAString& aDOMEventName, nsIContent *aContent)
 {
   nsIContent* target = aContent ? aContent : mContent;
 
   if (target) {
     nsRefPtr<nsPLDOMEvent> event =
       new nsPLDOMEvent(target, aDOMEventName, PR_TRUE, PR_FALSE);
-    if (!event || NS_FAILED(event->PostDOMEvent()))
+    if (NS_FAILED(event->PostDOMEvent()))
       NS_WARNING("Failed to dispatch nsPLDOMEvent");
   }
 }
 
 NS_IMETHODIMP
 nsFrame::HandleEvent(nsPresContext* aPresContext, 
                      nsGUIEvent*     aEvent,
                      nsEventStatus*  aEventStatus)
--- a/layout/generic/nsFrameUtil.cpp
+++ b/layout/generic/nsFrameUtil.cpp
@@ -215,19 +215,16 @@ nsFrameUtil::Node::ReadTree(FILE* aFile)
   fclose(aFile);
   return result;
 }
 
 nsFrameUtil::Node*
 nsFrameUtil::Node::Read(FILE* aFile, Tag* tag)
 {
   Node* node = new Node;
-  if (!node) {
-    /* crash() */
-  }
   node->type = Copy(tag->GetAttr("type"));
   if (!node->type) {
     /* crash() */
   }
   node->state = GetInt(tag, "state");
   delete tag;
 
   for (;;) {
@@ -503,31 +500,28 @@ nsFrameUtil::Tag::ToString(nsString& aRe
   if (type == openClose) {
     aResult.Append(PRUnichar('/'));
   }
   aResult.Append(PRUnichar('>'));
 }
 
 //----------------------------------------------------------------------
 
-nsresult NS_NewFrameUtil(nsIFrameUtil** aResult);
 nsresult
 NS_NewFrameUtil(nsIFrameUtil** aResult)
 {
   NS_PRECONDITION(nsnull != aResult, "null pointer");
   if (nsnull == aResult) {
     return NS_ERROR_NULL_POINTER;
   }
-  *aResult = nsnull;
 
   nsFrameUtil* it = new nsFrameUtil();
-  if (nsnull == it) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-  return it->QueryInterface(NS_GET_IID(nsIFrameUtil), (void**) aResult);
+
+  NS_ADDREF(*aResult = it);
+  return NS_OK;
 }
 
 nsFrameUtil::nsFrameUtil()
 {
 }
 
 nsFrameUtil::~nsFrameUtil()
 {
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -1556,25 +1556,21 @@ nsGfxScrollFrameInner::ScrollTo(nsPoint 
 
   if (mAsyncScroll) {
     if (mAsyncScroll->mIsSmoothScroll) {
       currentPosition = mAsyncScroll->PositionAt(now);
       currentVelocity = mAsyncScroll->VelocityAt(now);
     }
   } else {
     mAsyncScroll = new AsyncScroll;
-    if (mAsyncScroll) {
-      mAsyncScroll->mScrollTimer = do_CreateInstance("@mozilla.org/timer;1");
-      if (!mAsyncScroll->mScrollTimer) {
-        delete mAsyncScroll;
-        mAsyncScroll = nsnull;
-      }
-    }
-    if (!mAsyncScroll) {
-      // some allocation failed. Scroll the normal way.
+    mAsyncScroll->mScrollTimer = do_CreateInstance("@mozilla.org/timer;1");
+    if (!mAsyncScroll->mScrollTimer) {
+      delete mAsyncScroll;
+      mAsyncScroll = nsnull;
+      // allocation failed. Scroll the normal way.
       ScrollToImpl(mDestination);
       return;
     }
     if (isSmoothScroll) {
       mAsyncScroll->mScrollTimer->InitWithFuncCallback(
         AsyncScrollCallback, this, 1000 / 60,
         nsITimer::TYPE_REPEATING_SLACK);
     } else {
@@ -3614,20 +3610,17 @@ nsGfxScrollFrameInner::SaveState(nsIStat
 
   nsPoint scrollPos = GetLogicalScrollPosition();
   // Don't save scroll position if we are at (0,0)
   if (scrollPos == nsPoint(0,0)) {
     return nsnull;
   }
 
   nsPresState* state = new nsPresState();
-  if (!state) {
-    return nsnull;
-  }
- 
+
   state->SetScrollState(scrollPos);
 
   return state;
 }
 
 void
 nsGfxScrollFrameInner::RestoreState(nsPresState* aState)
 {
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -244,17 +244,16 @@ NS_IMETHODIMP
 nsImageFrame::Init(nsIContent*      aContent,
                    nsIFrame*        aParent,
                    nsIFrame*        aPrevInFlow)
 {
   nsresult rv = nsSplittableFrame::Init(aContent, aParent, aPrevInFlow);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mListener = new nsImageListener(this);
-  if (!mListener) return NS_ERROR_OUT_OF_MEMORY;
 
   nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(aContent);
   NS_ENSURE_TRUE(imageLoader, NS_ERROR_UNEXPECTED);
 
   {
     // Push a null JSContext on the stack so that code that runs
     // within the below code doesn't think it's being called by
     // JS. See bug 604262.
@@ -1853,18 +1852,16 @@ nsImageFrame::GetLoadGroup(nsPresContext
 nsresult nsImageFrame::LoadIcons(nsPresContext *aPresContext)
 {
   NS_ASSERTION(!gIconLoad, "called LoadIcons twice");
 
   NS_NAMED_LITERAL_STRING(loadingSrc,"resource://gre-resources/loading-image.png");
   NS_NAMED_LITERAL_STRING(brokenSrc,"resource://gre-resources/broken-image.png");
 
   gIconLoad = new IconLoad();
-  if (!gIconLoad) 
-    return NS_ERROR_OUT_OF_MEMORY;
   NS_ADDREF(gIconLoad);
 
   nsresult rv;
   // create a loader and load the images
   rv = LoadIcon(loadingSrc,
                 aPresContext,
                 getter_AddRefs(gIconLoad->mLoadingImage));
   if (NS_FAILED(rv)) {
--- a/layout/generic/nsLineBox.cpp
+++ b/layout/generic/nsLineBox.cpp
@@ -403,20 +403,18 @@ PRBool
 nsLineBox::SetCarriedOutBottomMargin(nsCollapsingMargin aValue)
 {
   PRBool changed = PR_FALSE;
   if (IsBlock()) {
     if (!aValue.IsZero()) {
       if (!mBlockData) {
         mBlockData = new ExtraBlockData(mBounds);
       }
-      if (mBlockData) {
-        changed = aValue != mBlockData->mCarriedOutBottomMargin;
-        mBlockData->mCarriedOutBottomMargin = aValue;
-      }
+      changed = aValue != mBlockData->mCarriedOutBottomMargin;
+      mBlockData->mCarriedOutBottomMargin = aValue;
     }
     else if (mBlockData) {
       changed = aValue != mBlockData->mCarriedOutBottomMargin;
       mBlockData->mCarriedOutBottomMargin = aValue;
       MaybeFreeData();
     }
   }
   return changed;
@@ -464,19 +462,17 @@ void
 nsLineBox::AppendFloats(nsFloatCacheFreeList& aFreeList)
 { 
   NS_ABORT_IF_FALSE(IsInline(), "block line can't have floats");
   if (IsInline()) {
     if (aFreeList.NotEmpty()) {
       if (!mInlineData) {
         mInlineData = new ExtraInlineData(mBounds);
       }
-      if (mInlineData) {
-        mInlineData->mFloats.Append(aFreeList);
-      }
+      mInlineData->mFloats.Append(aFreeList);
     }
   }
 }
 
 PRBool
 nsLineBox::RemoveFloat(nsIFrame* aFrame)
 {
   NS_ABORT_IF_FALSE(IsInline(), "block line can't have floats");
--- a/layout/generic/nsObjectFrame.cpp
+++ b/layout/generic/nsObjectFrame.cpp
@@ -2097,19 +2097,16 @@ nsObjectFrame::PrepareInstanceOwner()
   NS_ASSERTION(!mInstanceOwner, "Must not have an instance owner here");
 
   mInstanceOwner = new nsPluginInstanceOwner();
 
   PR_LOG(nsObjectFrameLM, PR_LOG_DEBUG,
          ("Created new instance owner %p for frame %p\n", mInstanceOwner.get(),
           this));
 
-  if (!mInstanceOwner)
-    return NS_ERROR_OUT_OF_MEMORY;
-
   // Note, |this| may very well be gone after this call.
   return mInstanceOwner->Init(PresContext(), this, GetContent());
 }
 
 nsresult
 nsObjectFrame::Instantiate(nsIChannel* aChannel, nsIStreamListener** aStreamListener)
 {
   if (mPreventInstantiation) {
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -504,18 +504,16 @@ private:
   PRUint32 mDelay;
 };
 
 NS_IMPL_ISUPPORTS1(nsAutoScrollTimer, nsITimerCallback)
 
 nsresult NS_NewDomSelection(nsISelection **aDomSelection)
 {
   nsTypedSelection *rlist = new nsTypedSelection;
-  if (!rlist)
-    return NS_ERROR_OUT_OF_MEMORY;
   *aDomSelection = (nsISelection *)rlist;
   NS_ADDREF(rlist);
   return NS_OK;
 }
 
 static PRInt8
 GetIndexFromSelectionType(SelectionType aType)
 {
@@ -706,18 +704,16 @@ nsSelectionIterator::IsDone()
 ////////////BEGIN nsFrameSelection methods
 
 nsFrameSelection::nsFrameSelection()
   : mDelayedMouseEvent(PR_FALSE, 0, nsnull, nsMouseEvent::eReal)
 {
   PRInt32 i;
   for (i = 0;i<nsISelectionController::NUM_SELECTIONTYPES;i++){
     mDomSelections[i] = new nsTypedSelection(this);
-    if (!mDomSelections[i])
-      break;
     mDomSelections[i]->SetType(GetSelectionTypeFromIndex(i));
   }
   mBatching = 0;
   mChangesDuringBatching = PR_FALSE;
   mNotifyFrames = PR_TRUE;
   mLimiter = nsnull; //no default limiter.
   mAncestorLimiter = nsnull;
   
@@ -1824,19 +1820,16 @@ nsFrameSelection::TakeFocus(nsIContent *
     mBatching = 1;
 
     if (aMultipleSelection) {
       // Remove existing collapsed ranges as there's no point in having 
       // non-anchor/focus collapsed ranges.
       mDomSelections[index]->RemoveCollapsedRanges();
 
       nsCOMPtr<nsIRange> newRange = new nsRange();
-      if (!newRange) {
-        return NS_ERROR_OUT_OF_MEMORY;
-      }
 
       newRange->SetStart(aNewFocus, aContentOffset);
       newRange->SetEnd(aNewFocus, aContentOffset);
       mDomSelections[index]->AddRange(newRange);
       mBatching = batching;
       mChangesDuringBatching = changes;
     }
     else
@@ -3257,17 +3250,16 @@ nsTypedSelection::GetTableSelectionType(
 }
 
 nsresult
 nsFrameSelection::CreateAndAddRange(nsINode *aParentNode, PRInt32 aOffset)
 {
   if (!aParentNode) return NS_ERROR_NULL_POINTER;
 
   nsCOMPtr<nsIRange> range = new nsRange();
-  if (!range) return NS_ERROR_OUT_OF_MEMORY;
 
   // Set range around child at given offset
   nsresult result = range->SetStart(aParentNode, aOffset);
   if (NS_FAILED(result)) return result;
   result = range->SetEnd(aParentNode, aOffset+1);
   if (NS_FAILED(result)) return result;
   
   PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
@@ -3689,19 +3681,17 @@ nsTypedSelection::SubtractRange(RangeDat
   // cmp < 0, and cmp2 < 0
   // If it right overlaps the new range then cmp > 0 and cmp2 > 0
   // If it fully contains the new range, then cmp < 0 and cmp2 > 0
 
   if (cmp2 > 0) {
     // We need to add a new RangeData to the output, running from
     // the end of aSubtract to the end of range
     nsIRange* postOverlap = new nsRange();
-    if (!postOverlap)
-      return NS_ERROR_OUT_OF_MEMORY;
-    
+
     rv =
       postOverlap->SetStart(aSubtract->GetEndParent(), aSubtract->EndOffset());
     NS_ENSURE_SUCCESS(rv, rv);
     rv =
      postOverlap->SetEnd(range->GetEndParent(), range->EndOffset());
     NS_ENSURE_SUCCESS(rv, rv);
     if (!postOverlap->Collapsed()) {
       if (!aOutput->InsertElementAt(0, RangeData(postOverlap)))
@@ -3709,18 +3699,16 @@ nsTypedSelection::SubtractRange(RangeDat
       (*aOutput)[0].mTextRangeStyle = aRange->mTextRangeStyle;
     }
   }
 
   if (cmp < 0) {
     // We need to add a new RangeData to the output, running from
     // the start of the range to the start of aSubtract
     nsIRange* preOverlap = new nsRange();
-    if (!preOverlap)
-      return NS_ERROR_OUT_OF_MEMORY;
 
     nsresult rv =
      preOverlap->SetStart(range->GetStartParent(), range->StartOffset());
     NS_ENSURE_SUCCESS(rv, rv);
     rv =
      preOverlap->SetEnd(aSubtract->GetStartParent(), aSubtract->StartOffset());
     NS_ENSURE_SUCCESS(rv, rv);
     
@@ -4516,18 +4504,16 @@ nsTypedSelection::LookUpSelection(nsICon
       // of it.
       start = 0;
       end = aContentLength;
     }
     if (start < 0)
       continue; // the ranges do not overlap the input range
 
     SelectionDetails* details = new SelectionDetails;
-    if (!details)
-      return NS_ERROR_OUT_OF_MEMORY;
 
     details->mNext = *aReturnDetails;
     details->mStart = start;
     details->mEnd = end;
     details->mType = aType;
     RangeData *rd = FindRangeData(range);
     if (rd) {
       details->mTextRangeStyle = rd->mTextRangeStyle;
@@ -4670,19 +4656,16 @@ nsTypedSelection::StartAutoScrollTimer(n
   nsresult result;
   if (!mFrameSelection)
     return NS_OK;//nothing to do
 
   if (!mAutoScrollTimer)
   {
     mAutoScrollTimer = new nsAutoScrollTimer();
 
-    if (!mAutoScrollTimer)
-      return NS_ERROR_OUT_OF_MEMORY;
-
     result = mAutoScrollTimer->Init(mFrameSelection, this);
 
     if (NS_FAILED(result))
       return result;
   }
 
   result = mAutoScrollTimer->SetDelay(aDelay);
 
@@ -4737,21 +4720,18 @@ nsTypedSelection::DoAutoScroll(nsIFrame 
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTypedSelection::GetEnumerator(nsIEnumerator **aIterator)
 {
-  nsresult status = NS_ERROR_OUT_OF_MEMORY;
-  nsSelectionIterator *iterator =  new nsSelectionIterator(this);
-  if (iterator && NS_FAILED(status = CallQueryInterface(iterator, aIterator)) )
-    delete iterator;
-  return status;
+  NS_ADDREF(*aIterator = new nsSelectionIterator(this));
+  return NS_OK;
 }
 
 
 
 /** RemoveAllRanges zeroes the selection
  */
 NS_IMETHODIMP
 nsTypedSelection::RemoveAllRanges()
@@ -4939,20 +4919,16 @@ nsTypedSelection::Collapse(nsINode* aPar
   nsRefPtr<nsPresContext>  presContext;
   GetPresContext(getter_AddRefs(presContext));
   Clear(presContext);
 
   // Turn off signal for table selection
   mFrameSelection->ClearTableCellSelection();
 
   nsCOMPtr<nsIRange> range = new nsRange();
-  if (!range) {
-    NS_ASSERTION(PR_FALSE,"Couldn't make a range - nsFrameSelection::Collapse");
-    return NS_ERROR_UNEXPECTED;
-  }
   result = range->SetEnd(aParentNode, aOffset);
   if (NS_FAILED(result))
     return result;
   result = range->SetStart(aParentNode, aOffset);
   if (NS_FAILED(result))
     return result;
 
 #ifdef DEBUG_SELECTION