Bug 1420547: Add assertions for the assumptions we're making. r=bz
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 11 Dec 2017 10:14:36 +0100
changeset 397087 24e90541f05637a7399f705bbce71bb12bfb5813
parent 397086 04a9c149d299878293af6551518e0eb42df11f18
child 397088 6e443911baf01e082d846c571170db7106083a01
push id57264
push userecoal95@gmail.com
push dateThu, 21 Dec 2017 03:01:09 +0000
treeherderautoland@24e90541f056 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1420547
milestone59.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 1420547: Add assertions for the assumptions we're making. r=bz MozReview-Commit-ID: 8CVtclXLgzH
dom/base/nsNodeUtils.cpp
--- a/dom/base/nsNodeUtils.cpp
+++ b/dom/base/nsNodeUtils.cpp
@@ -43,25 +43,33 @@ using namespace mozilla::dom;
 using mozilla::AutoJSContext;
 
 enum class IsRemoveNotification
 {
   Yes,
   No,
 };
 
+#ifdef DEBUG
+#define COMPOSED_DOC_DECL \
+  const bool wasInComposedDoc = !!node->GetComposedDoc();
+#else
+#define COMPOSED_DOC_DECL
+#endif
+
 // This macro expects the ownerDocument of content_ to be in scope as
 // |nsIDocument* doc|
 #define IMPL_MUTATION_NOTIFICATION(func_, content_, params_, remove_)       \
   PR_BEGIN_MACRO                                                            \
   bool needsEnterLeave = doc->MayHaveDOMMutationObservers();                \
   if (needsEnterLeave) {                                                    \
     nsDOMMutationObserver::EnterMutationHandling();                         \
   }                                                                         \
   nsINode* node = content_;                                                 \
+  COMPOSED_DOC_DECL                                                         \
   NS_ASSERTION(node->OwnerDoc() == doc, "Bogus document");                  \
   if (remove_ == IsRemoveNotification::Yes && node->GetComposedDoc()) {     \
     if (nsIPresShell* shell = doc->GetObservingShell()) {                   \
       shell->func_ params_;                                                 \
     }                                                                       \
   }                                                                         \
   doc->BindingManager()->func_ params_;                                     \
   nsINode* last;                                                            \
@@ -74,16 +82,22 @@ enum class IsRemoveNotification
     }                                                                       \
     last = node;                                                            \
     if (ShadowRoot* shadow = ShadowRoot::FromNode(node)) {                  \
       node = shadow->GetHost();                                             \
     } else {                                                                \
       node = node->GetParentNode();                                         \
     }                                                                       \
   } while (node);                                                           \
+  /* Whitelist NativeAnonymousChildListChange removal notifications from    \
+   * the assertion since it runs from UnbindFromTree, and thus we don't     \
+   * reach the document, but doesn't matter. */                             \
+  MOZ_ASSERT((last == doc) == wasInComposedDoc ||                           \
+             (remove_ == IsRemoveNotification::Yes &&                       \
+              !strcmp(#func_, "NativeAnonymousChildListChange")));          \
   if (remove_ == IsRemoveNotification::No && last == doc) {                 \
     if (nsIPresShell* shell = doc->GetObservingShell()) {                   \
       shell->func_ params_;                                                 \
     }                                                                       \
   }                                                                         \
   if (needsEnterLeave) {                                                    \
     nsDOMMutationObserver::LeaveMutationHandling();                         \
   }                                                                         \
@@ -181,19 +195,21 @@ nsNodeUtils::ContentAppended(nsIContent*
                              IsRemoveNotification::No);
 }
 
 void
 nsNodeUtils::NativeAnonymousChildListChange(nsIContent* aContent,
                                             bool aIsRemove)
 {
   nsIDocument* doc = aContent->OwnerDoc();
+  auto isRemove = aIsRemove
+    ? IsRemoveNotification::Yes : IsRemoveNotification::No;
   IMPL_MUTATION_NOTIFICATION(NativeAnonymousChildListChange, aContent,
                             (doc, aContent, aIsRemove),
-                            IsRemoveNotification::No);
+                            isRemove);
 }
 
 void
 nsNodeUtils::ContentInserted(nsINode* aContainer,
                              nsIContent* aChild)
 {
   NS_PRECONDITION(aContainer->IsContent() ||
                   aContainer->IsNodeOfType(nsINode::eDOCUMENT),