Bug 781032 - Fix a crash in CSSParserImpl::SetDefaultNamespaceOnSelector by creating the nsCSSParser at a valid spot. r=bz
authorThaddee Tyl <thaddee.tyl@gmail.com>
Wed, 05 Sep 2012 19:10:55 -0400
changeset 104723 c6768c151b64763a0fdf87b2105b27bcc99d7709
parent 104722 1cc49d5dcff4faaca357226dcfcfb6da56ac0bef
child 104724 72c85979e852baa371bb8a79920e55a1f33b7679
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersbz
bugs781032
milestone18.0a1
Bug 781032 - Fix a crash in CSSParserImpl::SetDefaultNamespaceOnSelector by creating the nsCSSParser at a valid spot. r=bz
layout/style/nsCSSParser.cpp
layout/style/nsCSSStyleSheet.cpp
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -786,16 +786,18 @@ CSSParserImpl::SetStyleSheet(nsCSSStyleS
     // Switch to using the new sheet, if any
     mGroupStack.Clear();
     mSheet = aSheet;
     if (mSheet) {
       mNameSpaceMap = mSheet->GetNameSpaceMap();
     } else {
       mNameSpaceMap = nullptr;
     }
+  } else if (mSheet) {
+    mNameSpaceMap = mSheet->GetNameSpaceMap();
   }
 
   return NS_OK;
 }
 
 nsresult
 CSSParserImpl::SetQuirkMode(bool aQuirkMode)
 {
--- a/layout/style/nsCSSStyleSheet.cpp
+++ b/layout/style/nsCSSStyleSheet.cpp
@@ -2129,18 +2129,16 @@ nsCSSStyleSheet::ParseSheet(const nsAStr
   nsRefPtr<css::Loader> loader;
   if (mDocument) {
     loader = mDocument->CSSLoader();
     NS_ASSERTION(loader, "Document with no CSS loader!");
   } else {
     loader = new css::Loader();
   }
 
-  nsCSSParser parser(loader, this);
-
   mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true);
 
   nsresult rv = WillDirty();
   NS_ENSURE_SUCCESS(rv, rv);
 
   // detach existing rules (including child sheets via import rules)
   int ruleCount;
   while ((ruleCount = mInner->mOrderedRules.Count()) != 0) {
@@ -2158,16 +2156,18 @@ nsCSSStyleSheet::ParseSheet(const nsAStr
     child->mParent = nullptr;
     child->mDocument = nullptr;
   }
   mInner->mFirstChild = nullptr;
   mInner->mNameSpaceMap = nullptr;
 
   // allow unsafe rules if the style sheet's principal is the system principal
   bool allowUnsafeRules = nsContentUtils::IsSystemPrincipal(mInner->mPrincipal);
+
+  nsCSSParser parser(loader, this);
   rv = parser.ParseSheet(aInput, mInner->mSheetURI, mInner->mBaseURI,
                          mInner->mPrincipal, 1, allowUnsafeRules);
   DidDirty(); // we are always 'dirty' here since we always remove rules first
   NS_ENSURE_SUCCESS(rv, rv);
 
   // notify document of all new rules
   if (mDocument) {
     for (int32_t index = 0; index < mInner->mOrderedRules.Count(); ++index) {