| 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 b261c80514f8de4966a4f07f43eb41362d471fe0..b19de7c9f60594bdda98063f4ed6a9d18062fdbe 100644
|
| --- a/third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.cpp
|
| +++ b/third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.cpp
|
| @@ -4,6 +4,8 @@
|
|
|
| #include "core/dom/custom/CustomElementDefinition.h"
|
|
|
| +#include "core/dom/ExceptionCode.h"
|
| +
|
| namespace blink {
|
|
|
| CustomElementDefinition::CustomElementDefinition(
|
| @@ -46,4 +48,47 @@ void CustomElementDefinition::upgrade(Element* element)
|
| CHECK(element->getCustomElementState() == CustomElementState::Custom);
|
| }
|
|
|
| +static String errorMessageForConstructorResult(Element* element,
|
| + Document& document, const QualifiedName& tagName)
|
| +{
|
| + // https://dom.spec.whatwg.org/#concept-create-element
|
| + // 6.1.4. If result's attribute list is not empty, then throw a NotSupportedError.
|
| + if (element->hasAttributes())
|
| + return "The result must not have attributes";
|
| + // 6.1.5. If result has children, then throw a NotSupportedError.
|
| + if (element->hasChildren())
|
| + return "The result must not have children";
|
| + // 6.1.6. If result's parent is not null, then throw a NotSupportedError.
|
| + if (element->parentNode())
|
| + return "The result must not have a parent";
|
| + // 6.1.7. If result's node document is not document, then throw a NotSupportedError.
|
| + if (&element->document() != &document)
|
| + return "The result must be in the same document";
|
| + // 6.1.8. If result's namespace is not the HTML namespace, then throw a NotSupportedError.
|
| + if (element->namespaceURI() != HTMLNames::xhtmlNamespaceURI)
|
| + return "The result must have HTML namespace";
|
| + // 6.1.9. If result's local name is not equal to localName, then throw a NotSupportedError.
|
| + if (element->localName() != tagName.localName())
|
| + return "The result must have the same localName";
|
| + return String();
|
| +}
|
| +
|
| +void CustomElementDefinition::errorForConstructorResult(Element* element,
|
| + Document& document, const QualifiedName& tagName,
|
| + ExceptionState& exceptionState)
|
| +{
|
| + // https://dom.spec.whatwg.org/#concept-create-element
|
| + // 6.1.3. If result does not implement the HTMLElement interface, throw a TypeError.
|
| + // See https://github.com/whatwg/html/issues/1402 for more clarifications.
|
| + if (!element || !element->isHTMLElement()) {
|
| + exceptionState.throwTypeError("The result must implement HTMLElement interface");
|
| + return;
|
| + }
|
| +
|
| + // 6.1.4. through 6.1.9.
|
| + const String message = errorMessageForConstructorResult(element, document, tagName);
|
| + if (!message.isEmpty())
|
| + exceptionState.throwDOMException(NotSupportedError, message);
|
| +}
|
| +
|
| } // namespace blink
|
|
|