Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Unified Diff: third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.cpp

Issue 2274883005: Fix ScriptCustomElementDefinition::createElementSync to use the given document (Closed)
Patch Set: Remove #if DCHECK_IS_ON() due to failure on CrOS Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.cpp
diff --git a/third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.cpp b/third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.cpp
index a9e7d5cd80b3ae9db6a1ff58feab377d277472db..45edde7230ed1e41fc0ba651933153f9436918fc 100644
--- a/third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.cpp
+++ b/third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.cpp
@@ -84,6 +84,22 @@ void CustomElementDefinition::checkConstructorResult(Element* element,
exceptionState.throwDOMException(NotSupportedError, message);
}
+HTMLElement* CustomElementDefinition::createElementForConstructor(
+ Document& document)
+{
+ // TODO(kojii): When HTMLElementFactory has an option not to queue
+ // upgrade, call that instead of HTMLElement. HTMLElement is enough
+ // for now, but type extension will require HTMLElementFactory.
+ HTMLElement* element = HTMLElement::create(
+ QualifiedName(nullAtom, descriptor().localName(),
+ HTMLNames::xhtmlNamespaceURI),
+ document);
+ // TODO(davaajav): write this as one call to setCustomElementState instead of two
+ element->setCustomElementState(CustomElementState::Undefined);
+ element->setCustomElementDefinition(this);
+ return element;
+}
+
HTMLElement* CustomElementDefinition::createElementAsync(Document& document, const QualifiedName& tagName)
{
// https://dom.spec.whatwg.org/#concept-create-element
@@ -101,6 +117,25 @@ HTMLElement* CustomElementDefinition::createElementAsync(Document& document, con
return element;
}
+CustomElementDefinition::ConstructionStackScope::ConstructionStackScope(
+ CustomElementDefinition* definition, Element* element)
+ : m_constructionStack(definition->m_constructionStack)
+ , m_element(element)
+{
+ // Push the construction stack.
+ m_constructionStack.append(element);
+ m_depth = m_constructionStack.size();
+}
+
+CustomElementDefinition::ConstructionStackScope::~ConstructionStackScope()
+{
+ // Pop the construction stack.
+ DCHECK(!m_constructionStack.last()
+ || m_constructionStack.last() == m_element);
+ DCHECK_EQ(m_constructionStack.size(), m_depth); // It's a *stack*.
+ m_constructionStack.removeLast();
+}
+
// https://html.spec.whatwg.org/multipage/scripting.html#concept-upgrade-an-element
void CustomElementDefinition::upgrade(Element* element)
{
@@ -112,17 +147,11 @@ void CustomElementDefinition::upgrade(Element* element)
if (element->isConnected() && hasConnectedCallback())
enqueueConnectedCallback(element);
- m_constructionStack.append(element);
- size_t depth = m_constructionStack.size();
-
- bool succeeded = runConstructor(element);
-
- // Pop the construction stack.
- if (m_constructionStack.last().get())
- DCHECK_EQ(m_constructionStack.last(), element);
- DCHECK_EQ(m_constructionStack.size(), depth); // It's a *stack*.
- m_constructionStack.removeLast();
-
+ bool succeeded = false;
+ {
+ ConstructionStackScope constructionStackScope(this, element);
+ succeeded = runConstructor(element);
+ }
if (!succeeded) {
element->setCustomElementState(CustomElementState::Failed);
return;
« no previous file with comments | « third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698