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

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

Issue 2003593003: Make CustomElementsRegistry lazily initialize script state. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Does not use a separate representation of initialized state. Created 4 years, 7 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 // 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"
11 #include "bindings/core/v8/ScriptState.h" 11 #include "bindings/core/v8/ScriptState.h"
12 #include "bindings/core/v8/ScriptValue.h" 12 #include "bindings/core/v8/ScriptValue.h"
13 #include "bindings/core/v8/V8Binding.h" 13 #include "bindings/core/v8/V8Binding.h"
14 #include "bindings/core/v8/V8BindingMacros.h" 14 #include "bindings/core/v8/V8BindingMacros.h"
15 #include "bindings/core/v8/V8HiddenValue.h" 15 #include "bindings/core/v8/V8HiddenValue.h"
16 #include "core/dom/Document.h" 16 #include "core/dom/Document.h"
17 #include "core/dom/ElementRegistrationOptions.h" 17 #include "core/dom/ElementRegistrationOptions.h"
18 #include "core/dom/ExceptionCode.h" 18 #include "core/dom/ExceptionCode.h"
19 #include "core/dom/custom/CustomElement.h" 19 #include "core/dom/custom/CustomElement.h"
20 #include "core/dom/custom/CustomElementDefinition.h" 20 #include "core/dom/custom/CustomElementDefinition.h"
21 #include "core/dom/custom/V0CustomElementRegistrationContext.h" 21 #include "core/dom/custom/V0CustomElementRegistrationContext.h"
22 #include "core/dom/custom/V0CustomElementRegistry.h" 22 #include "core/dom/custom/V0CustomElementRegistry.h"
23 23
24 namespace blink { 24 namespace blink {
25 25
26 CustomElementsRegistry* CustomElementsRegistry::create( 26 CustomElementsRegistry* CustomElementsRegistry::create(
27 ScriptState* scriptState,
28 V0CustomElementRegistrationContext* v0) 27 V0CustomElementRegistrationContext* v0)
29 { 28 {
30 DCHECK(scriptState->world().isMainWorld());
31 CustomElementsRegistry* registry = new CustomElementsRegistry(v0); 29 CustomElementsRegistry* registry = new CustomElementsRegistry(v0);
32 if (v0) 30 if (v0)
33 v0->setV1(registry); 31 v0->setV1(registry);
34
35 v8::Isolate* isolate = scriptState->isolate();
36 v8::Local<v8::Object> wrapper =
37 toV8(registry, scriptState).As<v8::Object>();
38 v8::Local<v8::String> name =
39 V8HiddenValue::customElementsRegistryMap(isolate);
40 v8::Local<v8::Map> map = v8::Map::New(isolate);
41 bool didSetPrototype =
42 V8HiddenValue::setHiddenValue(scriptState, wrapper, name, map);
43 DCHECK(didSetPrototype);
44
45 return registry; 32 return registry;
46 } 33 }
47 34
48 CustomElementsRegistry::CustomElementsRegistry( 35 CustomElementsRegistry::CustomElementsRegistry(
49 const V0CustomElementRegistrationContext* v0) 36 const V0CustomElementRegistrationContext* v0)
50 : m_v0(v0) 37 : m_v0(v0)
51 { 38 {
52 } 39 }
53 40
54 // http://w3c.github.io/webcomponents/spec/custom/#dfn-element-definition 41 // http://w3c.github.io/webcomponents/spec/custom/#dfn-element-definition
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 return v8CallOrCrash( 153 return v8CallOrCrash(
167 idMap(scriptState)->Get(scriptState->context(), idValue)) 154 idMap(scriptState)->Get(scriptState->context(), idValue))
168 .As<v8::Object>(); 155 .As<v8::Object>();
169 } 156 }
170 157
171 bool CustomElementsRegistry::nameIsDefined(const AtomicString& name) const 158 bool CustomElementsRegistry::nameIsDefined(const AtomicString& name) const
172 { 159 {
173 return m_names.contains(name); 160 return m_names.contains(name);
174 } 161 }
175 162
163 void CustomElementsRegistry::initializeScript(
haraken 2016/05/23 01:46:37 I'd rename the method to ensureConstructorMap() an
164 ScriptState* scriptState,
165 v8::Local<v8::Map>& map)
166 {
167 CHECK(scriptState->world().isMainWorld());
168 v8::Local<v8::Object> wrapper = toV8(this, scriptState).As<v8::Object>();
169 v8::Isolate* isolate = scriptState->isolate();
170 v8::Local<v8::String> name =
171 V8HiddenValue::customElementsRegistryMap(isolate);
172 DCHECK(V8HiddenValue::getHiddenValue(scriptState, wrapper, name).IsEmpty());
173 map = v8::Map::New(isolate);
174 V8HiddenValue::setHiddenValue(scriptState, wrapper, name, map);
175 }
176
176 v8::Local<v8::Map> CustomElementsRegistry::idMap(ScriptState* scriptState) 177 v8::Local<v8::Map> CustomElementsRegistry::idMap(ScriptState* scriptState)
177 { 178 {
178 DCHECK(scriptState->world().isMainWorld()); 179 CHECK(scriptState->world().isMainWorld());
179 v8::Local<v8::Object> wrapper = 180 v8::Local<v8::Object> wrapper = toV8(this, scriptState).As<v8::Object>();
180 toV8(this, scriptState).As<v8::Object>();
181 v8::Local<v8::String> name = V8HiddenValue::customElementsRegistryMap( 181 v8::Local<v8::String> name = V8HiddenValue::customElementsRegistryMap(
182 scriptState->isolate()); 182 scriptState->isolate());
183 return V8HiddenValue::getHiddenValue(scriptState, wrapper, name) 183 v8::Local<v8::Value> mapValue =
184 .As<v8::Map>(); 184 V8HiddenValue::getHiddenValue(scriptState, wrapper, name);
185 v8::Local<v8::Map> map;
186 if (!mapValue.IsEmpty())
187 map = mapValue.As<v8::Map>();
188 else
189 initializeScript(scriptState, map);
190 return map;
185 } 191 }
186 192
187 bool CustomElementsRegistry::idForConstructor( 193 bool CustomElementsRegistry::idForConstructor(
188 ScriptState* scriptState, 194 ScriptState* scriptState,
189 v8::Local<v8::Value> constructor, 195 v8::Local<v8::Value> constructor,
190 Id& id) 196 Id& id)
191 { 197 {
192 v8::Local<v8::Value> entry = v8CallOrCrash( 198 v8::Local<v8::Value> entry = v8CallOrCrash(
193 idMap(scriptState)->Get(scriptState->context(), constructor)); 199 idMap(scriptState)->Get(scriptState->context(), constructor));
194 if (!entry->IsUint32()) 200 if (!entry->IsUint32())
195 return false; 201 return false;
196 id = v8CallOrCrash(entry->Uint32Value(scriptState->context())); 202 id = v8CallOrCrash(entry->Uint32Value(scriptState->context()));
197 return true; 203 return true;
198 } 204 }
199 205
200 bool CustomElementsRegistry::v0NameIsDefined(const AtomicString& name) 206 bool CustomElementsRegistry::v0NameIsDefined(const AtomicString& name)
201 { 207 {
202 return m_v0.get() && m_v0->nameIsDefined(name); 208 return m_v0.get() && m_v0->nameIsDefined(name);
203 } 209 }
204 210
205 DEFINE_TRACE(CustomElementsRegistry) 211 DEFINE_TRACE(CustomElementsRegistry)
206 { 212 {
207 visitor->trace(m_definitions); 213 visitor->trace(m_definitions);
208 visitor->trace(m_v0); 214 visitor->trace(m_v0);
209 } 215 }
210 216
211 } // namespace blink 217 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698