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..abd21d8186ccdca30714240e78b364c5f03cee99 100644 |
--- a/third_party/WebKit/Source/core/dom/custom/CustomElementsRegistry.cpp |
+++ b/third_party/WebKit/Source/core/dom/custom/CustomElementsRegistry.cpp |
@@ -23,6 +23,15 @@ |
namespace blink { |
+namespace { |
+ |
+const int kConstructorIndex = 0; |
+const int kPrototypeIndex = 1; |
+const int kSizeOfIdMapEntry = 2; |
+ |
+} // namespace |
+ |
+ |
CustomElementsRegistry* CustomElementsRegistry::create( |
ScriptState* scriptState, |
V0CustomElementRegistrationContext* v0) |
@@ -137,10 +146,13 @@ void CustomElementsRegistry::define(ScriptState* scriptState, |
// This map is stored in a hidden reference from the |
// CustomElementsRegistry wrapper. |
v8::Local<v8::Map> map = idMap(scriptState); |
+ v8::Local<v8::Array> mapEntry = v8::Array::New(isolate, kSizeOfIdMapEntry); |
+ v8CallOrCrash(mapEntry->Set(context, kConstructorIndex, constructor)); |
+ v8CallOrCrash(mapEntry->Set(context, kPrototypeIndex, prototype)); |
// The map keeps the constructor and prototypes alive. |
v8CallOrCrash(map->Set(context, constructor, idValue)); |
- v8CallOrCrash(map->Set(context, idValue, prototype)); |
- m_names.add(name); |
+ v8CallOrCrash(map->Set(context, idValue, mapEntry)); |
+ m_names.add(name, id); |
// TODO(dominicc): Implement steps: |
// 20: when-defined promise processing |
@@ -157,15 +169,33 @@ CustomElementDefinition* CustomElementsRegistry::definitionForConstructor( |
return m_definitions[id]; |
} |
+// https://html.spec.whatwg.org/multipage/scripting.html#dom-customelementsregistry-get |
+ScriptValue CustomElementsRegistry::get( |
+ ScriptState* scriptState, |
+ const AtomicString& name) |
+{ |
+ DCHECK(scriptState->world().isMainWorld()); |
+ const auto& it = m_names.find(name); |
+ if (it == m_names.end()) |
+ return ScriptValue(scriptState, v8Undefined()); |
+ v8::Local<v8::Context> context = scriptState->context(); |
+ v8::Local<v8::Map> map = idMap(scriptState); |
+ v8::Local<v8::Value> mapEntry = v8CallOrCrash( |
+ map->Get(context, toV8(it->value, scriptState))); |
+ DCHECK(mapEntry->IsArray()) << *v8::String::Utf8Value(mapEntry); |
+ v8::Local<v8::Value> result = v8CallOrCrash( |
+ mapEntry.As<v8::Array>()->Get(context, kConstructorIndex)); |
+ return ScriptValue(scriptState, result); |
+} |
+ |
v8::Local<v8::Object> CustomElementsRegistry::prototype( |
ScriptState* scriptState, |
const CustomElementDefinition& def) |
{ |
- v8::Local<v8::Value> idValue = |
- v8::Integer::NewFromUnsigned(scriptState->isolate(), def.id()); |
- return v8CallOrCrash( |
- idMap(scriptState)->Get(scriptState->context(), idValue)) |
- .As<v8::Object>(); |
+ v8::Local<v8::Value> idValue = toV8(def.id(), scriptState); |
+ v8::Local<v8::Value> mapEntry = v8CallOrCrash( |
+ idMap(scriptState)->Get(scriptState->context(), idValue)); |
+ return mapEntry.As<v8::Array>()->Get(kPrototypeIndex).As<v8::Object>(); |
} |
bool CustomElementsRegistry::nameIsDefined(const AtomicString& name) const |
@@ -173,6 +203,8 @@ bool CustomElementsRegistry::nameIsDefined(const AtomicString& name) const |
return m_names.contains(name); |
} |
+// Note: Since |toV8(this, scriptState)| requires non-const pointer, we can't |
+// make |idMap()| as const function. |
v8::Local<v8::Map> CustomElementsRegistry::idMap(ScriptState* scriptState) |
{ |
DCHECK(scriptState->world().isMainWorld()); |