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 // TODO(dominicc): Stop including Document.h when | 7 // TODO(dominicc): Stop including Document.h when |
8 // v0CustomElementIsDefined has been removed. | 8 // v0CustomElementIsDefined has been removed. |
9 #include "bindings/core/v8/DOMWrapperWorld.h" | 9 #include "bindings/core/v8/DOMWrapperWorld.h" |
10 #include "bindings/core/v8/ExceptionState.h" | 10 #include "bindings/core/v8/ExceptionState.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 | 130 |
131 Id id = m_definitions.size(); | 131 Id id = m_definitions.size(); |
132 v8::Local<v8::Value> idValue = v8::Integer::NewFromUnsigned(isolate, id); | 132 v8::Local<v8::Value> idValue = v8::Integer::NewFromUnsigned(isolate, id); |
133 m_definitions.append(new CustomElementDefinition(this, id, name)); | 133 m_definitions.append(new CustomElementDefinition(this, id, name)); |
134 // This map is stored in a hidden reference from the | 134 // This map is stored in a hidden reference from the |
135 // CustomElementsRegistry wrapper. | 135 // CustomElementsRegistry wrapper. |
136 v8::Local<v8::Map> map = idMap(scriptState); | 136 v8::Local<v8::Map> map = idMap(scriptState); |
137 // The map keeps the constructor and prototypes alive. | 137 // The map keeps the constructor and prototypes alive. |
138 v8CallOrCrash(map->Set(context, constructor, idValue)); | 138 v8CallOrCrash(map->Set(context, constructor, idValue)); |
139 v8CallOrCrash(map->Set(context, idValue, prototype)); | 139 v8CallOrCrash(map->Set(context, idValue, prototype)); |
140 m_names.add(name); | 140 m_names.add(name, id); |
141 | 141 |
142 // TODO(dominicc): Implement steps: | 142 // TODO(dominicc): Implement steps: |
143 // 20: when-defined promise processing | 143 // 20: when-defined promise processing |
144 DCHECK(!tryCatch.HasCaught() || tryCatch.HasTerminated()); | 144 DCHECK(!tryCatch.HasCaught() || tryCatch.HasTerminated()); |
145 } | 145 } |
146 | 146 |
147 CustomElementDefinition* CustomElementsRegistry::definitionForConstructor( | 147 CustomElementDefinition* CustomElementsRegistry::definitionForConstructor( |
148 ScriptState* scriptState, | 148 ScriptState* scriptState, |
149 v8::Local<v8::Value> constructor) | 149 v8::Local<v8::Value> constructor) |
150 { | 150 { |
151 Id id; | 151 Id id; |
152 if (!idForConstructor(scriptState, constructor, id)) | 152 if (!idForConstructor(scriptState, constructor, id)) |
153 return nullptr; | 153 return nullptr; |
154 return m_definitions[id]; | 154 return m_definitions[id]; |
155 } | 155 } |
156 | 156 |
157 // http://w3c.github.io/webcomponents/spec/custom/#dom-customelementsregistry-ge t | |
kojii
2016/05/19 10:04:32
It's already old, should be:
https://html.spec.wha
yosin_UTC9
2016/05/23 04:45:06
Done
| |
158 ScriptValue CustomElementsRegistry::get( | |
159 ScriptState* scriptState, const AtomicString& name) const | |
160 { | |
161 const auto& it = m_names.find(name); | |
162 if (it == m_names.end()) | |
163 return ScriptValue(scriptState, v8Undefined()); | |
164 v8::Local<v8::Context> context = scriptState->context(); | |
dominicc (has gone to gerrit)
2016/05/19 22:12:10
You should CHECK that scriptState->world().isMainW
| |
165 v8::Local<v8::Map> map = idMap(scriptState); | |
166 v8::Local<v8::Value> idValue = toV8(it->value, scriptState); | |
167 return ScriptValue(scriptState, v8CallOrCrash(map->Get(context, idValue))); | |
dominicc (has gone to gerrit)
2016/05/19 22:12:10
I believe this is the prototype; not the construct
| |
168 } | |
169 | |
157 v8::Local<v8::Object> CustomElementsRegistry::prototype( | 170 v8::Local<v8::Object> CustomElementsRegistry::prototype( |
158 ScriptState* scriptState, | 171 ScriptState* scriptState, |
159 const CustomElementDefinition& def) | 172 const CustomElementDefinition& def) |
160 { | 173 { |
161 v8::Local<v8::Value> idValue = | 174 v8::Local<v8::Value> idValue = |
162 v8::Integer::NewFromUnsigned(scriptState->isolate(), def.id()); | 175 v8::Integer::NewFromUnsigned(scriptState->isolate(), def.id()); |
163 return v8CallOrCrash( | 176 return v8CallOrCrash( |
164 idMap(scriptState)->Get(scriptState->context(), idValue)) | 177 idMap(scriptState)->Get(scriptState->context(), idValue)) |
165 .As<v8::Object>(); | 178 .As<v8::Object>(); |
166 } | 179 } |
167 | 180 |
168 bool CustomElementsRegistry::nameIsDefined(const AtomicString& name) const | 181 bool CustomElementsRegistry::nameIsDefined(const AtomicString& name) const |
169 { | 182 { |
170 return m_names.contains(name); | 183 return m_names.contains(name); |
171 } | 184 } |
172 | 185 |
173 v8::Local<v8::Map> CustomElementsRegistry::idMap(ScriptState* scriptState) | 186 v8::Local<v8::Map> CustomElementsRegistry::idMap(ScriptState* scriptState) const |
174 { | 187 { |
175 DCHECK(scriptState->world().isMainWorld()); | 188 DCHECK(scriptState->world().isMainWorld()); |
176 v8::Local<v8::Object> wrapper = | 189 v8::Local<v8::Object> wrapper = |
177 toV8(this, scriptState).As<v8::Object>(); | 190 toV8(this, scriptState).As<v8::Object>(); |
178 v8::Local<v8::String> name = V8HiddenValue::customElementsRegistryMap( | 191 v8::Local<v8::String> name = V8HiddenValue::customElementsRegistryMap( |
179 scriptState->isolate()); | 192 scriptState->isolate()); |
180 return V8HiddenValue::getHiddenValue(scriptState, wrapper, name) | 193 return V8HiddenValue::getHiddenValue(scriptState, wrapper, name) |
181 .As<v8::Map>(); | 194 .As<v8::Map>(); |
182 } | 195 } |
183 | 196 |
(...skipping 15 matching lines...) Expand all Loading... | |
199 return m_v0.get() && m_v0->nameIsDefined(name); | 212 return m_v0.get() && m_v0->nameIsDefined(name); |
200 } | 213 } |
201 | 214 |
202 DEFINE_TRACE(CustomElementsRegistry) | 215 DEFINE_TRACE(CustomElementsRegistry) |
203 { | 216 { |
204 visitor->trace(m_definitions); | 217 visitor->trace(m_definitions); |
205 visitor->trace(m_v0); | 218 visitor->trace(m_v0); |
206 } | 219 } |
207 | 220 |
208 } // namespace blink | 221 } // namespace blink |
OLD | NEW |