From a9d5f524ee329612fccd7bc18314e26abe28db93 Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Thu, 21 Apr 2011 20:17:31 -0700 Subject: [PATCH] Remove null-checks of nsCSSParser, since construction is infallible. (Bug 542058, patch 1) r=bzbarsky Note that many callers already skipped the null-checks. --- content/base/src/nsGenericElement.cpp | 1 - content/base/src/nsStyledElement.cpp | 21 +++++++++---------- .../canvas/src/nsCanvasRenderingContext2D.cpp | 2 -- content/svg/content/src/nsSVGElement.cpp | 3 --- content/xul/content/src/nsXULElement.cpp | 1 - layout/style/Loader.cpp | 6 ------ layout/style/nsCSSParser.h | 5 ----- layout/style/nsCSSRules.cpp | 3 --- layout/style/nsCSSStyleSheet.cpp | 6 ------ layout/style/nsStyleAnimation.cpp | 3 +-- 10 files changed, 11 insertions(+), 40 deletions(-) diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 333131d9ec84..33ded5d7aea2 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -5469,7 +5469,6 @@ ParseSelectorList(nsINode* aNode, NS_ENSURE_STATE(doc); nsCSSParser parser(doc->CSSLoader()); - NS_ENSURE_TRUE(parser, NS_ERROR_OUT_OF_MEMORY); nsCSSSelectorList* selectorList; nsresult rv = parser.ParseSelectorString(aSelectorString, diff --git a/content/base/src/nsStyledElement.cpp b/content/base/src/nsStyledElement.cpp index 0ae2cbce8cb9..3c1a522db1f9 100644 --- a/content/base/src/nsStyledElement.cpp +++ b/content/base/src/nsStyledElement.cpp @@ -332,18 +332,17 @@ nsStyledElementNotElementCSSInlineStyle::ParseStyleAttribute(const nsAString& aV if (isCSS) { css::Loader* cssLoader = doc->CSSLoader(); nsCSSParser cssParser(cssLoader); - if (cssParser) { - nsCOMPtr baseURI = GetBaseURI(); - nsRefPtr rule; - cssParser.ParseStyleAttribute(aValue, doc->GetDocumentURI(), - baseURI, - NodePrincipal(), - getter_AddRefs(rule)); - if (rule) { - aResult.SetTo(rule, &aValue); - return; - } + nsCOMPtr baseURI = GetBaseURI(); + + nsRefPtr rule; + cssParser.ParseStyleAttribute(aValue, doc->GetDocumentURI(), + baseURI, + NodePrincipal(), + getter_AddRefs(rule)); + if (rule) { + aResult.SetTo(rule, &aValue); + return; } } } diff --git a/content/canvas/src/nsCanvasRenderingContext2D.cpp b/content/canvas/src/nsCanvasRenderingContext2D.cpp index 518eba6806e2..7555761d6895 100644 --- a/content/canvas/src/nsCanvasRenderingContext2D.cpp +++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp @@ -2210,7 +2210,6 @@ CreateFontStyleRule(const nsAString& aFont, // Pass the CSS Loader object to the parser, to allow parser error reports // to include the outer window ID. nsCSSParser parser(document->CSSLoader()); - NS_ENSURE_TRUE(parser, NS_ERROR_OUT_OF_MEMORY); nsresult rv = parser.ParseStyleAttribute(EmptyString(), docURL, baseURL, principal, getter_AddRefs(rule)); @@ -3680,7 +3679,6 @@ nsCanvasRenderingContext2D::DrawWindow(nsIDOMWindow* aWindow, float aX, float aY // Pass the CSS Loader object to the parser, to allow parser error reports // to include the outer window ID. nsCSSParser parser(elementDoc ? elementDoc->CSSLoader() : nsnull); - NS_ENSURE_TRUE(parser, NS_ERROR_OUT_OF_MEMORY); nsresult rv = parser.ParseColorString(PromiseFlatString(aBGColor), nsnull, 0, &bgColor); NS_ENSURE_SUCCESS(rv, rv); diff --git a/content/svg/content/src/nsSVGElement.cpp b/content/svg/content/src/nsSVGElement.cpp index 8eebed142c33..6818d4f9a215 100644 --- a/content/svg/content/src/nsSVGElement.cpp +++ b/content/svg/content/src/nsSVGElement.cpp @@ -1169,9 +1169,6 @@ MappedAttrParser::MappedAttrParser(css::Loader* aLoader, : mParser(aLoader), mDocURI(aDocURI), mBaseURI(aBaseURI), mNodePrincipal(aNodePrincipal), mDecl(nsnull) { - // mParser should successfully construct, now that we have infallible malloc. - NS_ABORT_IF_FALSE(mParser, "parser failed to initialize?"); - // SVG and CSS differ slightly in their interpretation of some of // the attributes. SVG allows attributes of the form: font-size="5" // (style="font-size: 5" if using a style attribute) diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index dafd9f7f3bc6..f81023df865a 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -2876,7 +2876,6 @@ nsXULPrototypeElement::SetAttrAt(PRUint32 aPos, const nsAString& aValue, nsRefPtr rule; nsCSSParser parser; - NS_ENSURE_TRUE(parser, NS_ERROR_OUT_OF_MEMORY); // XXX Get correct Base URI (need GetBaseURI on *prototype* element) parser.ParseStyleAttribute(aValue, aDocumentURI, aDocumentURI, diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index cde8f08d0e25..5af2cd3bcf64 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -1168,7 +1168,6 @@ Loader::PrepareSheet(nsCSSStyleSheet* aSheet, NS_ENSURE_TRUE(mediaList, NS_ERROR_OUT_OF_MEMORY); nsCSSParser mediumParser(this); - NS_ENSURE_TRUE(mediumParser, NS_ERROR_OUT_OF_MEMORY); // We have aMediaString only when linked from link elements, style // elements, or PIs, so pass PR_TRUE. @@ -1575,11 +1574,6 @@ Loader::ParseSheet(nsIUnicharInputStream* aStream, aCompleted = PR_FALSE; nsCSSParser parser(this, aLoadData->mSheet); - if (!parser) { - LOG_ERROR((" Failed to get CSS parser")); - SheetComplete(aLoadData, NS_ERROR_OUT_OF_MEMORY); - return NS_ERROR_OUT_OF_MEMORY; - } // Push our load data on the stack so any kids can pick it up mParsingDatas.AppendElement(aLoadData); diff --git a/layout/style/nsCSSParser.h b/layout/style/nsCSSParser.h index 7832a111b9f9..696ea1b331ad 100644 --- a/layout/style/nsCSSParser.h +++ b/layout/style/nsCSSParser.h @@ -81,11 +81,6 @@ private: nsCSSParser& operator=(nsCSSParser const&); public: - // If this is false, memory allocation failed in the constructor - // and all other methods will crash. - operator bool() const - { return !!mImpl; } - // Set a style sheet for the parser to fill in. The style sheet must // implement the nsCSSStyleSheet interface. Null can be passed in to clear // out an existing stylesheet reference. diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 5ae3d7cdd17a..55cb92bfaf57 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -1895,7 +1895,6 @@ NS_IMETHODIMP nsCSSKeyframeRule::SetKeyText(const nsAString& aKeyText) { nsCSSParser parser; - NS_ENSURE_TRUE(parser, NS_ERROR_OUT_OF_MEMORY); nsTArray newSelectors; // FIXME: pass filename and line number @@ -2059,7 +2058,6 @@ nsCSSKeyframesRule::InsertRule(const nsAString& aRule) // which also turns out to match WebKit: // http://lists.w3.org/Archives/Public/www-style/2011Apr/0034.html nsCSSParser parser; - NS_ENSURE_TRUE(parser, NS_OK); // FIXME: pass filename and line number nsRefPtr rule = @@ -2078,7 +2076,6 @@ PRUint32 nsCSSKeyframesRule::FindRuleIndexForKey(const nsAString& aKey) { nsCSSParser parser; - NS_ENSURE_TRUE(parser, RULE_NOT_FOUND); nsTArray keys; // FIXME: pass filename and line number diff --git a/layout/style/nsCSSStyleSheet.cpp b/layout/style/nsCSSStyleSheet.cpp index 30e4e0e1cfae..398e5993971d 100644 --- a/layout/style/nsCSSStyleSheet.cpp +++ b/layout/style/nsCSSStyleSheet.cpp @@ -577,7 +577,6 @@ nsresult nsMediaList::SetText(const nsAString& aMediaText) { nsCSSParser parser; - NS_ENSURE_TRUE(parser, NS_ERROR_OUT_OF_MEMORY); PRBool htmlMode = PR_FALSE; if (mStyleSheet) { @@ -1781,8 +1780,6 @@ nsCSSStyleSheet::InsertRuleInternal(const nsAString& aRule, } nsCSSParser css(loader, this); - if (!css) - return NS_ERROR_OUT_OF_MEMORY; mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE); @@ -1991,9 +1988,6 @@ nsCSSStyleSheet::InsertRuleIntoGroup(const nsAString & aRule, } nsCSSParser css(loader, this); - if (!css) { - return NS_ERROR_OUT_OF_MEMORY; - } // parse and grab the rule mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE); diff --git a/layout/style/nsStyleAnimation.cpp b/layout/style/nsStyleAnimation.cpp index a2f807cb69fe..6beea45e3909 100644 --- a/layout/style/nsStyleAnimation.cpp +++ b/layout/style/nsStyleAnimation.cpp @@ -1807,8 +1807,7 @@ BuildStyleRule(nsCSSProperty aProperty, // Get a parser, parse the property, and check for CSS parsing errors. // If any of these steps fails, we bail out and delete the declaration. - if (!parser || - NS_FAILED(parser.ParseProperty(aProperty, aSpecifiedValue, + if (NS_FAILED(parser.ParseProperty(aProperty, aSpecifiedValue, doc->GetDocumentURI(), baseURI, aTargetElement->NodePrincipal(), declaration, &changed, PR_FALSE)) ||