Remove null-checks of nsCSSParser, since construction is infallible. (Bug 542058, patch 1) r=bzbarsky

Note that many callers already skipped the null-checks.
This commit is contained in:
L. David Baron 2011-04-21 20:17:31 -07:00
parent 6242cc7dee
commit a9d5f524ee
10 changed files with 11 additions and 40 deletions

View File

@ -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,

View File

@ -332,18 +332,17 @@ nsStyledElementNotElementCSSInlineStyle::ParseStyleAttribute(const nsAString& aV
if (isCSS) {
css::Loader* cssLoader = doc->CSSLoader();
nsCSSParser cssParser(cssLoader);
if (cssParser) {
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
nsRefPtr<css::StyleRule> rule;
cssParser.ParseStyleAttribute(aValue, doc->GetDocumentURI(),
baseURI,
NodePrincipal(),
getter_AddRefs(rule));
if (rule) {
aResult.SetTo(rule, &aValue);
return;
}
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
nsRefPtr<css::StyleRule> rule;
cssParser.ParseStyleAttribute(aValue, doc->GetDocumentURI(),
baseURI,
NodePrincipal(),
getter_AddRefs(rule));
if (rule) {
aResult.SetTo(rule, &aValue);
return;
}
}
}

View File

@ -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);

View File

@ -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)

View File

@ -2876,7 +2876,6 @@ nsXULPrototypeElement::SetAttrAt(PRUint32 aPos, const nsAString& aValue,
nsRefPtr<css::StyleRule> 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,

View File

@ -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);

View File

@ -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.

View File

@ -1895,7 +1895,6 @@ NS_IMETHODIMP
nsCSSKeyframeRule::SetKeyText(const nsAString& aKeyText)
{
nsCSSParser parser;
NS_ENSURE_TRUE(parser, NS_ERROR_OUT_OF_MEMORY);
nsTArray<float> 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<nsCSSKeyframeRule> rule =
@ -2078,7 +2076,6 @@ PRUint32
nsCSSKeyframesRule::FindRuleIndexForKey(const nsAString& aKey)
{
nsCSSParser parser;
NS_ENSURE_TRUE(parser, RULE_NOT_FOUND);
nsTArray<float> keys;
// FIXME: pass filename and line number

View File

@ -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);

View File

@ -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)) ||