Chromium Code Reviews| 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" |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 ScriptValue CustomElementRegistry::get(const AtomicString& name) { | 187 ScriptValue CustomElementRegistry::get(const AtomicString& name) { |
| 188 CustomElementDefinition* definition = definitionForName(name); | 188 CustomElementDefinition* definition = definitionForName(name); |
| 189 if (!definition) { | 189 if (!definition) { |
| 190 // Binding layer converts |ScriptValue()| to script specific value, | 190 // Binding layer converts |ScriptValue()| to script specific value, |
| 191 // e.g. |undefined| for v8. | 191 // e.g. |undefined| for v8. |
| 192 return ScriptValue(); | 192 return ScriptValue(); |
| 193 } | 193 } |
| 194 return definition->getConstructorForScript(); | 194 return definition->getConstructorForScript(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 // https://html.spec.whatwg.org/multipage/scripting.html#look-up-a-custom-elemen t-definition | |
| 198 // At this point, what the spec calls 'is' is 'name' from desc | |
| 197 CustomElementDefinition* CustomElementRegistry::definitionFor( | 199 CustomElementDefinition* CustomElementRegistry::definitionFor( |
| 198 const CustomElementDescriptor& desc) const { | 200 const CustomElementDescriptor& desc) const { |
| 199 CustomElementDefinition* definition = definitionForName(desc.name()); | 201 // 4. If there is a definition in registry with name equal to localName and |
|
dominicc (has gone to gerrit)
2016/10/27 04:33:14
Try to write this with only one lookup with defini
| |
| 200 if (!definition) | 202 // local name equal to localName, return that definition |
| 201 return nullptr; | 203 CustomElementDefinition* definition = definitionForName(desc.localName()); |
| 202 // The definition for a customized built-in element, such as | 204 if (definition and definition->descriptor().localName() == desc.localName()) |
| 203 // <button is="my-button"> should not be provided for an | 205 return definition; |
| 204 // autonomous element, such as <my-button>, even though the | 206 // 5. If there is a definition in registry with name equal to is and local |
| 205 // name "my-button" matches. | 207 // name equal to localName, return that definition |
| 206 return definition->descriptor() == desc ? definition : nullptr; | 208 definition = definitionForName(desc.name()); |
| 209 if (definition and definition->descriptor().localName() == desc.localName()) | |
| 210 return definition; | |
| 211 // 6. Return null | |
| 212 return nullptr; | |
| 207 } | 213 } |
| 208 | 214 |
| 209 bool CustomElementRegistry::nameIsDefined(const AtomicString& name) const { | 215 bool CustomElementRegistry::nameIsDefined(const AtomicString& name) const { |
| 210 return m_definitions.contains(name); | 216 return m_definitions.contains(name); |
| 211 } | 217 } |
| 212 | 218 |
| 213 void CustomElementRegistry::entangle(V0CustomElementRegistrationContext* v0) { | 219 void CustomElementRegistry::entangle(V0CustomElementRegistrationContext* v0) { |
| 214 m_v0->add(v0); | 220 m_v0->add(v0); |
| 215 v0->setV1(this); | 221 v0->setV1(this); |
| 216 } | 222 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 m_upgradeCandidates->remove(it); | 284 m_upgradeCandidates->remove(it); |
| 279 | 285 |
| 280 Document* document = m_owner->document(); | 286 Document* document = m_owner->document(); |
| 281 if (!document) | 287 if (!document) |
| 282 return; | 288 return; |
| 283 | 289 |
| 284 sorter.sorted(elements, document); | 290 sorter.sorted(elements, document); |
| 285 } | 291 } |
| 286 | 292 |
| 287 } // namespace blink | 293 } // namespace blink |
| OLD | NEW |