Bug 1351286 - stylo: Make Servo mapped attributes mechanism cope with the document being in the bfcache. r=dbaron
authorCameron McCormack <cam@mcc.id.au>
Sat, 08 Apr 2017 22:42:43 +0800
changeset 559347 b06bd43117138b783ca95017f57e3c7dd0621311
parent 559346 c0aefd90ac6369eead7b5a5573060a2dc23c02e1
child 559348 a89729a1910cfe514e53c20a9137d25e01359a03
push id53058
push userarchaeopteryx@coole-files.de
push dateSun, 09 Apr 2017 21:36:26 +0000
reviewersdbaron
bugs1351286
milestone55.0a1
Bug 1351286 - stylo: Make Servo mapped attributes mechanism cope with the document being in the bfcache. r=dbaron MozReview-Commit-ID: H8tpBVKf3xo
layout/style/ServoStyleSet.cpp
layout/style/nsHTMLStyleSheet.cpp
layout/style/nsHTMLStyleSheet.h
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -192,17 +192,17 @@ ServoStyleSet::GetContext(already_AddRef
   }
   return result.forget();
 }
 
 void
 ServoStyleSet::ResolveMappedAttrDeclarationBlocks()
 {
   if (nsHTMLStyleSheet* sheet = mPresContext->Document()->GetAttributeStyleSheet()) {
-    sheet->CalculateMappedServoDeclarations();
+    sheet->CalculateMappedServoDeclarations(mPresContext);
   }
 
   mPresContext->Document()->ResolveScheduledSVGPresAttrs();
 }
 
 void
 ServoStyleSet::PreTraverseSync()
 {
--- a/layout/style/nsHTMLStyleSheet.cpp
+++ b/layout/style/nsHTMLStyleSheet.cpp
@@ -550,26 +550,28 @@ nsHTMLStyleSheet::DropMappedAttributes(n
 #endif
 
   mMappedAttrTable.Remove(aMapped);
 
   NS_ASSERTION(entryCount == mMappedAttrTable.EntryCount(), "not removed");
 }
 
 void
-nsHTMLStyleSheet::CalculateMappedServoDeclarations()
+nsHTMLStyleSheet::CalculateMappedServoDeclarations(nsPresContext* aPresContext)
 {
-  nsPresContext* presContext = mDocument->GetShell()->GetPresContext();
+  MOZ_ASSERT_IF(mDocument->GetShell(),
+                mDocument->GetShell()->GetPresContext() == aPresContext);
+
   for (auto iter = mMappedAttrTable.Iter(); !iter.Done(); iter.Next()) {
     MappedAttrTableEntry* attr = static_cast<MappedAttrTableEntry*>(iter.Get());
     if (attr->mAttributes->GetServoStyle()) {
       // Only handle cases which haven't been filled in already
       continue;
     }
-    attr->mAttributes->LazilyResolveServoDeclaration(presContext);
+    attr->mAttributes->LazilyResolveServoDeclaration(aPresContext);
   }
 }
 
 nsIStyleRule*
 nsHTMLStyleSheet::LangRuleFor(const nsString& aLanguage)
 {
   auto entry =
     static_cast<LangRuleTableEntry*>(mLangRuleTable.Add(&aLanguage, fallible));
--- a/layout/style/nsHTMLStyleSheet.h
+++ b/layout/style/nsHTMLStyleSheet.h
@@ -60,17 +60,17 @@ public:
 
   // Mapped Attribute management methods
   already_AddRefed<nsMappedAttributes>
     UniqueMappedAttributes(nsMappedAttributes* aMapped);
   void DropMappedAttributes(nsMappedAttributes* aMapped);
   // For each mapped presentation attribute in the cache, resolve
   // the attached ServoDeclarationBlock by running the mapping
   // and converting the ruledata to Servo specified values.
-  void CalculateMappedServoDeclarations();
+  void CalculateMappedServoDeclarations(nsPresContext* aPresContext);
 
   nsIStyleRule* LangRuleFor(const nsString& aLanguage);
 
 private: 
   nsHTMLStyleSheet(const nsHTMLStyleSheet& aCopy) = delete;
   nsHTMLStyleSheet& operator=(const nsHTMLStyleSheet& aCopy) = delete;
 
   ~nsHTMLStyleSheet() {}