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/CustomElementsRegistry.h" | 5 #include "core/dom/custom/CustomElementsRegistry.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 "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/dom/Element.h" | 10 #include "core/dom/Element.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 define(name, builder, options, exceptionState); | 83 define(name, builder, options, exceptionState); |
84 } | 84 } |
85 | 85 |
86 // http://w3c.github.io/webcomponents/spec/custom/#dfn-element-definition | 86 // http://w3c.github.io/webcomponents/spec/custom/#dfn-element-definition |
87 void CustomElementsRegistry::define( | 87 void CustomElementsRegistry::define( |
88 const AtomicString& name, | 88 const AtomicString& name, |
89 CustomElementDefinitionBuilder& builder, | 89 CustomElementDefinitionBuilder& builder, |
90 const ElementRegistrationOptions& options, | 90 const ElementRegistrationOptions& options, |
91 ExceptionState& exceptionState) | 91 ExceptionState& exceptionState) |
92 { | 92 { |
93 CEReactionsScope reactions; | |
94 | |
95 if (!builder.checkConstructorIntrinsics()) | 93 if (!builder.checkConstructorIntrinsics()) |
96 return; | 94 return; |
97 | 95 |
98 if (!CustomElement::isValidName(name)) { | 96 if (!CustomElement::isValidName(name)) { |
99 exceptionState.throwDOMException( | 97 exceptionState.throwDOMException( |
100 SyntaxError, | 98 SyntaxError, |
101 "\"" + name + "\" is not a valid custom element name"); | 99 "\"" + name + "\" is not a valid custom element name"); |
102 return; | 100 return; |
103 } | 101 } |
104 | 102 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 CustomElementDescriptor descriptor(name, name); | 140 CustomElementDescriptor descriptor(name, name); |
143 CustomElementDefinition* definition = builder.build(descriptor); | 141 CustomElementDefinition* definition = builder.build(descriptor); |
144 CHECK(!exceptionState.hadException()); | 142 CHECK(!exceptionState.hadException()); |
145 CHECK(definition->descriptor() == descriptor); | 143 CHECK(definition->descriptor() == descriptor); |
146 DefinitionMap::AddResult result = | 144 DefinitionMap::AddResult result = |
147 m_definitions.add(descriptor.name(), definition); | 145 m_definitions.add(descriptor.name(), definition); |
148 CHECK(result.isNewEntry); | 146 CHECK(result.isNewEntry); |
149 | 147 |
150 HeapVector<Member<Element>> candidates; | 148 HeapVector<Member<Element>> candidates; |
151 collectCandidates(descriptor, &candidates); | 149 collectCandidates(descriptor, &candidates); |
152 for (Element* candidate : candidates) { | 150 for (Element* candidate : candidates) |
153 reactions.enqueue( | 151 CustomElement::enqueueUpgradeReaction(candidate, definition); |
154 candidate, | |
155 new CustomElementUpgradeReaction(definition)); | |
156 } | |
157 | 152 |
158 // TODO(dominicc): Implement steps: | 153 // TODO(dominicc): Implement steps: |
159 // 20: when-defined promise processing | 154 // 20: when-defined promise processing |
160 } | 155 } |
161 | 156 |
162 // https://html.spec.whatwg.org/multipage/scripting.html#dom-customelementsregis
try-get | 157 // https://html.spec.whatwg.org/multipage/scripting.html#dom-customelementsregis
try-get |
163 ScriptValue CustomElementsRegistry::get(const AtomicString& name) | 158 ScriptValue CustomElementsRegistry::get(const AtomicString& name) |
164 { | 159 { |
165 CustomElementDefinition* definition = definitionForName(name); | 160 CustomElementDefinition* definition = definitionForName(name); |
166 if (!definition) { | 161 if (!definition) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 if (!element || !desc.matches(*element)) | 218 if (!element || !desc.matches(*element)) |
224 continue; | 219 continue; |
225 sorter.add(element); | 220 sorter.add(element); |
226 } | 221 } |
227 | 222 |
228 m_upgradeCandidates->remove(it); | 223 m_upgradeCandidates->remove(it); |
229 sorter.sorted(elements, m_document.get()); | 224 sorter.sorted(elements, m_document.get()); |
230 } | 225 } |
231 | 226 |
232 } // namespace blink | 227 } // namespace blink |
OLD | NEW |