OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/dom/custom/CustomElementDefinition.h" | 5 #include "core/dom/custom/CustomElementDefinition.h" |
6 | 6 |
| 7 #include "core/dom/ExceptionCode.h" |
| 8 |
7 namespace blink { | 9 namespace blink { |
8 | 10 |
9 CustomElementDefinition::CustomElementDefinition( | 11 CustomElementDefinition::CustomElementDefinition( |
10 const CustomElementDescriptor& descriptor) | 12 const CustomElementDescriptor& descriptor) |
11 : m_descriptor(descriptor) | 13 : m_descriptor(descriptor) |
12 { | 14 { |
13 } | 15 } |
14 | 16 |
15 CustomElementDefinition::~CustomElementDefinition() | 17 CustomElementDefinition::~CustomElementDefinition() |
16 { | 18 { |
(...skipping 22 matching lines...) Expand all Loading... |
39 DCHECK_EQ(m_constructionStack.last(), element); | 41 DCHECK_EQ(m_constructionStack.last(), element); |
40 DCHECK_EQ(m_constructionStack.size(), depth); // It's a *stack*. | 42 DCHECK_EQ(m_constructionStack.size(), depth); // It's a *stack*. |
41 m_constructionStack.removeLast(); | 43 m_constructionStack.removeLast(); |
42 | 44 |
43 if (!succeeded) | 45 if (!succeeded) |
44 return; | 46 return; |
45 | 47 |
46 CHECK(element->getCustomElementState() == CustomElementState::Custom); | 48 CHECK(element->getCustomElementState() == CustomElementState::Custom); |
47 } | 49 } |
48 | 50 |
| 51 static String errorMessageForConstructorResult(Element* element, |
| 52 Document& document, const QualifiedName& tagName) |
| 53 { |
| 54 // https://dom.spec.whatwg.org/#concept-create-element |
| 55 // 6.1.4. If result's attribute list is not empty, then throw a NotSupported
Error. |
| 56 if (element->hasAttributes()) |
| 57 return "The result must not have attributes"; |
| 58 // 6.1.5. If result has children, then throw a NotSupportedError. |
| 59 if (element->hasChildren()) |
| 60 return "The result must not have children"; |
| 61 // 6.1.6. If result's parent is not null, then throw a NotSupportedError. |
| 62 if (element->parentNode()) |
| 63 return "The result must not have a parent"; |
| 64 // 6.1.7. If result's node document is not document, then throw a NotSupport
edError. |
| 65 if (&element->document() != &document) |
| 66 return "The result must be in the same document"; |
| 67 // 6.1.8. If result's namespace is not the HTML namespace, then throw a NotS
upportedError. |
| 68 if (element->namespaceURI() != HTMLNames::xhtmlNamespaceURI) |
| 69 return "The result must have HTML namespace"; |
| 70 // 6.1.9. If result's local name is not equal to localName, then throw a Not
SupportedError. |
| 71 if (element->localName() != tagName.localName()) |
| 72 return "The result must have the same localName"; |
| 73 return String(); |
| 74 } |
| 75 |
| 76 void CustomElementDefinition::errorForConstructorResult(Element* element, |
| 77 Document& document, const QualifiedName& tagName, |
| 78 ExceptionState& exceptionState) |
| 79 { |
| 80 // https://dom.spec.whatwg.org/#concept-create-element |
| 81 // 6.1.3. If result does not implement the HTMLElement interface, throw a Ty
peError. |
| 82 // See https://github.com/whatwg/html/issues/1402 for more clarifications. |
| 83 if (!element || !element->isHTMLElement()) { |
| 84 exceptionState.throwTypeError("The result must implement HTMLElement int
erface"); |
| 85 return; |
| 86 } |
| 87 |
| 88 // 6.1.4. through 6.1.9. |
| 89 const String message = errorMessageForConstructorResult(element, document, t
agName); |
| 90 if (!message.isEmpty()) |
| 91 exceptionState.throwDOMException(NotSupportedError, message); |
| 92 } |
| 93 |
49 } // namespace blink | 94 } // namespace blink |
OLD | NEW |