Bug 1474466: Properly clear associated ShadowRoot from StyleSheet objects. r=smaug
☠☠ backed out by 0dfb0b5f6a95 ☠ ☠
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sat, 14 Jul 2018 16:06:03 +0200
changeset 481774 e0841c88d3aeafebc016d894802b2a6e287b7be8
parent 481767 2a8f94a45fd3f898cb63c54b8df662f8ad1f7527
child 481775 0dfb0b5f6a95b67a8bf629f4740e5998002d2b9a
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1474466
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 1474466: 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);
   }