Backed out changeset c15e59678a60 (bug 1017896) for reftest failures
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Wed, 04 Jun 2014 08:55:59 +0200
changeset 205692 24743a3a0f9158f48bd21c7cfc4c0958048e8747
parent 205691 7b6a7a038a3c314df76ed8036be3df8a38cdbee9
child 205693 8f0e194a29430c0081ce44c046794248899ba876
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1017896
milestone32.0a1
backs outc15e59678a6036e9e3db78e0ae6460581a4da8f6
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
Backed out changeset c15e59678a60 (bug 1017896) for reftest failures
content/base/src/nsDocument.cpp
content/html/content/src/HTMLTemplateElement.cpp
content/html/content/src/HTMLTemplateElement.h
dom/tests/mochitest/webcomponents/mochitest.ini
dom/tests/mochitest/webcomponents/test_bug1017896.html
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -4508,21 +4508,16 @@ nsDocument::SetScriptGlobalObject(nsIScr
   }
 
   // Set our visibility state, but do not fire the event.  This is correct
   // because either we're coming out of bfcache (in which case IsVisible() will
   // still test false at this point and no state change will happen) or we're
   // doing the initial document load and don't want to fire the event for this
   // change.
   mVisibilityState = GetVisibilityState();
-
-  // The global in the template contents owner document should be the same.
-  if (mTemplateContentsOwner && mTemplateContentsOwner != this) {
-    mTemplateContentsOwner->SetScriptGlobalObject(aScriptGlobalObject);
-  }
 }
 
 nsIScriptGlobalObject*
 nsDocument::GetScriptHandlingObjectInternal() const
 {
   MOZ_ASSERT(!mScriptGlobalObject,
              "Do not call this when mScriptGlobalObject is set!");
   if (mHasHadDefaultView) {
@@ -9443,16 +9438,17 @@ nsDocument::GetCurrentContentSink()
 
 nsIDocument*
 nsDocument::GetTemplateContentsOwner()
 {
   if (!mTemplateContentsOwner) {
     bool hasHadScriptObject = true;
     nsIScriptGlobalObject* scriptObject =
       GetScriptHandlingObject(hasHadScriptObject);
+    NS_ENSURE_TRUE(scriptObject || !hasHadScriptObject, nullptr);
 
     nsCOMPtr<nsIDOMDocument> domDocument;
     nsresult rv = NS_NewDOMDocument(getter_AddRefs(domDocument),
                                     EmptyString(), // aNamespaceURI
                                     EmptyString(), // aQualifiedName
                                     nullptr, // aDoctype
                                     nsIDocument::GetDocumentURI(),
                                     nsIDocument::GetDocBaseURI(),
@@ -9460,26 +9456,22 @@ nsDocument::GetTemplateContentsOwner()
                                     true, // aLoadedAsData
                                     scriptObject, // aEventObject
                                     DocumentFlavorHTML);
     NS_ENSURE_SUCCESS(rv, nullptr);
 
     mTemplateContentsOwner = do_QueryInterface(domDocument);
     NS_ENSURE_TRUE(mTemplateContentsOwner, nullptr);
 
-    nsDocument* doc = static_cast<nsDocument*>(mTemplateContentsOwner.get());
-    doc->mHasHadScriptHandlingObject = hasHadScriptObject;
-
-    if (!scriptObject) {
-      mTemplateContentsOwner->SetScopeObject(GetScopeObject());
-    }
+    mTemplateContentsOwner->SetScriptHandlingObject(scriptObject);
 
     // Set |doc| as the template contents owner of itself so that
     // |doc| is the template contents owner of template elements created
     // by |doc|.
+    nsDocument* doc = static_cast<nsDocument*>(mTemplateContentsOwner.get());
     doc->mTemplateContentsOwner = doc;
   }
 
   return mTemplateContentsOwner;
 }
 
 void
 nsDocument::RegisterHostObjectUri(const nsACString& aUri)
--- a/content/html/content/src/HTMLTemplateElement.cpp
+++ b/content/html/content/src/HTMLTemplateElement.cpp
@@ -6,33 +6,51 @@
 #include "mozilla/dom/HTMLTemplateElement.h"
 #include "mozilla/dom/HTMLTemplateElementBinding.h"
 
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsIAtom.h"
 #include "nsRuleData.h"
 
-NS_IMPL_NS_NEW_HTML_ELEMENT(Template)
+using namespace mozilla::dom;
+
+nsGenericHTMLElement*
+NS_NewHTMLTemplateElement(already_AddRefed<nsINodeInfo>&& aNodeInfo,
+                          FromParser aFromParser)
+{
+  HTMLTemplateElement* it = new HTMLTemplateElement(aNodeInfo);
+  nsresult rv = it->Init();
+  if (NS_FAILED(rv)) {
+    delete it;
+    return nullptr;
+  }
+
+  return it;
+}
 
 namespace mozilla {
 namespace dom {
 
 HTMLTemplateElement::HTMLTemplateElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
   SetHasWeirdParserInsertionMode();
+}
 
+nsresult
+HTMLTemplateElement::Init()
+{
   nsIDocument* contentsOwner = OwnerDoc()->GetTemplateContentsOwner();
-  if (!contentsOwner) {
-    MOZ_CRASH("There should always be a template contents owner.");
-  }
+  NS_ENSURE_TRUE(contentsOwner, NS_ERROR_UNEXPECTED);
 
   mContent = contentsOwner->CreateDocumentFragment();
   mContent->SetHost(this);
+
+  return NS_OK;
 }
 
 HTMLTemplateElement::~HTMLTemplateElement()
 {
   if (mContent) {
     mContent->SetHost(nullptr);
   }
 }
@@ -54,17 +72,17 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_
                                                   nsGenericHTMLElement)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mContent)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 // QueryInterface implementation for HTMLTemplateElement
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(HTMLTemplateElement)
 NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement)
 
-NS_IMPL_ELEMENT_CLONE(HTMLTemplateElement)
+NS_IMPL_ELEMENT_CLONE_WITH_INIT(HTMLTemplateElement)
 
 JSObject*
 HTMLTemplateElement::WrapNode(JSContext *aCx)
 {
   return HTMLTemplateElementBinding::Wrap(aCx, this);
 }
 
 } // namespace dom
--- a/content/html/content/src/HTMLTemplateElement.h
+++ b/content/html/content/src/HTMLTemplateElement.h
@@ -23,16 +23,18 @@ public:
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLTemplateElement,
                                            nsGenericHTMLElement)
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
 
+  nsresult Init();
+
   DocumentFragment* Content()
   {
     return mContent;
   }
 
 protected:
   virtual JSObject* WrapNode(JSContext *aCx) MOZ_OVERRIDE;
 
--- a/dom/tests/mochitest/webcomponents/mochitest.ini
+++ b/dom/tests/mochitest/webcomponents/mochitest.ini
@@ -1,14 +1,13 @@
 [DEFAULT]
 support-files =
   inert_style.css
 
 [test_bug900724.html]
-[test_bug1017896.html]
 [test_content_element.html]
 [test_nested_content_element.html]
 [test_dest_insertion_points.html]
 [test_dest_insertion_points_shadow.html]
 [test_fallback_dest_insertion_points.html]
 [test_dynamic_content_element_matching.html]
 [test_document_register.html]
 [test_document_register_base_queue.html]
deleted file mode 100644
--- a/dom/tests/mochitest/webcomponents/test_bug1017896.html
+++ /dev/null
@@ -1,32 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=1017896
--->
-<head>
-  <title>Test template element in stale document.</title>
-  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-</head>
-<body>
-<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1017896">Bug 1017896</a>
-<div id="container"></div>
-<script>
-
-SimpleTest.waitForExplicitFinish();
-
-var frame = document.createElement("iframe");
-document.getElementById("container").appendChild(frame);
-
-var staleFrameDoc = frame.contentDocument;
-
-setTimeout(function() {
-  var v = staleFrameDoc.createElement("div");
-  v.innerHTML = "<template>Content</template>";
-  is(v.firstChild.content.childNodes.length, 1, "Template should have one child in template content.");
-  SimpleTest.finish();
-}, 0);
-
-</script>
-</body>
-</html>