Bug 1497940 - Fix an assertion in XULDocument::AddSubtreeToDocument. r=smaug
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 29 Oct 2018 14:26:09 +0100
changeset 443414 ed31fa097a650aa8e8f119584b516af3b2c388ac
parent 443413 4eaa5f13d23184e6f8b2c22d4cbe31e98f5b630d
child 443415 4fb88c6c2223597c9acf26f6e2e07b9fa1d83d3d
push id34956
push userrgurzau@mozilla.com
push dateTue, 30 Oct 2018 05:30:29 +0000
treeherdermozilla-central@6e4537056d53 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1497940
milestone65.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 1497940 - Fix an assertion in XULDocument::AddSubtreeToDocument. r=smaug We notify the document when appending to a connected shadow root, that assertion doesn't really hold.
dom/xul/XULDocument.cpp
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -602,17 +602,28 @@ XULDocument::AddElementToDocumentPost(El
     }
 
     return NS_OK;
 }
 
 nsresult
 XULDocument::AddSubtreeToDocument(nsIContent* aContent)
 {
-    NS_ASSERTION(aContent->GetUncomposedDoc() == this, "Element not in doc!");
+    MOZ_ASSERT(aContent->GetComposedDoc() == this, "Element not in doc!");
+
+    // If the content is not in the document, it must be in a shadow tree.
+    //
+    // The shadow root itself takes care of maintaining the ID tables and such,
+    // and there's no use case for localization links in shadow trees, or at
+    // least they don't work in regular HTML documents either as of today so...
+    if (MOZ_UNLIKELY(!aContent->IsInUncomposedDoc())) {
+        MOZ_ASSERT(aContent->IsInShadowTree());
+        return NS_OK;
+    }
+
     // From here on we only care about elements.
     Element* aElement = Element::FromNode(aContent);
     if (!aElement) {
         return NS_OK;
     }
 
     // Do pre-order addition magic
     nsresult rv = AddElementToDocumentPre(aElement);