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

Unified Diff: Source/core/dom/Document.cpp

Issue 137863004: Avoid checks in createElementNS overload (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Centralize checks Created 6 years, 10 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Document.cpp
diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp
index 189f09e2622f96b38ed90d0ce34e5ecc5b927c68..482b31b40e8080fa331a5ee13702a42fbf140a07 100644
--- a/Source/core/dom/Document.cpp
+++ b/Source/core/dom/Document.cpp
@@ -769,26 +769,41 @@ PassRefPtr<Element> Document::createElement(const AtomicString& localName, const
return element;
}
-PassRefPtr<Element> Document::createElementNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& typeExtension, ExceptionState& exceptionState)
+static inline QualifiedName createQualifiedName(const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionState& exceptionState)
{
AtomicString prefix, localName;
- if (!parseQualifiedName(qualifiedName, prefix, localName, exceptionState))
- return 0;
+ if (!Document::parseQualifiedName(qualifiedName, prefix, localName, exceptionState))
+ return nullQName();
QualifiedName qName(prefix, localName, namespaceURI);
- if (!hasValidNamespaceForElements(qName)) {
+ if (!Document::hasValidNamespaceForElements(qName)) {
exceptionState.throwDOMException(NamespaceError, "The namespace URI provided ('" + namespaceURI + "') is not valid for the qualified name provided ('" + qualifiedName + "').");
- return 0;
+ return nullQName();
}
+ return qName;
+}
+
+PassRefPtr<Element> Document::createElementNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionState& exceptionState)
+{
+ QualifiedName qName(createQualifiedName(namespaceURI, qualifiedName, exceptionState));
+ if (qName == nullQName())
+ return 0;
+
+ return createElement(qName, false);
+}
+
+PassRefPtr<Element> Document::createElementNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& typeExtension, ExceptionState& exceptionState)
+{
+ QualifiedName qName(createQualifiedName(namespaceURI, qualifiedName, exceptionState));
+ if (qName == nullQName())
+ return 0;
+
RefPtr<Element> element;
- if (CustomElement::isValidName(qName.localName()) && registrationContext()) {
+ if (CustomElement::isValidName(qName.localName()) && registrationContext())
element = registrationContext()->createCustomTagElement(*this, qName);
- } else {
- element = createElementNS(namespaceURI, qualifiedName, exceptionState);
- if (exceptionState.hadException())
- return 0;
- }
+ else
+ element = createElement(qName, false);
if (!typeExtension.isEmpty())
CustomElementRegistrationContext::setIsAttributeAndTypeExtension(element.get(), typeExtension);
@@ -1085,21 +1100,6 @@ NamedFlowCollection* Document::namedFlows()
return m_namedFlows.get();
}
-PassRefPtr<Element> Document::createElementNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionState& exceptionState)
-{
- AtomicString prefix, localName;
- if (!parseQualifiedName(qualifiedName, prefix, localName, exceptionState))
- return 0;
-
- QualifiedName qName(prefix, localName, namespaceURI);
- if (!hasValidNamespaceForElements(qName)) {
- exceptionState.throwDOMException(NamespaceError, "The namespace URI provided ('" + namespaceURI + "') is not valid for the qualified name provided ('" + qualifiedName + "').");
- return 0;
- }
-
- return createElement(qName, false);
-}
-
String Document::readyState() const
{
DEFINE_STATIC_LOCAL(const String, loading, ("loading"));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698