Bug 976318 - Template element contents owner document should be an inert template document. r=mrbkap

This commit is contained in:
William Chen 2014-03-03 12:03:23 -08:00
parent 4e89716e1a
commit c739e15afa
3 changed files with 16 additions and 10 deletions

View File

@ -9367,6 +9367,12 @@ nsDocument::GetTemplateContentsOwner()
NS_ENSURE_TRUE(mTemplateContentsOwner, nullptr);
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;

View File

@ -39,16 +39,8 @@ HTMLTemplateElement::HTMLTemplateElement(already_AddRefed<nsINodeInfo> aNodeInfo
nsresult
HTMLTemplateElement::Init()
{
nsIDocument* doc = OwnerDoc();
nsIDocument* contentsOwner = doc;
// Used to test if the document "has a browsing context".
nsCOMPtr<nsISupports> container = doc->GetContainer();
if (container) {
// GetTemplateContentsOwner lazily creates a document.
contentsOwner = doc->GetTemplateContentsOwner();
NS_ENSURE_TRUE(contentsOwner, NS_ERROR_UNEXPECTED);
}
nsIDocument* contentsOwner = OwnerDoc()->GetTemplateContentsOwner();
NS_ENSURE_TRUE(contentsOwner, NS_ERROR_UNEXPECTED);
mContent = contentsOwner->CreateDocumentFragment();
mContent->SetHost(this);

View File

@ -50,6 +50,14 @@ ok(templateEl.content.ownerDocument != templateEl.ownerDocument, "Template shoul
var otherTemplateEl = document.getElementById("first");
is(templateEl.content.ownerDocument, otherTemplateEl.content.ownerDocument, "Template contents within the same document should be owned by the same template contents owner.");
var htmlDoc = document.implementation.createHTMLDocument();
var otherDocTemplateEl = htmlDoc.createElement("template");
isnot(otherDocTemplateEl.content.ownerDocument, htmlDoc, "Template content owner should be a new document.");
var templateOwnerDoc = otherDocTemplateEl.content.ownerDocument;
var docCreatedTemplateEl = templateOwnerDoc.createElement("template");
is(docCreatedTemplateEl.content.ownerDocument, templateOwnerDoc, "Template content owner of template elements created by a template document should be the template document.");
// Tests for XMLSerializer
templateEl = document.getElementById("justtemplate");
var serializer = new XMLSerializer();