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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 define(name, builder, options, exceptionState); | 58 define(name, builder, options, exceptionState); |
59 } | 59 } |
60 | 60 |
61 // http://w3c.github.io/webcomponents/spec/custom/#dfn-element-definition | 61 // http://w3c.github.io/webcomponents/spec/custom/#dfn-element-definition |
62 void CustomElementsRegistry::define( | 62 void CustomElementsRegistry::define( |
63 const AtomicString& name, | 63 const AtomicString& name, |
64 CustomElementDefinitionBuilder& builder, | 64 CustomElementDefinitionBuilder& builder, |
65 const ElementRegistrationOptions& options, | 65 const ElementRegistrationOptions& options, |
66 ExceptionState& exceptionState) | 66 ExceptionState& exceptionState) |
67 { | 67 { |
68 CEReactionsScope reactions; | |
69 | |
70 if (!builder.checkConstructorIntrinsics()) | 68 if (!builder.checkConstructorIntrinsics()) |
71 return; | 69 return; |
72 | 70 |
73 if (!CustomElement::isValidName(name)) { | 71 if (!CustomElement::isValidName(name)) { |
74 exceptionState.throwDOMException( | 72 exceptionState.throwDOMException( |
75 SyntaxError, | 73 SyntaxError, |
76 "\"" + name + "\" is not a valid custom element name"); | 74 "\"" + name + "\" is not a valid custom element name"); |
77 return; | 75 return; |
78 } | 76 } |
79 | 77 |
(...skipping 29 matching lines...) Expand all Loading... |
109 CustomElementDescriptor descriptor(name, name); | 107 CustomElementDescriptor descriptor(name, name); |
110 CustomElementDefinition* definition = builder.build(descriptor); | 108 CustomElementDefinition* definition = builder.build(descriptor); |
111 CHECK(!exceptionState.hadException()); | 109 CHECK(!exceptionState.hadException()); |
112 CHECK(definition->descriptor() == descriptor); | 110 CHECK(definition->descriptor() == descriptor); |
113 DefinitionMap::AddResult result = | 111 DefinitionMap::AddResult result = |
114 m_definitions.add(descriptor.name(), definition); | 112 m_definitions.add(descriptor.name(), definition); |
115 CHECK(result.isNewEntry); | 113 CHECK(result.isNewEntry); |
116 | 114 |
117 HeapVector<Member<Element>> candidates; | 115 HeapVector<Member<Element>> candidates; |
118 collectCandidates(descriptor, &candidates); | 116 collectCandidates(descriptor, &candidates); |
119 for (Element* candidate : candidates) { | 117 for (Element* candidate : candidates) |
120 reactions.enqueue( | 118 CustomElement::enqueueUpgradeReaction(candidate, definition); |
121 candidate, | |
122 new CustomElementUpgradeReaction(definition)); | |
123 } | |
124 | 119 |
125 // TODO(dominicc): Implement steps: | 120 // TODO(dominicc): Implement steps: |
126 // 20: when-defined promise processing | 121 // 20: when-defined promise processing |
127 } | 122 } |
128 | 123 |
129 // https://html.spec.whatwg.org/multipage/scripting.html#dom-customelementsregis
try-get | 124 // https://html.spec.whatwg.org/multipage/scripting.html#dom-customelementsregis
try-get |
130 ScriptValue CustomElementsRegistry::get(const AtomicString& name) | 125 ScriptValue CustomElementsRegistry::get(const AtomicString& name) |
131 { | 126 { |
132 CustomElementDefinition* definition = definitionForName(name); | 127 CustomElementDefinition* definition = definitionForName(name); |
133 if (!definition) { | 128 if (!definition) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 if (!element || !desc.matches(*element)) | 185 if (!element || !desc.matches(*element)) |
191 continue; | 186 continue; |
192 sorter.add(element); | 187 sorter.add(element); |
193 } | 188 } |
194 | 189 |
195 m_upgradeCandidates->remove(it); | 190 m_upgradeCandidates->remove(it); |
196 sorter.sorted(elements, m_document.get()); | 191 sorter.sorted(elements, m_document.get()); |
197 } | 192 } |
198 | 193 |
199 } // namespace blink | 194 } // namespace blink |
OLD | NEW |