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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/custom/CustomElementsRegistry.cpp
diff --git a/third_party/WebKit/Source/core/dom/custom/CustomElementsRegistry.cpp b/third_party/WebKit/Source/core/dom/custom/CustomElementsRegistry.cpp
index 3478c6b4cf5f6f23811b1f505bae7a320310c749..834a2897ebadfb3d6d8d7265165d1381f8d02b15 100644
--- a/third_party/WebKit/Source/core/dom/custom/CustomElementsRegistry.cpp
+++ b/third_party/WebKit/Source/core/dom/custom/CustomElementsRegistry.cpp
@@ -24,24 +24,11 @@
namespace blink {
CustomElementsRegistry* CustomElementsRegistry::create(
- ScriptState* scriptState,
V0CustomElementRegistrationContext* v0)
{
- DCHECK(scriptState->world().isMainWorld());
CustomElementsRegistry* registry = new CustomElementsRegistry(v0);
if (v0)
v0->setV1(registry);
-
- v8::Isolate* isolate = scriptState->isolate();
- v8::Local<v8::Object> wrapper =
- toV8(registry, scriptState).As<v8::Object>();
- v8::Local<v8::String> name =
- V8HiddenValue::customElementsRegistryMap(isolate);
- v8::Local<v8::Map> map = v8::Map::New(isolate);
- bool didSetPrototype =
- V8HiddenValue::setHiddenValue(scriptState, wrapper, name, map);
- DCHECK(didSetPrototype);
-
return registry;
}
@@ -173,15 +160,34 @@ bool CustomElementsRegistry::nameIsDefined(const AtomicString& name) const
return m_names.contains(name);
}
+void CustomElementsRegistry::initializeScript(
haraken 2016/05/23 01:46:37 I'd rename the method to ensureConstructorMap() an
+ ScriptState* scriptState,
+ v8::Local<v8::Map>& map)
+{
+ CHECK(scriptState->world().isMainWorld());
+ v8::Local<v8::Object> wrapper = toV8(this, scriptState).As<v8::Object>();
+ v8::Isolate* isolate = scriptState->isolate();
+ v8::Local<v8::String> name =
+ V8HiddenValue::customElementsRegistryMap(isolate);
+ DCHECK(V8HiddenValue::getHiddenValue(scriptState, wrapper, name).IsEmpty());
+ map = v8::Map::New(isolate);
+ V8HiddenValue::setHiddenValue(scriptState, wrapper, name, map);
+}
+
v8::Local<v8::Map> CustomElementsRegistry::idMap(ScriptState* scriptState)
{
- DCHECK(scriptState->world().isMainWorld());
- v8::Local<v8::Object> wrapper =
- toV8(this, scriptState).As<v8::Object>();
+ CHECK(scriptState->world().isMainWorld());
+ v8::Local<v8::Object> wrapper = toV8(this, scriptState).As<v8::Object>();
v8::Local<v8::String> name = V8HiddenValue::customElementsRegistryMap(
scriptState->isolate());
- return V8HiddenValue::getHiddenValue(scriptState, wrapper, name)
- .As<v8::Map>();
+ v8::Local<v8::Value> mapValue =
+ V8HiddenValue::getHiddenValue(scriptState, wrapper, name);
+ v8::Local<v8::Map> map;
+ if (!mapValue.IsEmpty())
+ map = mapValue.As<v8::Map>();
+ else
+ initializeScript(scriptState, map);
+ return map;
}
bool CustomElementsRegistry::idForConstructor(

Powered by Google App Engine
This is Rietveld 408576698