Bug 654369 - Part 11: Remove OOM checks from layout/base r=bz
authorCraig Topper <craig.topper@gmail.com>
Thu, 28 Apr 2011 22:02:40 -0700
changeset 71800 8027b37a9b32c6df9f729fcb99c9fad5f0e75852
parent 71799 acec89b9786bb24df059210436ff7db4ab1e1cf7
child 71801 63697d518258e6de4383e961020fbb4a465660ff
push idunknown
push userunknown
push dateunknown
reviewersbz
bugs654369
milestone7.0a1
Bug 654369 - Part 11: Remove OOM checks from layout/base r=bz
layout/base/nsCSSFrameConstructor.cpp
layout/base/nsCSSFrameConstructor.h
layout/base/nsCSSRendering.cpp
layout/base/nsCounterManager.cpp
layout/base/nsDisplayList.cpp
layout/base/nsDocumentViewer.cpp
layout/base/nsFrameManager.cpp
layout/base/nsFrameTraversal.cpp
layout/base/nsLayoutDebugger.cpp
layout/base/nsLayoutHistoryState.cpp
layout/base/nsLayoutUtils.cpp
layout/base/nsPresContext.cpp
layout/base/nsPresShell.cpp
layout/base/nsStyleSheetService.cpp
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -1595,18 +1595,16 @@ nsCSSFrameConstructor::CreateGeneratedCo
       nsCounterList* counterList = mCounterManager.CounterListFor(
           nsDependentString(counters->Item(0).GetStringBufferValue()));
       if (!counterList)
         return nsnull;
 
       nsCounterUseNode* node =
         new nsCounterUseNode(counters, aContentIndex,
                              type == eStyleContentType_Counters);
-      if (!node)
-        return nsnull;
 
       nsGenConInitializer* initializer =
         new nsGenConInitializer(node, counterList,
                                 &nsCSSFrameConstructor::CountersDirty);
       return CreateGenConTextNode(aState, EmptyString(), &node->mText,
                                   initializer);
     }
 
@@ -1616,18 +1614,16 @@ nsCSSFrameConstructor::CreateGeneratedCo
 
   case eStyleContentType_OpenQuote:
   case eStyleContentType_CloseQuote:
   case eStyleContentType_NoOpenQuote:
   case eStyleContentType_NoCloseQuote:
     {
       nsQuoteNode* node =
         new nsQuoteNode(type, aContentIndex);
-      if (!node)
-        return nsnull;
 
       nsGenConInitializer* initializer =
         new nsGenConInitializer(node, &mQuoteList,
                                 &nsCSSFrameConstructor::QuotesDirty);
       return CreateGenConTextNode(aState, EmptyString(), &node->mText,
                                   initializer);
     }
   
@@ -5067,19 +5063,17 @@ nsCSSFrameConstructor::AddFrameConstruct
 
     nsIXBLService * xblService = GetXBLService();
     if (!xblService)
       return;
 
     PRBool resolveStyle;
 
     nsAutoPtr<PendingBinding> newPendingBinding(new PendingBinding());
-    if (!newPendingBinding) {
-      return;
-    }
+
     nsresult rv = xblService->LoadBindings(aContent, display->mBinding->GetURI(),
                                            display->mBinding->mOriginPrincipal,
                                            PR_FALSE,
                                            getter_AddRefs(newPendingBinding->mBinding),
                                            &resolveStyle);
     if (NS_FAILED(rv) && rv != NS_ERROR_XBL_BLOCKED)
       return;
 
@@ -9400,20 +9394,16 @@ nsCSSFrameConstructor::CreateNeededTable
                                 // to match that of our first child item to
                                 // match the old behavior
                                 iter.item().mNameSpaceID,
                                 // no pending binding
                                 nsnull,
                                 wrapperStyle.forget(),
                                 PR_TRUE);
 
-    if (!newItem) {
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
-
     // Here we're cheating a tad... technically, table-internal items should be
     // inline if aParentFrame is inline, but they'll get wrapped in an
     // inline-table in the end, so it'll all work out.  In any case, arguably
     // we don't need to maintain this state at this point... but it's better
     // to, I guess.
     newItem->mIsAllInline = newItem->mHasInlineEnds =
       newItem->mStyleContext->GetStyleDisplay()->IsInlineOutside();
 
--- a/layout/base/nsCSSFrameConstructor.h
+++ b/layout/base/nsCSSFrameConstructor.h
@@ -851,24 +851,19 @@ private:
                                       PendingBinding* aPendingBinding,
                                       already_AddRefed<nsStyleContext> aStyleContext,
                                       PRBool aSuppressWhiteSpaceOptimizations)
     {
       FrameConstructionItem* item =
         new FrameConstructionItem(aFCData, aContent, aTag, aNameSpaceID,
                                   aPendingBinding, aStyleContext,
                                   aSuppressWhiteSpaceOptimizations);
-      if (item) {
-        PR_APPEND_LINK(item, &mItems);
-        ++mItemCount;
-        ++mDesiredParentCounts[item->DesiredParentType()];
-      } else {
-        // Clean up the style context
-        nsRefPtr<nsStyleContext> sc(aStyleContext);
-      }
+      PR_APPEND_LINK(item, &mItems);
+      ++mItemCount;
+      ++mDesiredParentCounts[item->DesiredParentType()];
       return item;
     }
 
     void InlineItemAdded() { ++mInlineCount; }
     void BlockItemAdded() { ++mBlockCount; }
     void LineParticipantItemAdded() { ++mLineParticipantCount; }
 
     class Iterator;
--- a/layout/base/nsCSSRendering.cpp
+++ b/layout/base/nsCSSRendering.cpp
@@ -2116,30 +2116,30 @@ nsCSSRendering::PaintGradient(nsPresCont
     double outerRadius = radiusX*lastStop;
     if (stopScale == 0.0) {
       // Stops are all at the same place.  See above (except we now have
       // the inside vs. outside of an ellipse).
       outerRadius = innerRadius + 1;
     }
     gradientPattern = new gfxPattern(lineStart.x, lineStart.y, innerRadius,
                                      lineStart.x, lineStart.y, outerRadius);
-    if (gradientPattern && radiusX != radiusY) {
+    if (radiusX != radiusY) {
       // Stretch the circles into ellipses vertically by setting a transform
       // in the pattern.
       // Recall that this is the transform from user space to pattern space.
       // So to stretch the ellipse by factor of P vertically, we scale
       // user coordinates by 1/P.
       gfxMatrix matrix;
       matrix.Translate(lineStart);
       matrix.Scale(1.0, radiusX/radiusY);
       matrix.Translate(-lineStart);
       gradientPattern->SetMatrix(matrix);
     }
   }
-  if (!gradientPattern || gradientPattern->CairoStatus())
+  if (gradientPattern->CairoStatus())
     return;
 
   // Now set normalized color stops in pattern.
   if (stopScale == 0.0) {
     // Non-repeating gradient with all stops in same place -> just add
     // first stop and last stop, both at position 0.
     // Repeating gradient with all stops in the same place, or radial
     // gradient with radius of 0 -> just paint the last stop color.
--- a/layout/base/nsCounterManager.cpp
+++ b/layout/base/nsCounterManager.cpp
@@ -239,18 +239,16 @@ nsCounterManager::AddCounterResetsAndInc
 
 PRBool
 nsCounterManager::AddResetOrIncrement(nsIFrame *aFrame, PRInt32 aIndex,
                                       const nsStyleCounterData *aCounterData,
                                       nsCounterNode::Type aType)
 {
     nsCounterChangeNode *node =
         new nsCounterChangeNode(aFrame, aType, aCounterData->mValue, aIndex);
-    if (!node)
-        return PR_FALSE;
 
     nsCounterList *counterList = CounterListFor(aCounterData->mCounter);
     if (!counterList) {
         NS_NOTREACHED("CounterListFor failed (should only happen on OOM)");
         return PR_FALSE;
     }
 
     counterList->Insert(node);
@@ -272,18 +270,16 @@ nsCounterManager::AddResetOrIncrement(ns
 nsCounterList*
 nsCounterManager::CounterListFor(const nsSubstring& aCounterName)
 {
     // XXX Why doesn't nsTHashtable provide an API that allows us to use
     // get/put in one hashtable lookup?
     nsCounterList *counterList;
     if (!mNames.Get(aCounterName, &counterList)) {
         counterList = new nsCounterList();
-        if (!counterList)
-            return nsnull;
         if (!mNames.Put(aCounterName, counterList)) {
             delete counterList;
             return nsnull;
         }
     }
     return counterList;
 }
 
--- a/layout/base/nsDisplayList.cpp
+++ b/layout/base/nsDisplayList.cpp
@@ -569,18 +569,16 @@ void nsDisplayList::PaintForFrame(nsDisp
     }
   }
   if (!layerManager) {
     if (!aCtx) {
       NS_WARNING("Nowhere to paint into");
       return;
     }
     layerManager = new BasicLayerManager();
-    if (!layerManager)
-      return;
   }
 
   if (aFlags & PAINT_FLUSH_LAYERS) {
     FrameLayerBuilder::InvalidateAllLayers(layerManager);
   }
 
   if (doBeginTransaction) {
     if (aCtx) {
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -540,19 +540,16 @@ public:
 // Class IDs
 static NS_DEFINE_CID(kViewManagerCID,       NS_VIEW_MANAGER_CID);
 
 //------------------------------------------------------------------
 nsresult
 NS_NewDocumentViewer(nsIDocumentViewer** aResult)
 {
   *aResult = new DocumentViewerImpl();
-  if (!*aResult) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
 
   NS_ADDREF(*aResult);
 
   return NS_OK;
 }
 
 void DocumentViewerImpl::PrepareToStartLoad()
 {
@@ -795,17 +792,16 @@ DocumentViewerImpl::InitPresentationStuf
     mPresContext->SetVisibleArea(nsRect(0, 0, width, height));
   }
 
   // now register ourselves as a selection listener, so that we get
   // called when the selection changes in the window
   if (!mSelectionListener) {
     nsDocViewerSelectionListener *selectionListener =
       new nsDocViewerSelectionListener();
-    NS_ENSURE_TRUE(selectionListener, NS_ERROR_OUT_OF_MEMORY);
 
     selectionListener->Init(this);
 
     // mSelectionListener is a owning reference
     mSelectionListener = selectionListener;
   }
 
   nsCOMPtr<nsISelection> selection;
@@ -820,17 +816,16 @@ DocumentViewerImpl::InitPresentationStuf
   // Save old listener so we can unregister it
   nsCOMPtr<nsIDOMFocusListener> oldFocusListener = mFocusListener;
 
   // focus listener
   //
   // now register ourselves as a focus listener, so that we get called
   // when the focus changes in the window
   nsDocViewerFocusListener *focusListener = new nsDocViewerFocusListener();
-  NS_ENSURE_TRUE(focusListener, NS_ERROR_OUT_OF_MEMORY);
 
   focusListener->Init(this);
 
   // mFocusListener is a strong reference
   mFocusListener = focusListener;
 
   if (mDocument) {
     rv = mDocument->AddEventListenerByIID(mFocusListener,
@@ -2175,19 +2170,16 @@ nsresult
 DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument,
                                    nsStyleSet** aStyleSet)
 {
   // Make sure this does the same thing as PresShell::AddSheet wrt ordering.
 
   // this should eventually get expanded to allow for creating
   // different sets for different media
   nsStyleSet *styleSet = new nsStyleSet();
-  if (!styleSet) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
 
   styleSet->BeginUpdate();
   
   // The document will fill in the document sheets when we create the presshell
   
   // Handle the user sheets.
 #ifdef DEBUG
   nsCOMPtr<nsISupports> debugDocContainer = aDocument->GetContainer();
@@ -3679,17 +3671,16 @@ DocumentViewerImpl::Print(nsIPrintSettin
   // If we are hosting a full-page plugin, tell it to print
   // first. It shows its own native print UI.
   nsCOMPtr<nsIPluginDocument> pDoc(do_QueryInterface(mDocument));
   if (pDoc)
     return pDoc->Print();
 
   if (!mPrintEngine) {
     mPrintEngine = new nsPrintEngine();
-    NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_OUT_OF_MEMORY);
 
     rv = mPrintEngine->Initialize(this, mContainer, mDocument, 
                                   float(mDeviceContext->AppUnitsPerCSSInch()) /
                                   float(mDeviceContext->AppUnitsPerDevPixel()) /
                                   mPageZoom,
 #ifdef NS_DEBUG
                                   mDebugFile
 #else
@@ -3746,17 +3737,16 @@ DocumentViewerImpl::PrintPreview(nsIPrin
   nsCOMPtr<nsIDOMDocument> domDoc;
   aChildDOMWin->GetDocument(getter_AddRefs(domDoc));
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
   NS_ENSURE_STATE(doc);
 
   nsPrintEventDispatcher beforeAndAfterPrint(doc);
   if (!mPrintEngine) {
     mPrintEngine = new nsPrintEngine();
-    NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_OUT_OF_MEMORY);
 
     rv = mPrintEngine->Initialize(this, mContainer, doc,
                                   float(mDeviceContext->AppUnitsPerCSSInch()) /
                                   float(mDeviceContext->AppUnitsPerDevPixel()) /
                                   mPageZoom,
 #ifdef NS_DEBUG
                                   mDebugFile
 #else
--- a/layout/base/nsFrameManager.cpp
+++ b/layout/base/nsFrameManager.cpp
@@ -375,24 +375,22 @@ nsFrameManager::SetUndisplayedContent(ns
 #endif
 
   NS_ASSERTION(!GetUndisplayedContent(aContent),
                "Already have an undisplayed context entry for aContent");
 
   if (! mUndisplayedMap) {
     mUndisplayedMap = new UndisplayedMap;
   }
-  if (mUndisplayedMap) {
-    nsIContent* parent = aContent->GetParent();
-    NS_ASSERTION(parent || (mPresShell && mPresShell->GetDocument() &&
-                 mPresShell->GetDocument()->GetRootElement() == aContent),
-                 "undisplayed content must have a parent, unless it's the root "
-                 "element");
-    mUndisplayedMap->AddNodeFor(parent, aContent, aStyleContext);
-  }
+  nsIContent* parent = aContent->GetParent();
+  NS_ASSERTION(parent || (mPresShell && mPresShell->GetDocument() &&
+               mPresShell->GetDocument()->GetRootElement() == aContent),
+               "undisplayed content must have a parent, unless it's the root "
+               "element");
+  mUndisplayedMap->AddNodeFor(parent, aContent, aStyleContext);
 }
 
 void
 nsFrameManager::ChangeUndisplayedContent(nsIContent* aContent, 
                                          nsStyleContext* aStyleContext)
 {
   NS_ASSERTION(mUndisplayedMap, "no existing undisplayed content");
   
@@ -1895,19 +1893,16 @@ nsFrameManagerBase::UndisplayedMap::Appe
 }
 
 nsresult 
 nsFrameManagerBase::UndisplayedMap::AddNodeFor(nsIContent* aParentContent,
                                                nsIContent* aChild, 
                                                nsStyleContext* aStyle)
 {
   UndisplayedNode*  node = new UndisplayedNode(aChild, aStyle);
-  if (! node) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
 
   AppendNodeFor(node, aParentContent);
   return NS_OK;
 }
 
 void
 nsFrameManagerBase::UndisplayedMap::RemoveNodeFor(nsIContent* aParentContent,
                                                   UndisplayedNode* aNode)
--- a/layout/base/nsFrameTraversal.cpp
+++ b/layout/base/nsFrameTraversal.cpp
@@ -146,18 +146,16 @@ protected:
 /************IMPLEMENTATIONS**************/
 
 nsresult NS_CreateFrameTraversal(nsIFrameTraversal** aResult)
 {
   NS_ENSURE_ARG_POINTER(aResult);
   *aResult = nsnull;
 
   nsCOMPtr<nsIFrameTraversal> t(new nsFrameTraversal());
-  if (!t)
-    return NS_ERROR_OUT_OF_MEMORY;
 
   *aResult = t;
   NS_ADDREF(*aResult);
 
   return NS_OK;
 }
 
 nsresult
@@ -174,20 +172,17 @@ NS_NewFrameTraversal(nsIFrameEnumerator 
   nsCOMPtr<nsIFrameEnumerator> trav;
   if (aVisual) {
     trav = new nsVisualIterator(aPresContext, aStart, aType,
                                 aLockInScrollView, aFollowOOFs);
   } else {
     trav = new nsFrameIterator(aPresContext, aStart, aType,
                                aLockInScrollView, aFollowOOFs);
   }
-  if (!trav)
-    return NS_ERROR_OUT_OF_MEMORY;
-  *aEnumerator = trav;
-  NS_ADDREF(trav);
+  trav.forget(aEnumerator);
   return NS_OK;
 }
 
 
 nsFrameTraversal::nsFrameTraversal()
 {
 }
 
--- a/layout/base/nsLayoutDebugger.cpp
+++ b/layout/base/nsLayoutDebugger.cpp
@@ -79,19 +79,16 @@ public:
 nsresult
 NS_NewLayoutDebugger(nsILayoutDebugger** aResult)
 {
   NS_PRECONDITION(aResult, "null OUT ptr");
   if (!aResult) {
     return NS_ERROR_NULL_POINTER;
   }
   nsLayoutDebugger* it = new nsLayoutDebugger();
-  if (!it) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
   return it->QueryInterface(NS_GET_IID(nsILayoutDebugger), (void**)aResult);
 }
 
 nsLayoutDebugger::nsLayoutDebugger()
 {
 }
 
 nsLayoutDebugger::~nsLayoutDebugger()
--- a/layout/base/nsLayoutHistoryState.cpp
+++ b/layout/base/nsLayoutHistoryState.cpp
@@ -72,18 +72,16 @@ private:
 
 nsresult
 NS_NewLayoutHistoryState(nsILayoutHistoryState** aState)
 {
   nsLayoutHistoryState *state;
 
   *aState = nsnull;
   state = new nsLayoutHistoryState();
-  if (!state)
-    return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(state);
   nsresult rv = state->Init();
   if (NS_SUCCEEDED(rv))
     *aState = state;
   else
     NS_RELEASE(state);
 
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -1806,20 +1806,16 @@ void nsLayoutUtils::RectAccumulator::Add
   }
 }
 
 nsLayoutUtils::RectListBuilder::RectListBuilder(nsClientRectList* aList)
   : mRectList(aList), mRV(NS_OK) {}
 
 void nsLayoutUtils::RectListBuilder::AddRect(const nsRect& aRect) {
   nsRefPtr<nsClientRect> rect = new nsClientRect();
-  if (!rect) {
-    mRV = NS_ERROR_OUT_OF_MEMORY;
-    return;
-  }
 
   rect->SetLayoutRect(aRect);
   mRectList->Append(rect);
 }
 
 nsIFrame* nsLayoutUtils::GetContainingBlockForClientRect(nsIFrame* aFrame)
 {
   // get the nearest enclosing SVG foreign object frame or the root frame
@@ -3871,22 +3867,18 @@ nsLayoutUtils::SurfaceFromElement(nsIDOM
     gfxIntSize size;
     nsRefPtr<gfxASurface> surf = container->GetCurrentAsSurface(&size);
     if (!surf)
       return result;
 
     if (wantImageSurface && surf->GetType() != gfxASurface::SurfaceTypeImage) {
       nsRefPtr<gfxImageSurface> imgSurf =
         new gfxImageSurface(size, gfxASurface::ImageFormatARGB32);
-      if (!imgSurf)
-        return result;
 
       nsRefPtr<gfxContext> ctx = new gfxContext(imgSurf);
-      if (!ctx)
-        return result;
       ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
       ctx->DrawSurface(surf, size);
       surf = imgSurf;
     }
 
     result.mSurface = surf;
     result.mSize = size;
     result.mPrincipal = principal.forget();
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -907,28 +907,21 @@ nsPresContext::Init(nsDeviceContext* aDe
   // from calling GetUserPreferences() when we get a presshell.
   nsresult rv = CallGetService(kLookAndFeelCID, &mLookAndFeel);
   if (NS_FAILED(rv)) {
     NS_ERROR("LookAndFeel service must be implemented for this toolkit");
     return rv;
   }
 
   mEventManager = new nsEventStateManager();
-  if (!mEventManager)
-    return NS_ERROR_OUT_OF_MEMORY;
-
   NS_ADDREF(mEventManager);
 
   mTransitionManager = new nsTransitionManager(this);
-  if (!mTransitionManager)
-    return NS_ERROR_OUT_OF_MEMORY;
 
   mAnimationManager = new nsAnimationManager(this);
-  if (!mAnimationManager)
-    return NS_ERROR_OUT_OF_MEMORY;
 
   if (mDocument->GetDisplayDocument()) {
     NS_ASSERTION(mDocument->GetDisplayDocument()->GetShell() &&
                  mDocument->GetDisplayDocument()->GetShell()->GetPresContext(),
                  "Why are we being initialized?");
     mRefreshDriver = mDocument->GetDisplayDocument()->GetShell()->
       GetPresContext()->RefreshDriver();
   } else {
@@ -954,18 +947,16 @@ nsPresContext::Init(nsDeviceContext* aDe
         if (parentItem) {
           mRefreshDriver = parent->GetShell()->GetPresContext()->RefreshDriver();
         }
       }
     }
 
     if (!mRefreshDriver) {
       mRefreshDriver = new nsRefreshDriver(this);
-      if (!mRefreshDriver)
-        return NS_ERROR_OUT_OF_MEMORY;
     }
   }
 
   mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID);
 
   // Register callbacks so we're notified when the preferences change
   Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
                                 "font.",
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -1239,44 +1239,40 @@ protected:
   public:
     nsDelayedMouseEvent(nsMouseEvent* aEvent) : nsDelayedInputEvent()
     {
       mEvent = new nsMouseEvent(NS_IS_TRUSTED_EVENT(aEvent),
                                 aEvent->message,
                                 aEvent->widget,
                                 aEvent->reason,
                                 aEvent->context);
-      if (mEvent) {
-        Init(aEvent);
-        static_cast<nsMouseEvent*>(mEvent)->clickCount = aEvent->clickCount;
-      }
+      Init(aEvent);
+      static_cast<nsMouseEvent*>(mEvent)->clickCount = aEvent->clickCount;
     }
 
     virtual ~nsDelayedMouseEvent()
     {
       delete static_cast<nsMouseEvent*>(mEvent);
     }
   };
 
   class nsDelayedKeyEvent : public nsDelayedInputEvent
   {
   public:
     nsDelayedKeyEvent(nsKeyEvent* aEvent) : nsDelayedInputEvent()
     {
       mEvent = new nsKeyEvent(NS_IS_TRUSTED_EVENT(aEvent),
                               aEvent->message,
                               aEvent->widget);
-      if (mEvent) {
-        Init(aEvent);
-        static_cast<nsKeyEvent*>(mEvent)->keyCode = aEvent->keyCode;
-        static_cast<nsKeyEvent*>(mEvent)->charCode = aEvent->charCode;
-        static_cast<nsKeyEvent*>(mEvent)->alternativeCharCodes =
-          aEvent->alternativeCharCodes;
-        static_cast<nsKeyEvent*>(mEvent)->isChar = aEvent->isChar;
-      }
+      Init(aEvent);
+      static_cast<nsKeyEvent*>(mEvent)->keyCode = aEvent->keyCode;
+      static_cast<nsKeyEvent*>(mEvent)->charCode = aEvent->charCode;
+      static_cast<nsKeyEvent*>(mEvent)->alternativeCharCodes =
+        aEvent->alternativeCharCodes;
+      static_cast<nsKeyEvent*>(mEvent)->isChar = aEvent->isChar;
     }
 
     virtual ~nsDelayedKeyEvent()
     {
       delete static_cast<nsKeyEvent*>(mEvent);
     }
   };
 
@@ -1659,18 +1655,16 @@ nsresult
 NS_NewPresShell(nsIPresShell** aInstancePtrResult)
 {
   NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
 
   if (!aInstancePtrResult)
     return NS_ERROR_NULL_POINTER;
 
   *aInstancePtrResult = new PresShell();
-  if (!*aInstancePtrResult)
-    return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*aInstancePtrResult);
   return NS_OK;
 }
 
 nsTHashtable<PresShell::PresShellPtrKey> *nsIPresShell::sLiveShells = 0;
 static PRBool sSynthMouseMove = PR_TRUE;
 
@@ -1796,17 +1790,16 @@ PresShell::Init(nsIDocument* aDocument,
   }
 
   mDocument = aDocument;
   NS_ADDREF(mDocument);
   mViewManager = aViewManager;
 
   // Create our frame constructor.
   mFrameConstructor = new nsCSSFrameConstructor(mDocument, this);
-  NS_ENSURE_TRUE(mFrameConstructor, NS_ERROR_OUT_OF_MEMORY);
 
   // The document viewer owns both view manager and pres shell.
   mViewManager->SetViewObserver(this);
 
   // Bind the context to the presentation shell.
   mPresContext = aPresContext;
   NS_ADDREF(mPresContext);
   aPresContext->SetShell(this);
@@ -5481,18 +5474,16 @@ PresShell::CreateRangePaintInfo(nsIDOMRa
            nsLayoutUtils::GetNextContinuationOrSpecialSibling(ancestorFrame))
       ancestorFrame = ancestorFrame->GetParent();
   }
 
   if (!ancestorFrame)
     return nsnull;
 
   info = new RangePaintInfo(range, ancestorFrame);
-  if (!info)
-    return nsnull;
 
   nsRect ancestorRect = ancestorFrame->GetVisualOverflowRect();
 
   // get a display list containing the range
   info->mBuilder.SetIncludeAllOutOfFlows();
   if (aForPrimarySelection) {
     info->mBuilder.SetSelectedFramesOnly();
   }
@@ -5584,17 +5575,17 @@ PresShell::PaintRangePaintInfo(nsTArray<
     aScreenRect->MoveTo(rootScreenRect.x + pixelArea.x, rootScreenRect.y + pixelArea.y);
   }
   aScreenRect->width = pixelArea.width;
   aScreenRect->height = pixelArea.height;
 
   gfxImageSurface* surface =
     new gfxImageSurface(gfxIntSize(pixelArea.width, pixelArea.height),
                         gfxImageSurface::ImageFormatARGB32);
-  if (!surface || surface->CairoStatus()) {
+  if (surface->CairoStatus()) {
     delete surface;
     return nsnull;
   }
 
   // clear the image
   gfxContext context(surface);
   context.SetOperator(gfxContext::OPERATOR_CLEAR);
   context.Rectangle(gfxRect(0, 0, pixelArea.width, pixelArea.height));
@@ -6560,17 +6551,17 @@ PresShell::HandleEvent(nsIView         *
 
   if (aEvent->eventStructType == NS_KEY_EVENT &&
       mDocument && mDocument->EventHandlingSuppressed()) {
     if (aEvent->message == NS_KEY_DOWN) {
       mNoDelayedKeyEvents = PR_TRUE;
     } else if (!mNoDelayedKeyEvents) {
       nsDelayedEvent* event =
         new nsDelayedKeyEvent(static_cast<nsKeyEvent*>(aEvent));
-      if (event && !mDelayedEvents.AppendElement(event)) {
+      if (!mDelayedEvents.AppendElement(event)) {
         delete event;
       }
     }
     return NS_OK;
   }
 
   nsIFrame* frame = static_cast<nsIFrame*>(aView->GetClientData());
   PRBool dispatchUsingCoordinates = NS_IsEventUsingCoordinates(aEvent);
@@ -8590,28 +8581,26 @@ static nsresult
 DumpToPNG(nsIPresShell* shell, nsAString& name) {
   PRInt32 width=1000, height=1000;
   nsRect r(0, 0, shell->GetPresContext()->DevPixelsToAppUnits(width),
                  shell->GetPresContext()->DevPixelsToAppUnits(height));
 
   nsRefPtr<gfxImageSurface> imgSurface =
      new gfxImageSurface(gfxIntSize(width, height),
                          gfxImageSurface::ImageFormatARGB32);
-  NS_ENSURE_TRUE(imgSurface, NS_ERROR_OUT_OF_MEMORY);
 
   nsRefPtr<gfxContext> imgContext = new gfxContext(imgSurface);
 
   nsRefPtr<gfxASurface> surface = 
     gfxPlatform::GetPlatform()->
     CreateOffscreenSurface(gfxIntSize(width, height),
       gfxASurface::ContentFromFormat(gfxASurface::ImageFormatARGB32));
   NS_ENSURE_TRUE(surface, NS_ERROR_OUT_OF_MEMORY);
 
   nsRefPtr<gfxContext> context = new gfxContext(surface);
-  NS_ENSURE_TRUE(context, NS_ERROR_OUT_OF_MEMORY);
 
   shell->RenderDocument(r, 0, NS_RGB(255, 255, 0), context);
 
   imgContext->DrawSurface(surface, gfxSize(width, height));
 
   nsCOMPtr<imgIEncoder> encoder = do_CreateInstance("@mozilla.org/image/encoder;2?type=image/png");
   NS_ENSURE_TRUE(encoder, NS_ERROR_FAILURE);
   encoder->InitFromData(imgSurface->Data(), imgSurface->Stride() * height,
@@ -8974,33 +8963,31 @@ ReflowCounter * ReflowCountMgr::LookUp(c
 void ReflowCountMgr::Add(const char * aName, nsIFrame * aFrame)
 {
   NS_ASSERTION(aName != nsnull, "Name shouldn't be null!");
 
   if (mDumpFrameCounts && nsnull != mCounts) {
     ReflowCounter * counter = (ReflowCounter *)PL_HashTableLookup(mCounts, aName);
     if (counter == nsnull) {
       counter = new ReflowCounter(this);
-      NS_ASSERTION(counter != nsnull, "null ptr");
       char * name = NS_strdup(aName);
       NS_ASSERTION(name != nsnull, "null ptr");
       PL_HashTableAdd(mCounts, name, counter);
     }
     counter->Add();
   }
 
   if ((mDumpFrameByFrameCounts || mPaintFrameByFrameCounts) && 
       nsnull != mIndiFrameCounts && 
       aFrame != nsnull) {
     char * key = new char[16];
     sprintf(key, "%p", (void*)aFrame);
     IndiReflowCounter * counter = (IndiReflowCounter *)PL_HashTableLookup(mIndiFrameCounts, key);
     if (counter == nsnull) {
       counter = new IndiReflowCounter(this);
-      NS_ASSERTION(counter != nsnull, "null ptr");
       counter->mFrame = aFrame;
       counter->mName.AssignASCII(aName);
       PL_HashTableAdd(mIndiFrameCounts, key, counter);
     }
     // this eliminates extra counts from super classes
     if (counter != nsnull && counter->mName.EqualsASCII(aName)) {
       counter->mCount++;
       counter->mCounter.Add(1);
--- a/layout/base/nsStyleSheetService.cpp
+++ b/layout/base/nsStyleSheetService.cpp
@@ -164,17 +164,16 @@ nsStyleSheetService::LoadAndRegisterShee
 nsresult
 nsStyleSheetService::LoadAndRegisterSheetInternal(nsIURI *aSheetURI,
                                                   PRUint32 aSheetType)
 {
   NS_ENSURE_ARG(aSheetType == AGENT_SHEET || aSheetType == USER_SHEET);
   NS_ENSURE_ARG_POINTER(aSheetURI);
 
   nsRefPtr<mozilla::css::Loader> loader = new mozilla::css::Loader();
-  NS_ENSURE_TRUE(loader, NS_ERROR_OUT_OF_MEMORY);
 
   nsRefPtr<nsCSSStyleSheet> sheet;
   // Allow UA sheets, but not user sheets, to use unsafe rules
   nsresult rv = loader->LoadSheetSync(aSheetURI, aSheetType == AGENT_SHEET,
                                       PR_TRUE, getter_AddRefs(sheet));
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!mSheets[aSheetType].AppendObject(sheet)) {