Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: third_party/WebKit/Source/core/dom/custom/CustomElementsRegistry.cpp

Issue 2029923003: Recursively defining custom elements should not lead to redefinition (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/ElementRegistrationOptions.h" 10 #include "core/dom/ElementRegistrationOptions.h"
11 #include "core/dom/ExceptionCode.h" 11 #include "core/dom/ExceptionCode.h"
12 #include "core/dom/custom/CustomElement.h" 12 #include "core/dom/custom/CustomElement.h"
13 #include "core/dom/custom/CustomElementDefinition.h" 13 #include "core/dom/custom/CustomElementDefinition.h"
14 #include "core/dom/custom/CustomElementDefinitionBuilder.h" 14 #include "core/dom/custom/CustomElementDefinitionBuilder.h"
15 #include "core/dom/custom/V0CustomElementRegistrationContext.h" 15 #include "core/dom/custom/V0CustomElementRegistrationContext.h"
16 #include "wtf/Allocator.h"
16 17
17 namespace blink { 18 namespace blink {
18 19
20 class CustomElementsRegistry::NameIsBeingDefined final {
21 STACK_ALLOCATED();
22 DISALLOW_IMPLICIT_CONSTRUCTORS(NameIsBeingDefined);
23 public:
24 NameIsBeingDefined(
25 CustomElementsRegistry* registry,
26 const AtomicString& name)
27 : m_registry(registry)
28 , m_name(name)
29 {
30 DCHECK(!m_registry->m_namesBeingDefined.contains(name));
31 m_registry->m_namesBeingDefined.add(name);
32 }
33
34 ~NameIsBeingDefined()
35 {
36 m_registry->m_namesBeingDefined.remove(m_name);
37 }
38
39 private:
40 Member<CustomElementsRegistry> m_registry;
41 const AtomicString& m_name;
42 };
43
19 CustomElementsRegistry* CustomElementsRegistry::create( 44 CustomElementsRegistry* CustomElementsRegistry::create(
20 V0CustomElementRegistrationContext* v0) 45 V0CustomElementRegistrationContext* v0)
21 { 46 {
22 // TODO(dominicc): The window could install a new document; add a signal 47 // TODO(dominicc): The window could install a new document; add a signal
23 // when a window installs a new document to notify that V0 context, too. 48 // when a window installs a new document to notify that V0 context, too.
24 CustomElementsRegistry* registry = new CustomElementsRegistry(v0); 49 CustomElementsRegistry* registry = new CustomElementsRegistry(v0);
25 if (v0) 50 if (v0)
26 v0->setV1(registry); 51 v0->setV1(registry);
27 return registry; 52 return registry;
28 } 53 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 if (!builder.checkConstructorIntrinsics()) 89 if (!builder.checkConstructorIntrinsics())
65 return; 90 return;
66 91
67 if (!CustomElement::isValidName(name)) { 92 if (!CustomElement::isValidName(name)) {
68 exceptionState.throwDOMException( 93 exceptionState.throwDOMException(
69 SyntaxError, 94 SyntaxError,
70 "\"" + name + "\" is not a valid custom element name"); 95 "\"" + name + "\" is not a valid custom element name");
71 return; 96 return;
72 } 97 }
73 98
99 if (m_namesBeingDefined.contains(name)) {
100 exceptionState.throwDOMException(
101 NotSupportedError,
102 "this name is already being defined in this registry");
103 return;
104 }
105 NameIsBeingDefined defining(this, name);
106
74 if (nameIsDefined(name) || v0NameIsDefined(name)) { 107 if (nameIsDefined(name) || v0NameIsDefined(name)) {
75 exceptionState.throwDOMException( 108 exceptionState.throwDOMException(
76 NotSupportedError, 109 NotSupportedError,
77 "this name has already been used with this registry"); 110 "this name has already been used with this registry");
78 return; 111 return;
79 } 112 }
80 113
81 if (!builder.checkConstructorNotRegistered()) 114 if (!builder.checkConstructorNotRegistered())
82 return; 115 return;
83 116
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return m_v0->nameIsDefined(name); 152 return m_v0->nameIsDefined(name);
120 } 153 }
121 154
122 CustomElementDefinition* CustomElementsRegistry::definitionForName( 155 CustomElementDefinition* CustomElementsRegistry::definitionForName(
123 const AtomicString& name) const 156 const AtomicString& name) const
124 { 157 {
125 return m_definitions.get(name); 158 return m_definitions.get(name);
126 } 159 }
127 160
128 } // namespace blink 161 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698