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 426670 e0841c88d3aeafebc016d894802b2a6e287b7be8
parent 426669 2a8f94a45fd3f898cb63c54b8df662f8ad1f7527
child 426671 0dfb0b5f6a95b67a8bf629f4740e5998002d2b9a
push id105280
push useremilio@crisal.io
push dateSun, 15 Jul 2018 10:28:04 +0000
treeherdermozilla-inbound@e0841c88d3ae [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);
   }