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/CustomElementRegistry.h" | 5 #include "core/dom/custom/CustomElementRegistry.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/core/v8/ScriptCustomElementDefinitionBuilder.h" | 8 #include "bindings/core/v8/ScriptCustomElementDefinitionBuilder.h" |
9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
11 #include "core/HTMLElementTypeHelpers.h" | |
11 #include "core/dom/Document.h" | 12 #include "core/dom/Document.h" |
12 #include "core/dom/Element.h" | 13 #include "core/dom/Element.h" |
13 #include "core/dom/ElementDefinitionOptions.h" | 14 #include "core/dom/ElementDefinitionOptions.h" |
14 #include "core/dom/ExceptionCode.h" | 15 #include "core/dom/ExceptionCode.h" |
15 #include "core/dom/custom/CEReactionsScope.h" | 16 #include "core/dom/custom/CEReactionsScope.h" |
16 #include "core/dom/custom/CustomElement.h" | 17 #include "core/dom/custom/CustomElement.h" |
17 #include "core/dom/custom/CustomElementDefinition.h" | 18 #include "core/dom/custom/CustomElementDefinition.h" |
18 #include "core/dom/custom/CustomElementDefinitionBuilder.h" | 19 #include "core/dom/custom/CustomElementDefinitionBuilder.h" |
19 #include "core/dom/custom/CustomElementDescriptor.h" | 20 #include "core/dom/custom/CustomElementDescriptor.h" |
20 #include "core/dom/custom/CustomElementUpgradeReaction.h" | 21 #include "core/dom/custom/CustomElementUpgradeReaction.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 if (nameIsDefined(name) || v0NameIsDefined(name)) { | 113 if (nameIsDefined(name) || v0NameIsDefined(name)) { |
113 exceptionState.throwDOMException( | 114 exceptionState.throwDOMException( |
114 NotSupportedError, | 115 NotSupportedError, |
115 "this name has already been used with this registry"); | 116 "this name has already been used with this registry"); |
116 return; | 117 return; |
117 } | 118 } |
118 | 119 |
119 if (!builder.checkConstructorNotRegistered()) | 120 if (!builder.checkConstructorNotRegistered()) |
120 return; | 121 return; |
121 | 122 |
123 AtomicString localName = name; | |
124 | |
122 // Step 7. customized built-in elements definition | 125 // Step 7. customized built-in elements definition |
123 // element interface extends option checks | 126 // element interface extends option checks |
124 if (RuntimeEnabledFeatures::customElementsBuiltinEnabled() && | 127 if (RuntimeEnabledFeatures::customElementsBuiltinEnabled() && |
125 options.hasExtends()) { | 128 options.hasExtends()) { |
126 // If element interface is valid custom element name, throw exception | 129 // 7.1. If element interface is valid custom element name, throw exception |
130 const AtomicString& extends = AtomicString(options.extends()); | |
127 if (throwIfValidName(AtomicString(options.extends()), exceptionState)) | 131 if (throwIfValidName(AtomicString(options.extends()), exceptionState)) |
128 return; | 132 return; |
129 // If element interface is undefined element, throw exception | 133 // 7.2. If element interface is undefined element, throw exception |
130 // Set localname to extends | 134 if (htmlElementTypeForTag(extends) == HTMLElementType::HTMLUnknownElement) { |
135 exceptionState.throwDOMException( | |
136 NotSupportedError, "\"" + extends + "\" is an HTMLUnknownElement"); | |
137 return; | |
138 } | |
139 // 7.3. Set localName to extends | |
140 localName = extends; | |
131 } | 141 } |
132 | 142 |
133 // TODO(dominicc): Add a test where the prototype getter destroys | 143 // TODO(dominicc): Add a test where the prototype getter destroys |
134 // the context. | 144 // the context. |
135 | 145 |
136 // 8. If this CustomElementRegistry's element definition is | 146 // 8. If this CustomElementRegistry's element definition is |
137 // running flag is set, then throw a "NotSupportedError" | 147 // running flag is set, then throw a "NotSupportedError" |
138 // DOMException and abort these steps. | 148 // DOMException and abort these steps. |
139 if (m_elementDefinitionIsRunning) { | 149 if (m_elementDefinitionIsRunning) { |
140 exceptionState.throwDOMException( | 150 exceptionState.throwDOMException( |
(...skipping 12 matching lines...) Expand all Loading... | |
153 | 163 |
154 // 10.3-6 | 164 // 10.3-6 |
155 if (!builder.rememberOriginalProperties()) | 165 if (!builder.rememberOriginalProperties()) |
156 return; | 166 return; |
157 | 167 |
158 // "Then, perform the following substep, regardless of whether | 168 // "Then, perform the following substep, regardless of whether |
159 // the above steps threw an exception or not: Unset this | 169 // the above steps threw an exception or not: Unset this |
160 // CustomElementRegistry's element definition is running | 170 // CustomElementRegistry's element definition is running |
161 // flag." | 171 // flag." |
162 // (ElementDefinitionIsRunning destructor does this.) | 172 // (ElementDefinitionIsRunning destructor does this.) |
173 // ElementDefinitionIsRunning destructor(m_elementDefinitionIsRunning); | |
dominicc (has gone to gerrit)
2016/10/25 04:30:16
Time to tackle this!
| |
163 } | 174 } |
164 | 175 |
165 CustomElementDescriptor descriptor(name, name); | 176 CustomElementDescriptor descriptor(name, localName); |
166 CustomElementDefinition* definition = builder.build(descriptor); | 177 CustomElementDefinition* definition = builder.build(descriptor); |
167 CHECK(!exceptionState.hadException()); | 178 CHECK(!exceptionState.hadException()); |
168 CHECK(definition->descriptor() == descriptor); | 179 CHECK(definition->descriptor() == descriptor); |
169 DefinitionMap::AddResult result = | 180 DefinitionMap::AddResult result = |
170 m_definitions.add(descriptor.name(), definition); | 181 m_definitions.add(descriptor.name(), definition); |
171 CHECK(result.isNewEntry); | 182 CHECK(result.isNewEntry); |
172 | 183 |
173 HeapVector<Member<Element>> candidates; | 184 HeapVector<Member<Element>> candidates; |
174 collectCandidates(descriptor, &candidates); | 185 collectCandidates(descriptor, &candidates); |
175 for (Element* candidate : candidates) | 186 for (Element* candidate : candidates) |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 m_upgradeCandidates->remove(it); | 289 m_upgradeCandidates->remove(it); |
279 | 290 |
280 Document* document = m_owner->document(); | 291 Document* document = m_owner->document(); |
281 if (!document) | 292 if (!document) |
282 return; | 293 return; |
283 | 294 |
284 sorter.sorted(elements, document); | 295 sorter.sorted(elements, document); |
285 } | 296 } |
286 | 297 |
287 } // namespace blink | 298 } // namespace blink |
OLD | NEW |