Index: Source/core/html/parser/HTMLConstructionSite.cpp |
diff --git a/Source/core/html/parser/HTMLConstructionSite.cpp b/Source/core/html/parser/HTMLConstructionSite.cpp |
index 96d3025240f3549ab78e3f2fdb2d2c1581e72e93..c01af71918dbac7ccd5a92f4a3f176a6a585550e 100644 |
--- a/Source/core/html/parser/HTMLConstructionSite.cpp |
+++ b/Source/core/html/parser/HTMLConstructionSite.cpp |
@@ -645,10 +645,14 @@ inline Document* HTMLConstructionSite::ownerDocumentForCurrentNode() |
PassRefPtr<Element> HTMLConstructionSite::createHTMLElement(AtomicHTMLToken* token) |
{ |
QualifiedName tagName(nullAtom, token->name(), xhtmlNamespaceURI); |
+ Document* document = ownerDocumentForCurrentNode(); |
+ // Only associate the element with the current form if we're creating the new element |
+ // in a document with a browsing context (rather than in <template> contents). |
+ HTMLFormElement* form = document->frame() ? m_form.get() : 0; |
// FIXME: This can't use HTMLConstructionSite::createElement because we |
// have to pass the current form element. We should rework form association |
// to occur after construction to allow better code sharing here. |
- RefPtr<Element> element = HTMLElementFactory::createHTMLElement(tagName, ownerDocumentForCurrentNode(), form(), true); |
+ RefPtr<Element> element = HTMLElementFactory::createHTMLElement(tagName, document, form, true); |
setAttributes(element.get(), token, m_parserContentPolicy); |
ASSERT(element->isHTMLElement()); |
return element.release(); |