Bug 1475351: Properly clear associated ShadowRoot from StyleSheet objects. r=smaug
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sat, 14 Jul 2018 16:06:03 +0200
changeset 426672 1ea3747437b7f17f3ca9e5b95b3020d3b7ac3056
parent 426671 0dfb0b5f6a95b67a8bf629f4740e5998002d2b9a
child 426673 ddb66025724b2ebae3b0d8493c0093e6fcfce1af
push id105282
push useremilio@crisal.io
push dateSun, 15 Jul 2018 10:38:25 +0000
treeherdermozilla-inbound@1ea3747437b7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1475351
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1475351: Properly clear associated ShadowRoot from StyleSheet objects. r=smaug Just like we do from the document's destructor. MozReview-Commit-ID: DygmZ0EI9es
dom/base/DocumentOrShadowRoot.cpp
dom/base/DocumentOrShadowRoot.h
dom/base/nsDocument.cpp
--- a/dom/base/DocumentOrShadowRoot.cpp
+++ b/dom/base/DocumentOrShadowRoot.cpp
@@ -20,16 +20,23 @@ DocumentOrShadowRoot::DocumentOrShadowRo
   , mKind(Kind::ShadowRoot)
 {}
 
 DocumentOrShadowRoot::DocumentOrShadowRoot(nsIDocument& aDoc)
   : mAsNode(aDoc)
   , mKind(Kind::Document)
 {}
 
+DocumentOrShadowRoot::~DocumentOrShadowRoot()
+{
+  for (StyleSheet* sheet : mStyleSheets) {
+    sheet->ClearAssociatedDocumentOrShadowRoot();
+  }
+}
+
 StyleSheetList&
 DocumentOrShadowRoot::EnsureDOMStyleSheets()
 {
   if (!mDOMStyleSheets) {
     mDOMStyleSheets = new StyleSheetList(*this);
   }
   return *mDOMStyleSheets;
 }
--- a/dom/base/DocumentOrShadowRoot.h
+++ b/dom/base/DocumentOrShadowRoot.h
@@ -95,17 +95,17 @@ public:
   already_AddRefed<nsContentList>
   GetElementsByTagNameNS(const nsAString& aNamespaceURI,
                          const nsAString& aLocalName,
                          mozilla::ErrorResult&);
 
   already_AddRefed<nsContentList>
   GetElementsByClassName(const nsAString& aClasses);
 
-  ~DocumentOrShadowRoot() = default;
+  ~DocumentOrShadowRoot();
 
   Element* GetPointerLockElement();
   Element* GetFullscreenElement();
 
   Element* ElementFromPoint(float aX, float aY);
   void ElementsFromPoint(float aX, float aY,
                          nsTArray<RefPtr<mozilla::dom::Element>>& aElements);
 
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -1679,25 +1679,22 @@ nsDocument::~nsDocument()
 
   for (uint32_t indx = mChildren.ChildCount(); indx-- != 0; ) {
     mChildren.ChildAt(indx)->UnbindFromTree();
     mChildren.RemoveChildAt(indx);
   }
   mFirstChild = nullptr;
   mCachedRootElement = nullptr;
 
-  // Let the stylesheets know we're going away
-  for (StyleSheet* sheet : mStyleSheets) {
-    sheet->ClearAssociatedDocumentOrShadowRoot();
-  }
   for (auto& sheets : mAdditionalSheets) {
     for (StyleSheet* sheet : sheets) {
       sheet->ClearAssociatedDocumentOrShadowRoot();
     }
   }
+
   if (mAttrStyleSheet) {
     mAttrStyleSheet->SetOwningDocument(nullptr);
   }
 
   if (mListenerManager) {
     mListenerManager->Disconnect();
     UnsetFlags(NODE_HAS_LISTENERMANAGER);
   }