diff --git a/content/html/content/src/nsGenericHTMLElement.h b/content/html/content/src/nsGenericHTMLElement.h index 74c9808c6de..0aaff53d3b2 100644 --- a/content/html/content/src/nsGenericHTMLElement.h +++ b/content/html/content/src/nsGenericHTMLElement.h @@ -977,36 +977,17 @@ protected: * A macro to implement the NS_NewHTMLXXXElement() functions. */ #define NS_IMPL_NS_NEW_HTML_ELEMENT(_elementName) \ -nsresult \ -NS_NewHTML##_elementName##Element(nsIHTMLContent **aResult, \ - nsINodeInfo *aNodeInfo, \ - PRBool aFromParser) \ +nsIHTMLContent* \ +NS_NewHTML##_elementName##Element(nsINodeInfo *aNodeInfo, PRBool aFromParser)\ { \ - nsIHTMLContent *it = new nsHTML##_elementName##Element(aNodeInfo); \ - if (!it) { \ - return NS_ERROR_OUT_OF_MEMORY; \ - } \ - \ - NS_ADDREF(*aResult = it); \ - \ - return NS_OK; \ + return new nsHTML##_elementName##Element(aNodeInfo); \ } #define NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(_elementName) \ -nsresult \ -NS_NewHTML##_elementName##Element(nsIHTMLContent **aResult, \ - nsINodeInfo *aNodeInfo, \ - PRBool aFromParser) \ +nsIHTMLContent* \ +NS_NewHTML##_elementName##Element(nsINodeInfo *aNodeInfo, PRBool aFromParser)\ { \ - nsIHTMLContent *it = new nsHTML##_elementName##Element(aNodeInfo, \ - aFromParser); \ - if (!it) { \ - return NS_ERROR_OUT_OF_MEMORY; \ - } \ - \ - NS_ADDREF(*aResult = it); \ - \ - return NS_OK; \ + return new nsHTML##_elementName##Element(aNodeInfo, aFromParser); \ } /** @@ -1189,200 +1170,59 @@ nsHTML##_elementName##Element::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) \ // Element class factory methods -nsresult -NS_NewHTMLSharedElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); +#define NS_DECLARE_NS_NEW_HTML_ELEMENT(_elementName) \ +nsIHTMLContent* \ +NS_NewHTML##_elementName##Element(nsINodeInfo *aNodeInfo, \ + PRBool aFromParser = PR_FALSE); -nsresult -NS_NewHTMLAnchorElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLAppletElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLAreaElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLBRElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLBodyElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLButtonElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLModElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLDivElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLFieldSetElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLFontElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLFormElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLFrameElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLFrameSetElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLHRElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLHeadElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLHeadingElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLHtmlElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLIFrameElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLImageElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLInputElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLLIElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLLabelElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLLegendElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLLinkElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLMapElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLMetaElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLSharedListElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLObjectElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLOptGroupElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLOptionElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLParagraphElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLPreElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLScriptElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLSelectElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLSpanElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLStyleElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLTableCaptionElement(nsIHTMLContent** aResult,nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLTableCellElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLTableColElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLTableElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLTableRowElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLTableSectionElement(nsIHTMLContent** aResult,nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLTbodyElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLTextAreaElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLTfootElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLTheadElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLTitleElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); - -nsresult -NS_NewHTMLUnknownElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser = PR_FALSE); +NS_DECLARE_NS_NEW_HTML_ELEMENT(Shared) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Anchor) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Applet) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Area) +NS_DECLARE_NS_NEW_HTML_ELEMENT(BR) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Body) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Button) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Mod) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Div) +NS_DECLARE_NS_NEW_HTML_ELEMENT(FieldSet) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Font) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Form) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Frame) +NS_DECLARE_NS_NEW_HTML_ELEMENT(FrameSet) +NS_DECLARE_NS_NEW_HTML_ELEMENT(HR) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Head) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Heading) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Html) +NS_DECLARE_NS_NEW_HTML_ELEMENT(IFrame) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Image) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Input) +NS_DECLARE_NS_NEW_HTML_ELEMENT(LI) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Label) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Legend) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Link) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Map) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Meta) +NS_DECLARE_NS_NEW_HTML_ELEMENT(SharedList) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Object) +NS_DECLARE_NS_NEW_HTML_ELEMENT(OptGroup) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Option) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Paragraph) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Pre) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Script) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Select) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Span) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Style) +NS_DECLARE_NS_NEW_HTML_ELEMENT(TableCaption) +NS_DECLARE_NS_NEW_HTML_ELEMENT(TableCell) +NS_DECLARE_NS_NEW_HTML_ELEMENT(TableCol) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Table) +NS_DECLARE_NS_NEW_HTML_ELEMENT(TableRow) +NS_DECLARE_NS_NEW_HTML_ELEMENT(TableSection) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Tbody) +NS_DECLARE_NS_NEW_HTML_ELEMENT(TextArea) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Tfoot) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Thead) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Title) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Unknown) #endif /* nsGenericHTMLElement_h___ */ diff --git a/content/html/content/src/nsHTMLFormElement.cpp b/content/html/content/src/nsHTMLFormElement.cpp index 013cf9b701e..05706e9a08a 100644 --- a/content/html/content/src/nsHTMLFormElement.cpp +++ b/content/html/content/src/nsHTMLFormElement.cpp @@ -397,29 +397,24 @@ ShouldBeInElements(nsIFormControl* aFormControl) // nsHTMLFormElement implementation // construction, destruction -nsresult -NS_NewHTMLFormElement(nsIHTMLContent** aInstancePtrResult, - nsINodeInfo *aNodeInfo, PRBool aFromParser) +nsIHTMLContent* +NS_NewHTMLFormElement(nsINodeInfo *aNodeInfo, PRBool aFromParser) { nsHTMLFormElement* it = new nsHTMLFormElement(aNodeInfo); if (!it) { - return NS_ERROR_OUT_OF_MEMORY; + return nsnull; } nsresult rv = it->Init(); if (NS_FAILED(rv)) { delete it; - - return rv; + return nsnull; } - NS_ADDREF(*aInstancePtrResult = it); - - return rv; + return it; } - nsHTMLFormElement::nsHTMLFormElement(nsINodeInfo *aNodeInfo) : nsGenericHTMLElement(aNodeInfo), mGeneratingSubmit(PR_FALSE), diff --git a/content/html/content/src/nsHTMLImageElement.cpp b/content/html/content/src/nsHTMLImageElement.cpp index 96a518d6d24..c0df8de1b2d 100644 --- a/content/html/content/src/nsHTMLImageElement.cpp +++ b/content/html/content/src/nsHTMLImageElement.cpp @@ -153,9 +153,8 @@ protected: nsSize GetWidthHeight(); }; -nsresult -NS_NewHTMLImageElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser) +nsIHTMLContent* +NS_NewHTMLImageElement(nsINodeInfo *aNodeInfo, PRBool aFromParser) { /* * nsHTMLImageElement's will be created without a nsINodeInfo passed in @@ -167,25 +166,18 @@ NS_NewHTMLImageElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, if (!nodeInfo) { nsCOMPtr doc = do_QueryInterface(nsContentUtils::GetDocumentFromCaller()); - NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED); + NS_ENSURE_TRUE(doc, nsnull); nsINodeInfoManager *nodeInfoManager = doc->GetNodeInfoManager(); - NS_ENSURE_TRUE(nodeInfoManager, NS_ERROR_UNEXPECTED); + NS_ENSURE_TRUE(nodeInfoManager, nsnull); rv = nodeInfoManager->GetNodeInfo(nsHTMLAtoms::img, nsnull, kNameSpaceID_None, getter_AddRefs(nodeInfo)); - NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_SUCCESS(rv, nsnull); } - nsHTMLImageElement* it = new nsHTMLImageElement(nodeInfo); - if (!it) { - return NS_ERROR_OUT_OF_MEMORY; - } - - NS_ADDREF(*aResult = it); - - return NS_OK; + return new nsHTMLImageElement(nodeInfo); } nsHTMLImageElement::nsHTMLImageElement(nsINodeInfo *aNodeInfo) diff --git a/content/html/content/src/nsHTMLOptionElement.cpp b/content/html/content/src/nsHTMLOptionElement.cpp index 0f79d541877..98ed3951474 100644 --- a/content/html/content/src/nsHTMLOptionElement.cpp +++ b/content/html/content/src/nsHTMLOptionElement.cpp @@ -151,9 +151,8 @@ protected: PRPackedBool mIsSelected; }; -nsresult -NS_NewHTMLOptionElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser) +nsIHTMLContent* +NS_NewHTMLOptionElement(nsINodeInfo *aNodeInfo, PRBool aFromParser) { /* * nsHTMLOptionElement's will be created without a nsINodeInfo passed in @@ -165,28 +164,20 @@ NS_NewHTMLOptionElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, if (!nodeInfo) { nsCOMPtr doc = do_QueryInterface(nsContentUtils::GetDocumentFromCaller()); - NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED); + NS_ENSURE_TRUE(doc, nsnull); nsINodeInfoManager *nodeInfoManager = doc->GetNodeInfoManager(); - NS_ENSURE_TRUE(nodeInfoManager, NS_ERROR_UNEXPECTED); + NS_ENSURE_TRUE(nodeInfoManager, nsnull); rv = nodeInfoManager->GetNodeInfo(nsHTMLAtoms::option, nsnull, kNameSpaceID_None, getter_AddRefs(nodeInfo)); - NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_SUCCESS(rv, nsnull); } - nsIHTMLContent* it = new nsHTMLOptionElement(nodeInfo); - if (!it) { - return NS_ERROR_OUT_OF_MEMORY; - } - - NS_ADDREF(*aResult = it); - - return NS_OK; + return new nsHTMLOptionElement(nodeInfo); } - nsHTMLOptionElement::nsHTMLOptionElement(nsINodeInfo *aNodeInfo) : nsGenericHTMLElement(aNodeInfo), mIsInitialized(PR_FALSE), diff --git a/content/html/content/src/nsHTMLSelectElement.cpp b/content/html/content/src/nsHTMLSelectElement.cpp index 49eecdc51c3..ce95713db1e 100644 --- a/content/html/content/src/nsHTMLSelectElement.cpp +++ b/content/html/content/src/nsHTMLSelectElement.cpp @@ -1049,13 +1049,14 @@ nsHTMLSelectElement::SetLength(PRUint32 aLength) } } else if (aLength) { // This violates the W3C DOM but we do this for backwards compatibility - nsCOMPtr element; nsCOMPtr nodeInfo; mNodeInfo->NameChanged(nsHTMLAtoms::option, getter_AddRefs(nodeInfo)); - rv = NS_NewHTMLOptionElement(getter_AddRefs(element), nodeInfo); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr element = NS_NewHTMLOptionElement(nodeInfo); + if (!element) { + return NS_ERROR_OUT_OF_MEMORY; + } nsCOMPtr text; rv = NS_NewTextNode(getter_AddRefs(text)); diff --git a/content/html/content/src/nsHTMLTableElement.cpp b/content/html/content/src/nsHTMLTableElement.cpp index d31dbcc79ae..8935bede2d1 100644 --- a/content/html/content/src/nsHTMLTableElement.cpp +++ b/content/html/content/src/nsHTMLTableElement.cpp @@ -518,14 +518,13 @@ nsHTMLTableElement::CreateTHead(nsIDOMHTMLElement** aValue) } else { // create a new head rowgroup - nsCOMPtr newHead; nsCOMPtr nodeInfo; mNodeInfo->NameChanged(nsHTMLAtoms::thead, getter_AddRefs(nodeInfo)); - rv = NS_NewHTMLTableSectionElement(getter_AddRefs(newHead),nodeInfo); + nsCOMPtr newHead = NS_NewHTMLTableSectionElement(nodeInfo); - if (NS_SUCCEEDED(rv) && newHead) { + if (newHead) { nsCOMPtr child; rv = GetFirstChild(getter_AddRefs(child)); @@ -575,14 +574,12 @@ nsHTMLTableElement::CreateTFoot(nsIDOMHTMLElement** aValue) } else { // create a new foot rowgroup - nsCOMPtr newFoot; - nsCOMPtr nodeInfo; mNodeInfo->NameChanged(nsHTMLAtoms::tfoot, getter_AddRefs(nodeInfo)); - rv = NS_NewHTMLTableSectionElement(getter_AddRefs(newFoot),nodeInfo); + nsCOMPtr newFoot = NS_NewHTMLTableSectionElement(nodeInfo); - if (NS_SUCCEEDED(rv) && newFoot) { + if (newFoot) { rv = AppendChildTo(newFoot, PR_TRUE, PR_FALSE); CallQueryInterface(newFoot, aValue); } @@ -622,14 +619,12 @@ nsHTMLTableElement::CreateCaption(nsIDOMHTMLElement** aValue) } else { // create a new head rowgroup - nsCOMPtr newCaption; - nsCOMPtr nodeInfo; mNodeInfo->NameChanged(nsHTMLAtoms::caption, getter_AddRefs(nodeInfo)); - rv = NS_NewHTMLTableCaptionElement(getter_AddRefs(newCaption),nodeInfo); + nsCOMPtr newCaption = NS_NewHTMLTableCaptionElement(nodeInfo); - if (NS_SUCCEEDED(rv) && newCaption) { + if (newCaption) { rv = AppendChildTo(newCaption, PR_TRUE, PR_FALSE); CallQueryInterface(newCaption, aValue); } @@ -699,15 +694,12 @@ nsHTMLTableElement::InsertRow(PRInt32 aIndex, nsIDOMHTMLElement** aValue) refRow->GetParentNode(getter_AddRefs(parent)); // create the row - - nsCOMPtr newRow; - nsCOMPtr nodeInfo; mNodeInfo->NameChanged(nsHTMLAtoms::tr, getter_AddRefs(nodeInfo)); - rv = NS_NewHTMLTableRowElement(getter_AddRefs(newRow), nodeInfo); + nsCOMPtr newRow = NS_NewHTMLTableRowElement(nodeInfo); - if (NS_SUCCEEDED(rv) && newRow) { + if (newRow) { nsCOMPtr newRowNode(do_QueryInterface(newRow)); nsCOMPtr retChild; @@ -749,15 +741,13 @@ nsHTMLTableElement::InsertRow(PRInt32 aIndex, nsIDOMHTMLElement** aValue) } if (!rowGroup) { // need to create a TBODY - nsCOMPtr newRowGroup; - nsCOMPtr nodeInfo; mNodeInfo->NameChanged(nsHTMLAtoms::tbody, getter_AddRefs(nodeInfo)); - rv = NS_NewHTMLTableSectionElement(getter_AddRefs(newRowGroup), - nodeInfo); + nsCOMPtr newRowGroup + = NS_NewHTMLTableSectionElement(nodeInfo); - if (NS_SUCCEEDED(rv) && newRowGroup) { + if (newRowGroup) { rv = AppendChildTo(newRowGroup, PR_TRUE, PR_FALSE); rowGroup = do_QueryInterface(newRowGroup); @@ -765,12 +755,10 @@ nsHTMLTableElement::InsertRow(PRInt32 aIndex, nsIDOMHTMLElement** aValue) } if (rowGroup) { - nsCOMPtr newRow; - nsCOMPtr nodeInfo; mNodeInfo->NameChanged(nsHTMLAtoms::tr, getter_AddRefs(nodeInfo)); - rv = NS_NewHTMLTableRowElement(getter_AddRefs(newRow), nodeInfo); + nsCOMPtr newRow = NS_NewHTMLTableRowElement(nodeInfo); if (newRow) { nsCOMPtr firstRow; diff --git a/content/html/content/src/nsHTMLTableRowElement.cpp b/content/html/content/src/nsHTMLTableRowElement.cpp index ed1e5fa3e97..782cf56c789 100644 --- a/content/html/content/src/nsHTMLTableRowElement.cpp +++ b/content/html/content/src/nsHTMLTableRowElement.cpp @@ -305,16 +305,17 @@ nsHTMLTableRowElement::InsertCell(PRInt32 aIndex, nsIDOMHTMLElement** aValue) nsCOMPtr nodeInfo; mNodeInfo->NameChanged(nsHTMLAtoms::td, getter_AddRefs(nodeInfo)); - nsCOMPtr cellContent; - nsresult rv = NS_NewHTMLTableCellElement(getter_AddRefs(cellContent), - nodeInfo); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr cellContent = NS_NewHTMLTableCellElement(nodeInfo); + if (!cellContent) { + return NS_ERROR_OUT_OF_MEMORY; + } nsCOMPtr cellNode(do_QueryInterface(cellContent)); NS_ASSERTION(cellNode, "Should implement nsIDOMNode!"); nsCOMPtr retChild; + nsresult rv; if (doInsert) { nsCOMPtr refCell; cells->Item(aIndex, getter_AddRefs(refCell)); diff --git a/content/html/content/src/nsHTMLTableSectionElement.cpp b/content/html/content/src/nsHTMLTableSectionElement.cpp index c686fbfc572..1a32c6c3597 100644 --- a/content/html/content/src/nsHTMLTableSectionElement.cpp +++ b/content/html/content/src/nsHTMLTableSectionElement.cpp @@ -168,16 +168,17 @@ nsHTMLTableSectionElement::InsertRow(PRInt32 aIndex, nsCOMPtr nodeInfo; mNodeInfo->NameChanged(nsHTMLAtoms::tr, getter_AddRefs(nodeInfo)); - nsCOMPtr rowContent; - nsresult rv = NS_NewHTMLTableRowElement(getter_AddRefs(rowContent), - nodeInfo); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr rowContent = NS_NewHTMLTableRowElement(nodeInfo); + if (!nodeInfo) { + return NS_ERROR_OUT_OF_MEMORY; + } nsCOMPtr rowNode(do_QueryInterface(rowContent)); NS_ASSERTION(rowNode, "Should implement nsIDOMNode!"); nsCOMPtr retChild; + nsresult rv; if (doInsert) { nsCOMPtr refRow; rows->Item(aIndex, getter_AddRefs(refRow)); diff --git a/content/html/document/src/nsHTMLContentSink.cpp b/content/html/document/src/nsHTMLContentSink.cpp index f44a7f264f2..c1e8df1dda9 100644 --- a/content/html/document/src/nsHTMLContentSink.cpp +++ b/content/html/document/src/nsHTMLContentSink.cpp @@ -179,15 +179,13 @@ static PRLogModuleInfo* gSinkLogModuleInfo; // sampling the clock too often. #define NS_MAX_TOKENS_DEFLECTED_IN_LOW_FREQ_MODE 200 -typedef nsresult (*contentCreatorCallback)(nsIHTMLContent**, nsINodeInfo*, - PRBool aFromParser); +typedef nsIHTMLContent* (*contentCreatorCallback)(nsINodeInfo*, PRBool aFromParser); -nsresult -NS_NewHTMLNOTUSEDElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aFromParser) +nsIHTMLContent* +NS_NewHTMLNOTUSEDElement(nsINodeInfo *aNodeInfo, PRBool aFromParser) { NS_NOTREACHED("The element ctor should never be called"); - return NS_ERROR_FAILURE; + return nsnull; } #define HTML_TAG(_tag, _classname) NS_NewHTML##_classname##Element, @@ -286,10 +284,10 @@ protected: nsresult AddAttributes(const nsIParserNode& aNode, nsIHTMLContent* aContent, PRBool aNotify = PR_FALSE, PRBool aCheckIfPresent = PR_FALSE); - nsresult CreateContentObject(const nsIParserNode& aNode, nsHTMLTag aNodeType, - nsIDOMHTMLFormElement* aForm, - nsIDocShell* aDocShell, - nsIHTMLContent** aResult); + already_AddRefed + CreateContentObject(const nsIParserNode& aNode, nsHTMLTag aNodeType, + nsIDOMHTMLFormElement* aForm, + nsIDocShell* aDocShell); inline PRInt32 GetNotificationInterval() { @@ -859,20 +857,19 @@ SetForm(nsIHTMLContent* aContent, nsIDOMHTMLFormElement* aForm) formControl->SetForm(aForm); } -static nsresult +static already_AddRefed MakeContentObject(nsHTMLTag aNodeType, nsINodeInfo *aNodeInfo, - nsIDOMHTMLFormElement* aForm, nsIHTMLContent** aResult, + nsIDOMHTMLFormElement* aForm, PRBool aInsideNoXXXTag, PRBool aFromParser); /** * Factory subroutine to create all of the html content objects. */ -nsresult +already_AddRefed HTMLContentSink::CreateContentObject(const nsIParserNode& aNode, nsHTMLTag aNodeType, nsIDOMHTMLFormElement* aForm, - nsIDocShell* aDocShell, - nsIHTMLContent** aResult) + nsIDocShell* aDocShell) { nsresult rv = NS_OK; @@ -897,7 +894,7 @@ HTMLContentSink::CreateContentObject(const nsIParserNode& aNode, } } - NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_SUCCESS(rv, nsnull); // XXX if the parser treated the text in a textarea like a normal // textnode we wouldn't need to do this. @@ -905,7 +902,7 @@ HTMLContentSink::CreateContentObject(const nsIParserNode& aNode, if (aNodeType == eHTMLTag_textarea) { nsCOMPtr dtd; mParser->GetDTD(getter_AddRefs(dtd)); - NS_ENSURE_TRUE(dtd, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(dtd, nsnull); PRInt32 lineNo = 0; @@ -913,8 +910,11 @@ HTMLContentSink::CreateContentObject(const nsIParserNode& aNode, } // Make the content object - rv = MakeContentObject(aNodeType, nodeInfo, aForm, aResult, - !!mInsideNoXXXTag, PR_TRUE); + nsIHTMLContent* result = MakeContentObject(aNodeType, nodeInfo, aForm, + !!mInsideNoXXXTag, PR_TRUE).get(); + if (!result) { + return nsnull; + } if (aNodeType == eHTMLTag_textarea && !mSkippedContent.IsEmpty()) { // XXX: if the parser treated the text in a textarea like a normal @@ -936,7 +936,7 @@ HTMLContentSink::CreateContentObject(const nsIParserNode& aNode, ++start; } - nsCOMPtr ta(do_QueryInterface(*aResult)); + nsCOMPtr ta(do_QueryInterface(result)); NS_ASSERTION(ta, "Huh? text area doesn't implement " "nsIDOMHTMLTextAreaElement?"); @@ -947,17 +947,14 @@ HTMLContentSink::CreateContentObject(const nsIParserNode& aNode, mSkippedContent.Truncate(); } - (*aResult)->SetContentID(mDocument->GetAndIncrementContentID()); + result->SetContentID(mDocument->GetAndIncrementContentID()); - return rv; + return result; } nsresult -NS_CreateHTMLElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, - PRBool aCaseSensitive) +NS_CreateHTMLElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, PRBool aCaseSensitive) { - nsresult rv = NS_OK; - nsIParserService* parserService = nsContentUtils::GetParserServiceWeakRef(); if (!parserService) return NS_ERROR_OUT_OF_MEMORY; @@ -974,8 +971,8 @@ NS_CreateHTMLElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, } if (aCaseSensitive) { - rv = MakeContentObject(nsHTMLTag(id), aNodeInfo, nsnull, - aResult, PR_FALSE, PR_FALSE); + *aResult = MakeContentObject(nsHTMLTag(id), aNodeInfo, nsnull, + PR_FALSE, PR_FALSE).get(); } else { // Revese map id to name to get the correct character case in // the tag name. @@ -991,18 +988,18 @@ NS_CreateHTMLElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo, if (!name->Equals(nsDependentString(tag))) { nsCOMPtr atom = do_GetAtom(tag); - rv = aNodeInfo->NameChanged(atom, getter_AddRefs(kungFuDeathGrip)); - NS_ENSURE_SUCCESS(rv, rv); + nsresult rv = aNodeInfo->NameChanged(atom, getter_AddRefs(kungFuDeathGrip)); + NS_ENSURE_SUCCESS(rv, nsnull); nodeInfo = kungFuDeathGrip; } } - rv = MakeContentObject(nsHTMLTag(id), nodeInfo, nsnull, aResult, - PR_FALSE, PR_FALSE); + *aResult = MakeContentObject(nsHTMLTag(id), nodeInfo, nsnull, + PR_FALSE, PR_FALSE).get(); } - return rv; + return *aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } //---------------------------------------------------------------------- @@ -1063,29 +1060,37 @@ nsHTMLElementFactory::CreateInstanceByTag(nsINodeInfo *aNodeInfo, return rv; } -nsresult +already_AddRefed MakeContentObject(nsHTMLTag aNodeType, nsINodeInfo *aNodeInfo, - nsIDOMHTMLFormElement* aForm, nsIHTMLContent** aResult, + nsIDOMHTMLFormElement* aForm, PRBool aInsideNoXXXTag, PRBool aFromParser) { if (aNodeType == eHTMLTag_form) { if (aForm) { // the form was already created - return CallQueryInterface(aForm, aResult); + nsIHTMLContent* result; + CallQueryInterface(aForm, &result); + return result; } - return NS_NewHTMLFormElement(aResult, aNodeInfo); + nsIHTMLContent* result = NS_NewHTMLFormElement(aNodeInfo); + NS_IF_ADDREF(result); + return result; } - nsresult rv; contentCreatorCallback cb = sContentCreatorCallbacks[aNodeType]; NS_ASSERTION(cb != NS_NewHTMLNOTUSEDElement, "Don't know how to construct tag element!"); - rv = cb(aResult, aNodeInfo, aFromParser); + nsIHTMLContent* result = cb(aNodeInfo, aFromParser); + if (!result) { + return nsnull; + } - if (NS_SUCCEEDED(rv) && !aInsideNoXXXTag) { + NS_ADDREF(result); + + if (!aInsideNoXXXTag) { switch (aNodeType) { case eHTMLTag_button: case eHTMLTag_fieldset: @@ -1095,14 +1100,14 @@ MakeContentObject(nsHTMLTag aNodeType, nsINodeInfo *aNodeInfo, case eHTMLTag_input: case eHTMLTag_select: case eHTMLTag_textarea: - SetForm(*aResult, aForm); + SetForm(result, aForm); break; default: break; } } - return rv; + return result; } //---------------------------------------------------------------------- @@ -1258,12 +1263,14 @@ SinkContext::OpenContainer(const nsIParserNode& aNode) // Create new container content object nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType()); - nsIHTMLContent* content; nsIDocShell *docshell = nsnull; if (mSink->mFrameset) docshell = (nsIDocShell *) mSink->mDocShell; - rv = mSink->CreateContentObject(aNode, nodeType, mSink->mCurrentForm, - docshell, &content); - NS_ENSURE_SUCCESS(rv, rv); + nsIHTMLContent* content = + mSink->CreateContentObject(aNode, nodeType, mSink->mCurrentForm, + docshell).get(); + if (!content) { + return NS_ERROR_OUT_OF_MEMORY; + } mStack[mStackPos].mType = nodeType; mStack[mStackPos].mContent = content; @@ -1505,11 +1512,10 @@ SinkContext::AddLeaf(const nsIParserNode& aNode) // Create new leaf content object nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType()); - nsCOMPtr content; - rv = mSink->CreateContentObject(aNode, nodeType, - mSink->mCurrentForm, mSink->mDocShell, - getter_AddRefs(content)); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr content = + mSink->CreateContentObject(aNode, nodeType, + mSink->mCurrentForm, mSink->mDocShell); + NS_ENSURE_TRUE(content, NS_ERROR_OUT_OF_MEMORY); // Set the content's document content->SetDocument(mSink->mDocument, PR_FALSE, PR_TRUE); @@ -2202,12 +2208,13 @@ HTMLContentSink::Init(nsIDocument* aDoc, CallQueryInterface(doc_root, &mRoot); } else { - rv = NS_NewHTMLHtmlElement(&mRoot, nodeInfo); - if (NS_FAILED(rv)) { + mRoot = NS_NewHTMLHtmlElement(nodeInfo); + if (!mRoot) { MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Init()\n")); MOZ_TIMER_STOP(mWatch); - return rv; + return NS_ERROR_OUT_OF_MEMORY; } + NS_ADDREF(mRoot); mRoot->SetDocument(mDocument, PR_FALSE, PR_TRUE); mDocument->SetRootContent(mRoot); @@ -2219,12 +2226,13 @@ HTMLContentSink::Init(nsIDocument* aDoc, getter_AddRefs(nodeInfo)); NS_ENSURE_SUCCESS(rv, rv); - rv = NS_NewHTMLHeadElement(&mHead, nodeInfo); + mHead = NS_NewHTMLHeadElement(nodeInfo); if (NS_FAILED(rv)) { MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Init()\n")); MOZ_TIMER_STOP(mWatch); - return rv; + return NS_ERROR_OUT_OF_MEMORY; } + NS_ADDREF(mHead); mRoot->AppendChildTo(mHead, PR_FALSE, PR_FALSE); @@ -2874,9 +2882,10 @@ HTMLContentSink::OpenForm(const nsIParserNode& aNode) getter_AddRefs(nodeInfo)); NS_ENSURE_SUCCESS(result, result); - nsCOMPtr content; - result = NS_NewHTMLFormElement(getter_AddRefs(content), nodeInfo); - NS_ENSURE_SUCCESS(result, result); + nsCOMPtr content = NS_NewHTMLFormElement(nodeInfo); + if (!content) { + return NS_ERROR_OUT_OF_MEMORY; + } mCurrentForm = do_QueryInterface(content); @@ -3206,9 +3215,10 @@ HTMLContentSink::SetDocumentTitle(const nsAString& aTitle) getter_AddRefs(nodeInfo)); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr it; - rv = NS_NewHTMLTitleElement(getter_AddRefs(it), nodeInfo); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr it = NS_NewHTMLTitleElement(nodeInfo); + if (!it) { + return NS_ERROR_OUT_OF_MEMORY; + } nsCOMPtr text; rv = NS_NewTextNode(getter_AddRefs(text)); @@ -3748,11 +3758,10 @@ HTMLContentSink::ProcessAREATag(const nsIParserNode& aNode) nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType()); - nsCOMPtr area; - nsresult rv = CreateContentObject(aNode, nodeType, nsnull, nsnull, - getter_AddRefs(area)); - if (NS_FAILED(rv)) { - return rv; + nsCOMPtr area = + CreateContentObject(aNode, nodeType, nsnull, nsnull); + if (!area) { + return NS_ERROR_OUT_OF_MEMORY; } // Set the content's document @@ -3765,7 +3774,7 @@ HTMLContentSink::ProcessAREATag(const nsIParserNode& aNode) AddBaseTagInfo(area); // Set the content's attributes - rv = AddAttributes(aNode, area); + nsresult rv = AddAttributes(aNode, area); NS_ENSURE_SUCCESS(rv, rv); // Add AREA object to the current map @@ -4037,9 +4046,10 @@ HTMLContentSink::ProcessMETATag(const nsIParserNode& aNode) getter_AddRefs(nodeInfo)); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr it; - rv = NS_NewHTMLMetaElement(getter_AddRefs(it), nodeInfo); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr it = NS_NewHTMLMetaElement(nodeInfo); + if (!it) { + return NS_ERROR_OUT_OF_MEMORY; + } it->SetContentID(mDocument->GetAndIncrementContentID()); diff --git a/content/html/document/src/nsHTMLFragmentContentSink.cpp b/content/html/document/src/nsHTMLFragmentContentSink.cpp index 63a063789e6..c460057f97f 100644 --- a/content/html/document/src/nsHTMLFragmentContentSink.cpp +++ b/content/html/document/src/nsHTMLFragmentContentSink.cpp @@ -312,10 +312,11 @@ nsHTMLFragmentContentSink::SetTitle(const nsString& aValue) kNameSpaceID_None, getter_AddRefs(nodeInfo)); if(NS_SUCCEEDED(result)) { - nsCOMPtr content=nsnull; - result = NS_NewHTMLTitleElement(getter_AddRefs(content), nodeInfo); + nsCOMPtr content = NS_NewHTMLTitleElement(nodeInfo); - if (NS_SUCCEEDED(result)) { + if (!content) { + result = NS_ERROR_OUT_OF_MEMORY; + } else { nsIContent *parent = GetCurrentContent(); if (nsnull == parent) { diff --git a/content/html/document/src/nsImageDocument.cpp b/content/html/document/src/nsImageDocument.cpp index 422f645a589..f835960c67e 100644 --- a/content/html/document/src/nsImageDocument.cpp +++ b/content/html/document/src/nsImageDocument.cpp @@ -485,10 +485,9 @@ nsImageDocument::CreateSyntheticDocument() getter_AddRefs(nodeInfo)); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr image; - rv = NS_NewHTMLImageElement(getter_AddRefs(image), nodeInfo); - if (NS_FAILED(rv)) { - return rv; + nsCOMPtr image = NS_NewHTMLImageElement(nodeInfo); + if (!image) { + return NS_ERROR_OUT_OF_MEMORY; } image->SetDocument(this, PR_FALSE, PR_TRUE); mImageElement = do_QueryInterface(image); diff --git a/content/html/document/src/nsMediaDocument.cpp b/content/html/document/src/nsMediaDocument.cpp index 6218c24ef02..536837527af 100644 --- a/content/html/document/src/nsMediaDocument.cpp +++ b/content/html/document/src/nsMediaDocument.cpp @@ -239,10 +239,9 @@ nsMediaDocument::CreateSyntheticDocument() getter_AddRefs(nodeInfo)); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr root; - rv = NS_NewHTMLHtmlElement(getter_AddRefs(root), nodeInfo); - if (NS_FAILED(rv)) { - return rv; + nsCOMPtr root = NS_NewHTMLHtmlElement(nodeInfo); + if (!root) { + return NS_ERROR_OUT_OF_MEMORY; } root->SetDocument(this, PR_FALSE, PR_TRUE); SetRootContent(root); @@ -252,10 +251,9 @@ nsMediaDocument::CreateSyntheticDocument() getter_AddRefs(nodeInfo)); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr body; - rv = NS_NewHTMLBodyElement(getter_AddRefs(body), nodeInfo); - if (NS_FAILED(rv)) { - return rv; + nsCOMPtr body = NS_NewHTMLBodyElement(nodeInfo); + if (!body) { + return NS_ERROR_OUT_OF_MEMORY; } body->SetDocument(this, PR_FALSE, PR_TRUE); mBodyContent = do_QueryInterface(body); diff --git a/content/html/document/src/nsPluginDocument.cpp b/content/html/document/src/nsPluginDocument.cpp index e5f12f3a252..e4529b7f61f 100644 --- a/content/html/document/src/nsPluginDocument.cpp +++ b/content/html/document/src/nsPluginDocument.cpp @@ -175,9 +175,9 @@ nsPluginDocument::CreateSyntheticPluginDocument() kNameSpaceID_None, getter_AddRefs(nodeInfo)); NS_ENSURE_SUCCESS(rv, rv); - rv = NS_NewHTMLSharedElement(getter_AddRefs(mPluginContent), nodeInfo); - if (NS_FAILED(rv)) { - return rv; + mPluginContent = NS_NewHTMLSharedElement(nodeInfo); + if (!mPluginContent) { + return NS_ERROR_OUT_OF_MEMORY; } mPluginContent->SetDocument(this, PR_FALSE, PR_TRUE); diff --git a/layout/build/nsContentDLF.cpp b/layout/build/nsContentDLF.cpp index 3d9410ccc00..3d131d49960 100644 --- a/layout/build/nsContentDLF.cpp +++ b/layout/build/nsContentDLF.cpp @@ -342,22 +342,22 @@ nsContentDLF::CreateBlankDocument(nsILoadGroup *aLoadGroup, nsIDocument **aDocum nsCOMPtr htmlNodeInfo; // generate an html html element - nsCOMPtr htmlElement; nim->GetNodeInfo(nsHTMLAtoms::html, 0, kNameSpaceID_None, getter_AddRefs(htmlNodeInfo)); - NS_NewHTMLHtmlElement(getter_AddRefs(htmlElement), htmlNodeInfo); + nsCOMPtr htmlElement + = NS_NewHTMLHtmlElement(htmlNodeInfo); // generate an html head element - nsCOMPtr headElement; nim->GetNodeInfo(nsHTMLAtoms::head, 0, kNameSpaceID_None, getter_AddRefs(htmlNodeInfo)); - NS_NewHTMLHeadElement(getter_AddRefs(headElement), htmlNodeInfo); + nsCOMPtr headElement + = NS_NewHTMLHeadElement(htmlNodeInfo); // generate an html body element - nsCOMPtr bodyElement; nim->GetNodeInfo(nsHTMLAtoms::body, 0, kNameSpaceID_None, getter_AddRefs(htmlNodeInfo)); - NS_NewHTMLBodyElement(getter_AddRefs(bodyElement), htmlNodeInfo); + nsCOMPtr bodyElement + = NS_NewHTMLBodyElement(htmlNodeInfo); // blat in the structure if (htmlElement && headElement && bodyElement) { diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index 8b760c8d675..ce5e0e1a8ae 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -644,10 +644,11 @@ CreateHTMLImgElement(nsISupports* aOuter, REFNSIID aIID, void** aResult) *aResult = nsnull; if (aOuter) return NS_ERROR_NO_AGGREGATION; - nsIHTMLContent* inst; // Note! NS_NewHTMLImageElement is special cased to handle a null nodeinfo - nsresult rv = NS_NewHTMLImageElement(&inst, nsnull); - if (NS_SUCCEEDED(rv)) { + nsIHTMLContent* inst = NS_NewHTMLImageElement(nsnull); + nsresult rv = NS_ERROR_OUT_OF_MEMORY; + if (inst) { + NS_ADDREF(inst); rv = inst->QueryInterface(aIID, aResult); NS_RELEASE(inst); } @@ -694,10 +695,11 @@ CreateHTMLOptionElement(nsISupports* aOuter, REFNSIID aIID, void** aResult) *aResult = nsnull; if (aOuter) return NS_ERROR_NO_AGGREGATION; - nsIHTMLContent* inst; // Note! NS_NewHTMLOptionElement is special cased to handle a null nodeinfo - nsresult rv = NS_NewHTMLOptionElement(&inst, nsnull); - if (NS_SUCCEEDED(rv)) { + nsIHTMLContent* inst = NS_NewHTMLOptionElement(nsnull); + nsresult rv = NS_ERROR_OUT_OF_MEMORY; + if (inst) { + NS_ADDREF(inst); rv = inst->QueryInterface(aIID, aResult); NS_RELEASE(inst); }