diff --git a/mozilla/layout/base/nsCSSFrameConstructor.cpp b/mozilla/layout/base/nsCSSFrameConstructor.cpp index 1e3757428af..5dfc8c5c788 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/base/nsCSSFrameConstructor.cpp @@ -163,8 +163,8 @@ NS_NewXTFSVGDisplayFrame(nsIPresShell*, nsIContent*, nsIFrame**); #endif #endif -nsresult -NS_NewHTMLCanvasFrame (nsIPresShell* aPresShell, nsIFrame** aNewFrame); +nsIFrame* +NS_NewHTMLCanvasFrame (nsIPresShell* aPresShell); #ifdef MOZ_SVG #include "nsSVGAtoms.h" @@ -2092,10 +2092,9 @@ nsCSSFrameConstructor::CreateGeneratedFrameFor(nsIFrame* aParentFram content->SetNativeAnonymous(PR_TRUE); // Create an image frame and initialize it - nsIFrame* imageFrame = nsnull; - rv = NS_NewImageFrame(mPresShell, &imageFrame); - if (!imageFrame) { - return rv; + nsIFrame* imageFrame = NS_NewImageFrame(mPresShell); + if (NS_UNLIKELY(!imageFrame)) { + return NS_ERROR_OUT_OF_MEMORY; } rv = imageFrame->Init(presContext, content, aParentFrame, aStyleContext, @@ -2437,7 +2436,11 @@ nsCSSFrameConstructor::CreateInputFrame(nsIContent *aContent, case NS_FORM_INPUT_TEXT: case NS_FORM_INPUT_PASSWORD: - return NS_NewTextControlFrame(mPresShell, aFrame); + { + *aFrame = NS_NewTextControlFrame(mPresShell); + + return NS_UNLIKELY(!*aFrame) ? NS_ERROR_OUT_OF_MEMORY : NS_OK; + } default: NS_ASSERTION(0, "Unknown input type!"); @@ -2453,7 +2456,9 @@ nsCSSFrameConstructor::CreateHTMLImageFrame(nsIContent* aContent, { // Make sure to keep IsSpecialContent in synch with this code if (nsImageFrame::ShouldCreateImageFrameFor(aContent, aStyleContext)) { - return (*aFunc)(mPresShell, aFrame); + *aFrame = (*aFunc)(mPresShell); + + return NS_UNLIKELY(!*aFrame) ? NS_ERROR_OUT_OF_MEMORY : NS_OK; } *aFrame = nsnull; @@ -5489,6 +5494,8 @@ nsCSSFrameConstructor::ConstructHTMLFrame(nsFrameConstructorState& aState, PRBool isFloatContainer = PR_FALSE; PRBool addedToFrameList = PR_FALSE; nsresult rv = NS_OK; + + PRBool triedFrame = PR_FALSE; // See if the element is absolute or fixed positioned const nsStyleDisplay* display = aStyleContext->GetStyleDisplay(); @@ -5509,7 +5516,9 @@ nsCSSFrameConstructor::ConstructHTMLFrame(nsFrameConstructorState& aState, if (!aHasPseudoParent && !aState.mPseudoFrames.IsEmpty()) { ProcessPseudoFrames(aState, aFrameItems); } - rv = NS_NewBRFrame(mPresShell, &newFrame); + newFrame = NS_NewBRFrame(mPresShell); + triedFrame = PR_TRUE; + isReplaced = PR_TRUE; // BR frames don't go in the content->frame hash table: typically // there are many BR content objects and this would increase the size @@ -5520,7 +5529,8 @@ nsCSSFrameConstructor::ConstructHTMLFrame(nsFrameConstructorState& aState, if (!aHasPseudoParent && !aState.mPseudoFrames.IsEmpty()) { ProcessPseudoFrames(aState, aFrameItems); } - rv = NS_NewWBRFrame(mPresShell, &newFrame); + newFrame = NS_NewWBRFrame(mPresShell); + triedFrame = PR_TRUE; } else if (nsHTMLAtoms::input == aTag) { // Make sure to keep IsSpecialContent in synch with this code @@ -5537,7 +5547,8 @@ nsCSSFrameConstructor::ConstructHTMLFrame(nsFrameConstructorState& aState, ProcessPseudoFrames(aState, aFrameItems); } isReplaced = PR_TRUE; - rv = NS_NewTextControlFrame(mPresShell, &newFrame); + newFrame = NS_NewTextControlFrame(mPresShell); + triedFrame = PR_TRUE; } else if (nsHTMLAtoms::select == aTag) { if (!gUseXBLForms) { @@ -5579,25 +5590,21 @@ nsCSSFrameConstructor::ConstructHTMLFrame(nsFrameConstructorState& aState, objContent->GetDisplayedType(&type); if (type == nsIObjectLoadingContent::TYPE_LOADING) { // Ideally, this should show the standby attribute - rv = NS_NewEmptyFrame(mPresShell, &newFrame); + newFrame = NS_NewEmptyFrame(mPresShell); } else if (type == nsIObjectLoadingContent::TYPE_PLUGIN) - rv = NS_NewObjectFrame(mPresShell, &newFrame); + newFrame = NS_NewObjectFrame(mPresShell); else if (type == nsIObjectLoadingContent::TYPE_IMAGE) - rv = NS_NewImageFrame(mPresShell, &newFrame); - else if (type == nsIObjectLoadingContent::TYPE_DOCUMENT) { + newFrame = NS_NewImageFrame(mPresShell); + else if (type == nsIObjectLoadingContent::TYPE_DOCUMENT) newFrame = NS_NewSubDocumentFrame(mPresShell); - - // xxx marc - if (!newFrame) { - rv = NS_ERROR_OUT_OF_MEMORY; - } - } #ifdef DEBUG else NS_ERROR("Shouldn't get here if we're not broken and not " "suppressed and not blocked"); #endif + + triedFrame = PR_TRUE; } } else if (nsHTMLAtoms::fieldset == aTag) { @@ -5619,7 +5626,9 @@ nsCSSFrameConstructor::ConstructHTMLFrame(nsFrameConstructorState& aState, if (!aHasPseudoParent && !aState.mPseudoFrames.IsEmpty()) { ProcessPseudoFrames(aState, aFrameItems); } - rv = NS_NewLegendFrame(mPresShell, &newFrame); + newFrame = NS_NewLegendFrame(mPresShell); + triedFrame = PR_TRUE; + isFloatContainer = PR_TRUE; } else if (nsHTMLAtoms::frameset == aTag) { @@ -5630,7 +5639,8 @@ nsCSSFrameConstructor::ConstructHTMLFrame(nsFrameConstructorState& aState, ProcessPseudoFrames(aState, aFrameItems); } - rv = NS_NewHTMLFramesetFrame(mPresShell, &newFrame); + newFrame = NS_NewHTMLFramesetFrame(mPresShell); + triedFrame = PR_TRUE; } else if (nsHTMLAtoms::iframe == aTag) { if (!aHasPseudoParent && !aState.mPseudoFrames.IsEmpty()) { @@ -5639,12 +5649,8 @@ nsCSSFrameConstructor::ConstructHTMLFrame(nsFrameConstructorState& aState, isReplaced = PR_TRUE; newFrame = NS_NewSubDocumentFrame(mPresShell); - - // xxx marc - if (!newFrame) { - rv = NS_ERROR_OUT_OF_MEMORY; - } - + triedFrame = PR_TRUE; + if (newFrame) { // the nsSubDocumentFrame needs to know about its content parent during ::Init. // there is no reasonable way to get the value there. @@ -5661,13 +5667,16 @@ nsCSSFrameConstructor::ConstructHTMLFrame(nsFrameConstructorState& aState, if (!aHasPseudoParent && !aState.mPseudoFrames.IsEmpty()) { ProcessPseudoFrames(aState, aFrameItems); } - rv = NS_NewSpacerFrame(mPresShell, &newFrame); + newFrame = NS_NewSpacerFrame(mPresShell); + triedFrame = PR_TRUE; } else if (nsHTMLAtoms::button == aTag) { if (!aHasPseudoParent && !aState.mPseudoFrames.IsEmpty()) { ProcessPseudoFrames(aState, aFrameItems); } - rv = NS_NewHTMLButtonControlFrame(mPresShell, &newFrame); + newFrame = NS_NewHTMLButtonControlFrame(mPresShell); + triedFrame = PR_TRUE; + // the html4 button needs to act just like a // regular button except contain html content // so it must be replaced or html outside it will @@ -5680,18 +5689,24 @@ nsCSSFrameConstructor::ConstructHTMLFrame(nsFrameConstructorState& aState, ProcessPseudoFrames(aState, aFrameItems); } isReplaced = PR_TRUE; - rv = NS_NewIsIndexFrame(mPresShell, &newFrame); + newFrame = NS_NewIsIndexFrame(mPresShell); + triedFrame = PR_TRUE; } else if (nsHTMLAtoms::canvas == aTag) { if (!aHasPseudoParent && !aState.mPseudoFrames.IsEmpty()) { ProcessPseudoFrames(aState, aFrameItems); } isReplaced = PR_TRUE; - rv = NS_NewHTMLCanvasFrame(mPresShell, &newFrame); + newFrame = NS_NewHTMLCanvasFrame(mPresShell); + triedFrame = PR_TRUE; } - if (NS_FAILED(rv) || !newFrame) + if (NS_UNLIKELY(triedFrame && !newFrame)) { + return NS_ERROR_OUT_OF_MEMORY; + } + else if (NS_FAILED(rv) || !newFrame) { return rv; + } // If we succeeded in creating a frame then initialize it, process its // children (if requested), and set the initial child list @@ -11101,8 +11116,8 @@ nsCSSFrameConstructor::CreateContinuingFrame(nsPresContext* aPresContext, } } else if (nsLayoutAtoms::imageFrame == frameType) { - rv = NS_NewImageFrame(shell, &newFrame); - if (NS_SUCCEEDED(rv)) { + newFrame = NS_NewImageFrame(shell); + if (NS_LIKELY(newFrame != nsnull)) { newFrame->Init(aPresContext, content, aParentFrame, styleContext, aFrame); } } else if (nsLayoutAtoms::placeholderFrame == frameType) { diff --git a/mozilla/layout/base/nsCSSFrameConstructor.h b/mozilla/layout/base/nsCSSFrameConstructor.h index b507887e240..0ea47515624 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.h +++ b/mozilla/layout/base/nsCSSFrameConstructor.h @@ -654,7 +654,7 @@ private: nsStyleContext* aStyleContext); // A function that can be invoked to create some sort of image frame. - typedef nsresult (* ImageFrameCreatorFunc)(nsIPresShell*, nsIFrame**); + typedef nsIFrame* (* ImageFrameCreatorFunc)(nsIPresShell*); /** * CreateHTMLImageFrame will do some tests on aContent, and if it determines diff --git a/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp b/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp index 2127b3ebc45..4f5ee1e9775 100644 --- a/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp +++ b/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp @@ -71,19 +71,10 @@ #include "nsIAccessibilityService.h" #endif -nsresult -NS_NewHTMLButtonControlFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) +nsIFrame* +NS_NewHTMLButtonControlFrame(nsIPresShell* aPresShell) { - NS_PRECONDITION(aNewFrame, "null OUT ptr"); - if (nsnull == aNewFrame) { - return NS_ERROR_NULL_POINTER; - } - nsHTMLButtonControlFrame* it = new (aPresShell) nsHTMLButtonControlFrame; - if (!it) { - return NS_ERROR_OUT_OF_MEMORY; - } - *aNewFrame = it; - return NS_OK; + return new (aPresShell) nsHTMLButtonControlFrame; } nsHTMLButtonControlFrame::nsHTMLButtonControlFrame() diff --git a/mozilla/layout/forms/nsImageControlFrame.cpp b/mozilla/layout/forms/nsImageControlFrame.cpp index a1f4d923a75..f23be69aa45 100644 --- a/mozilla/layout/forms/nsImageControlFrame.cpp +++ b/mozilla/layout/forms/nsImageControlFrame.cpp @@ -151,19 +151,10 @@ nsImageControlFrame::Destroy(nsPresContext *aPresContext) return nsImageControlFrameSuper::Destroy(aPresContext); } -nsresult -NS_NewImageControlFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) +nsIFrame* +NS_NewImageControlFrame(nsIPresShell* aPresShell) { - NS_PRECONDITION(aNewFrame, "null OUT ptr"); - if (nsnull == aNewFrame) { - return NS_ERROR_NULL_POINTER; - } - nsImageControlFrame* it = new (aPresShell) nsImageControlFrame; - if (!it) { - return NS_ERROR_OUT_OF_MEMORY; - } - *aNewFrame = it; - return NS_OK; + return new (aPresShell) nsImageControlFrame; } // Frames are not refcounted, no need to AddRef diff --git a/mozilla/layout/forms/nsIsIndexFrame.cpp b/mozilla/layout/forms/nsIsIndexFrame.cpp index a4a5f9d74b9..635689405df 100644 --- a/mozilla/layout/forms/nsIsIndexFrame.cpp +++ b/mozilla/layout/forms/nsIsIndexFrame.cpp @@ -82,19 +82,10 @@ static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID); -nsresult -NS_NewIsIndexFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) +nsIFrame* +NS_NewIsIndexFrame(nsIPresShell* aPresShell) { - NS_PRECONDITION(aNewFrame, "null OUT ptr"); - if (nsnull == aNewFrame) { - return NS_ERROR_NULL_POINTER; - } - nsIsIndexFrame* it = new (aPresShell) nsIsIndexFrame(); - if (!it) { - return NS_ERROR_OUT_OF_MEMORY; - } - *aNewFrame = it; - return NS_OK; + return new (aPresShell) nsIsIndexFrame(); } nsIsIndexFrame::nsIsIndexFrame() diff --git a/mozilla/layout/forms/nsLegendFrame.cpp b/mozilla/layout/forms/nsLegendFrame.cpp index 15ac0fb901e..5010cf06e81 100644 --- a/mozilla/layout/forms/nsLegendFrame.cpp +++ b/mozilla/layout/forms/nsLegendFrame.cpp @@ -55,19 +55,10 @@ static NS_DEFINE_IID(kLegendFrameCID, NS_LEGEND_FRAME_CID); -nsresult -NS_NewLegendFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) +nsIFrame* +NS_NewLegendFrame(nsIPresShell* aPresShell) { - NS_PRECONDITION(aNewFrame, "null OUT ptr"); - if (nsnull == aNewFrame) { - return NS_ERROR_NULL_POINTER; - } - nsLegendFrame* it = new (aPresShell) nsLegendFrame; - if (!it) { - return NS_ERROR_OUT_OF_MEMORY; - } - *aNewFrame = it; - return NS_OK; + return new (aPresShell) nsLegendFrame; } nsIAtom* diff --git a/mozilla/layout/forms/nsTextControlFrame.cpp b/mozilla/layout/forms/nsTextControlFrame.cpp index 3d144f04846..e040586b263 100644 --- a/mozilla/layout/forms/nsTextControlFrame.cpp +++ b/mozilla/layout/forms/nsTextControlFrame.cpp @@ -1223,19 +1223,10 @@ NS_IMETHODIMP nsTextInputSelectionImpl::GetFrameFromLevel(nsPresContext *aPresCo -nsresult -NS_NewTextControlFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) +nsIFrame* +NS_NewTextControlFrame(nsIPresShell* aPresShell) { - NS_PRECONDITION(aNewFrame, "null OUT ptr"); - if (nsnull == aNewFrame) { - return NS_ERROR_NULL_POINTER; - } - nsTextControlFrame* it = new (aPresShell) nsTextControlFrame(aPresShell); - if (!it) { - return NS_ERROR_OUT_OF_MEMORY; - } - *aNewFrame = it; - return NS_OK; + return new (aPresShell) nsTextControlFrame(aPresShell); } NS_IMPL_ADDREF_INHERITED(nsTextControlFrame, nsBoxFrame) diff --git a/mozilla/layout/generic/nsBRFrame.cpp b/mozilla/layout/generic/nsBRFrame.cpp index 740ae30834f..c3648d0defc 100644 --- a/mozilla/layout/generic/nsBRFrame.cpp +++ b/mozilla/layout/generic/nsBRFrame.cpp @@ -80,19 +80,10 @@ protected: virtual ~BRFrame(); }; -nsresult -NS_NewBRFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) +nsIFrame* +NS_NewBRFrame(nsIPresShell* aPresShell) { - NS_PRECONDITION(aNewFrame, "null OUT ptr"); - if (nsnull == aNewFrame) { - return NS_ERROR_NULL_POINTER; - } - nsIFrame* frame = new (aPresShell) BRFrame; - if (nsnull == frame) { - return NS_ERROR_OUT_OF_MEMORY; - } - *aNewFrame = frame; - return NS_OK; + return new (aPresShell) BRFrame; } BRFrame::~BRFrame() diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index 0fc2b588aaa..8741290f973 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -442,19 +442,10 @@ void SetFontFromStyle(nsIRenderingContext* aRC, nsStyleContext* aSC) aRC->SetFont(font->mFont, visibility->mLangGroup); } -nsresult -NS_NewEmptyFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) +nsIFrame* +NS_NewEmptyFrame(nsIPresShell* aPresShell) { - NS_PRECONDITION(aNewFrame, "null OUT ptr"); - if (nsnull == aNewFrame) { - return NS_ERROR_NULL_POINTER; - } - nsFrame* it = new (aPresShell) nsFrame; - if (nsnull == it) { - return NS_ERROR_OUT_OF_MEMORY; - } - *aNewFrame = it; - return NS_OK; + new (aPresShell) nsFrame; } MOZ_DECL_CTOR_COUNTER(nsFrame) diff --git a/mozilla/layout/generic/nsFrame.h b/mozilla/layout/generic/nsFrame.h index c3d93144005..5991f4bd6da 100644 --- a/mozilla/layout/generic/nsFrame.h +++ b/mozilla/layout/generic/nsFrame.h @@ -135,7 +135,7 @@ public: * Create a new "empty" frame that maps a given piece of content into a * 0,0 area. */ - friend nsresult NS_NewEmptyFrame(nsIPresShell* aShell, nsIFrame** aInstancePtrResult); + friend nsIFrame* NS_NewEmptyFrame(nsIPresShell* aShell); // Overloaded new operator. Initializes the memory to 0 and relies on an arena // (which comes from the presShell) to perform the allocation. diff --git a/mozilla/layout/generic/nsFrameSetFrame.cpp b/mozilla/layout/generic/nsFrameSetFrame.cpp index 990ec5c1a67..6b68ad00d99 100644 --- a/mozilla/layout/generic/nsFrameSetFrame.cpp +++ b/mozilla/layout/generic/nsFrameSetFrame.cpp @@ -408,9 +408,9 @@ nsHTMLFramesetFrame::Init(nsPresContext* aPresContext, kidSC = shell->StyleSet()->ResolveStyleFor(child, mStyleContext); if (tag == nsHTMLAtoms::frameset) { - result = NS_NewHTMLFramesetFrame(shell, &frame); - if (NS_FAILED(result)) - return result; + frame = NS_NewHTMLFramesetFrame(shell); + if (NS_UNLIKELY(!frame)) + return NS_ERROR_OUT_OF_MEMORY; mChildTypes[mChildCount] = FRAMESET; nsHTMLFramesetFrame* childFrame = (nsHTMLFramesetFrame*)frame; @@ -1571,19 +1571,10 @@ nsHTMLFramesetFrame::EndMouseDrag(nsPresContext* aPresContext) gDragInProgress = PR_FALSE; } -nsresult -NS_NewHTMLFramesetFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) +nsIFrame* +NS_NewHTMLFramesetFrame(nsIPresShell* aPresShell) { - NS_PRECONDITION(aNewFrame, "null OUT ptr"); - if (nsnull == aNewFrame) { - return NS_ERROR_NULL_POINTER; - } - nsHTMLFramesetFrame* it = new (aPresShell) nsHTMLFramesetFrame; - if (!it) { - return NS_ERROR_OUT_OF_MEMORY; - } - *aNewFrame = it; - return NS_OK; + return new (aPresShell) nsHTMLFramesetFrame; } /******************************************************************************* diff --git a/mozilla/layout/generic/nsHTMLCanvasFrame.cpp b/mozilla/layout/generic/nsHTMLCanvasFrame.cpp index 3a23587a767..3ffcc8ba9bb 100644 --- a/mozilla/layout/generic/nsHTMLCanvasFrame.cpp +++ b/mozilla/layout/generic/nsHTMLCanvasFrame.cpp @@ -44,15 +44,10 @@ #include "nsHTMLCanvasFrame.h" #include "nsICanvasElement.h" -nsresult -NS_NewHTMLCanvasFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) +nsIFrame* +NS_NewHTMLCanvasFrame(nsIPresShell* aPresShell) { - nsHTMLCanvasFrame* it = new (aPresShell) nsHTMLCanvasFrame; - if (nsnull == it) { - return NS_ERROR_OUT_OF_MEMORY; - } - *aNewFrame = it; - return NS_OK; + return new (aPresShell) nsHTMLCanvasFrame; } nsHTMLCanvasFrame::nsHTMLCanvasFrame() diff --git a/mozilla/layout/generic/nsHTMLCanvasFrame.h b/mozilla/layout/generic/nsHTMLCanvasFrame.h index a1402a8e7f2..47866a01c9d 100644 --- a/mozilla/layout/generic/nsHTMLCanvasFrame.h +++ b/mozilla/layout/generic/nsHTMLCanvasFrame.h @@ -46,7 +46,7 @@ #include "gfxIImageFrame.h" #include "imgIContainer.h" -nsresult NS_NewHTMLCanvasFrame (nsIPresShell* aPresShell, nsIFrame** aNewFrame); +nsIFrame* NS_NewHTMLCanvasFrame (nsIPresShell* aPresShell); class nsHTMLCanvasFrame : public nsSplittableFrame { diff --git a/mozilla/layout/generic/nsHTMLParts.h b/mozilla/layout/generic/nsHTMLParts.h index 70727f7e7f6..38208b11a64 100644 --- a/mozilla/layout/generic/nsHTMLParts.h +++ b/mozilla/layout/generic/nsHTMLParts.h @@ -138,8 +138,8 @@ NS_NewRelativeItemWrapperFrame(nsIPresShell* aPresShell) { return NS_NewAreaFrame(aPresShell, 0); } -nsresult -NS_NewBRFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame); +nsIFrame* +NS_NewBRFrame(nsIPresShell* aPresShell); nsresult NS_NewCommentFrame(nsIPresShell* aPresShell, nsIFrame** aFrameResult); @@ -148,32 +148,32 @@ NS_NewCommentFrame(nsIPresShell* aPresShell, nsIFrame** aFrameResult); nsIFrame* NS_NewSubDocumentFrame(nsIPresShell* aPresShell); //