| 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" |
| 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_state(State::ScriptNotInitialized) |
| 38 , m_v0(v0) |
| 51 { | 39 { |
| 52 } | 40 } |
| 53 | 41 |
| 54 // http://w3c.github.io/webcomponents/spec/custom/#dfn-element-definition | 42 // http://w3c.github.io/webcomponents/spec/custom/#dfn-element-definition |
| 55 void CustomElementsRegistry::define(ScriptState* scriptState, | 43 void CustomElementsRegistry::define(ScriptState* scriptState, |
| 56 const AtomicString& name, const ScriptValue& constructorScriptValue, | 44 const AtomicString& name, const ScriptValue& constructorScriptValue, |
| 57 const ElementRegistrationOptions& options, ExceptionState& exceptionState) | 45 const ElementRegistrationOptions& options, ExceptionState& exceptionState) |
| 58 { | 46 { |
| 59 DCHECK(scriptState->world().isMainWorld()); | 47 DCHECK(scriptState->world().isMainWorld()); |
| 60 v8::Isolate* isolate = scriptState->isolate(); | 48 v8::Isolate* isolate = scriptState->isolate(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 return v8CallOrCrash( | 151 return v8CallOrCrash( |
| 164 idMap(scriptState)->Get(scriptState->context(), idValue)) | 152 idMap(scriptState)->Get(scriptState->context(), idValue)) |
| 165 .As<v8::Object>(); | 153 .As<v8::Object>(); |
| 166 } | 154 } |
| 167 | 155 |
| 168 bool CustomElementsRegistry::nameIsDefined(const AtomicString& name) const | 156 bool CustomElementsRegistry::nameIsDefined(const AtomicString& name) const |
| 169 { | 157 { |
| 170 return m_names.contains(name); | 158 return m_names.contains(name); |
| 171 } | 159 } |
| 172 | 160 |
| 161 void CustomElementsRegistry::initializeScript(ScriptState* scriptState) |
| 162 { |
| 163 CHECK(State::ScriptNotInitialized == m_state); |
| 164 CHECK(scriptState->world().isMainWorld()); |
| 165 v8::Local<v8::Object> wrapper = toV8(this, scriptState).As<v8::Object>(); |
| 166 v8::Isolate* isolate = scriptState->isolate(); |
| 167 v8::Local<v8::String> name = |
| 168 V8HiddenValue::customElementsRegistryMap(isolate); |
| 169 v8::Local<v8::Map> map = v8::Map::New(isolate); |
| 170 V8HiddenValue::setHiddenValue(scriptState, wrapper, name, map); |
| 171 m_state = State::ScriptInitialized; |
| 172 } |
| 173 |
| 173 v8::Local<v8::Map> CustomElementsRegistry::idMap(ScriptState* scriptState) | 174 v8::Local<v8::Map> CustomElementsRegistry::idMap(ScriptState* scriptState) |
| 174 { | 175 { |
| 175 DCHECK(scriptState->world().isMainWorld()); | 176 CHECK(scriptState->world().isMainWorld()); |
| 176 v8::Local<v8::Object> wrapper = | 177 ensureScriptInitialized(scriptState); |
| 177 toV8(this, scriptState).As<v8::Object>(); | 178 v8::Local<v8::Object> wrapper = toV8(this, scriptState).As<v8::Object>(); |
| 178 v8::Local<v8::String> name = V8HiddenValue::customElementsRegistryMap( | 179 v8::Local<v8::String> name = V8HiddenValue::customElementsRegistryMap( |
| 179 scriptState->isolate()); | 180 scriptState->isolate()); |
| 180 return V8HiddenValue::getHiddenValue(scriptState, wrapper, name) | 181 return V8HiddenValue::getHiddenValue(scriptState, wrapper, name) |
| 181 .As<v8::Map>(); | 182 .As<v8::Map>(); |
| 182 } | 183 } |
| 183 | 184 |
| 184 bool CustomElementsRegistry::idForConstructor( | 185 bool CustomElementsRegistry::idForConstructor( |
| 185 ScriptState* scriptState, | 186 ScriptState* scriptState, |
| 186 v8::Local<v8::Value> constructor, | 187 v8::Local<v8::Value> constructor, |
| 187 Id& id) | 188 Id& id) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 199 return m_v0.get() && m_v0->nameIsDefined(name); | 200 return m_v0.get() && m_v0->nameIsDefined(name); |
| 200 } | 201 } |
| 201 | 202 |
| 202 DEFINE_TRACE(CustomElementsRegistry) | 203 DEFINE_TRACE(CustomElementsRegistry) |
| 203 { | 204 { |
| 204 visitor->trace(m_definitions); | 205 visitor->trace(m_definitions); |
| 205 visitor->trace(m_v0); | 206 visitor->trace(m_v0); |
| 206 } | 207 } |
| 207 | 208 |
| 208 } // namespace blink | 209 } // namespace blink |
| OLD | NEW |