Bug 1361235 - Part 1: Clear ServoElementData from doomed NAC before adding the script runner that would destroy it. r?emilio draft
authorCameron McCormack <cam@mcc.id.au>
Thu, 11 May 2017 18:03:02 +0800
changeset 576184 8cce388c9bbdb4b51a4d02d349ab227f34ea93d4
parent 576183 cd1dbc4bf4a87afc2f90cfcc28e3a92ef1a89c3e
child 576185 590eec76664b2ca46b85bcdfd753d4550189dc4e
push id58271
push userbmo:cam@mcc.id.au
push dateThu, 11 May 2017 11:23:16 +0000
reviewersemilio
bugs1361235
milestone55.0a1
Bug 1361235 - Part 1: Clear ServoElementData from doomed NAC before adding the script runner that would destroy it. r?emilio MozReview-Commit-ID: KqJelGoA4NU
dom/base/nsContentUtils.cpp
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -215,16 +215,17 @@
 #include "mozilla/EnumSet.h"
 #include "mozilla/BloomFilter.h"
 #include "TabChild.h"
 #include "mozilla/dom/DocGroup.h"
 #include "mozilla/dom/TabGroup.h"
 #include "nsIWebNavigationInfo.h"
 #include "nsPluginHost.h"
 #include "mozilla/HangAnnotations.h"
+#include "mozilla/ServoRestyleManager.h"
 
 #include "nsIBidiKeyboard.h"
 
 #if defined(XP_WIN)
 // Undefine LoadImage to prevent naming conflict with Windows.
 #undef LoadImage
 #endif
 
@@ -5299,25 +5300,37 @@ private:
   nsCOMPtr<nsIContent> mParent;
 };
 
 /* static */
 void
 nsContentUtils::DestroyAnonymousContent(nsCOMPtr<nsIContent>* aContent)
 {
   if (*aContent) {
+    // Don't wait until UnbindFromTree to clear ServoElementData, since
+    // leak checking at shutdown can run before the AnonymousContentDestroyer
+    // runs.
+    if ((*aContent)->IsStyledByServo() && (*aContent)->IsElement()) {
+      ServoRestyleManager::ClearServoDataFromSubtree((*aContent)->AsElement());
+    }
     AddScriptRunner(new AnonymousContentDestroyer(aContent));
   }
 }
 
 /* static */
 void
 nsContentUtils::DestroyAnonymousContent(nsCOMPtr<Element>* aElement)
 {
   if (*aElement) {
+    // Don't wait until UnbindFromTree to clear ServoElementData, since
+    // leak checking at shutdown can run before the AnonymousContentDestroyer
+    // runs.
+    if ((*aElement)->IsStyledByServo()) {
+      ServoRestyleManager::ClearServoDataFromSubtree(*aElement);
+    }
     AddScriptRunner(new AnonymousContentDestroyer(aElement));
   }
 }
 
 /* static */
 void
 nsContentUtils::NotifyInstalledMenuKeyboardListener(bool aInstalling)
 {