| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 // http://w3c.github.io/webcomponents/spec/custom/#dfn-element-definition | 54 // http://w3c.github.io/webcomponents/spec/custom/#dfn-element-definition |
| 55 void CustomElementsRegistry::define(ScriptState* scriptState, | 55 void CustomElementsRegistry::define(ScriptState* scriptState, |
| 56 const AtomicString& name, const ScriptValue& constructorScriptValue, | 56 const AtomicString& name, const ScriptValue& constructorScriptValue, |
| 57 const ElementRegistrationOptions& options, ExceptionState& exceptionState) | 57 const ElementRegistrationOptions& options, ExceptionState& exceptionState) |
| 58 { | 58 { |
| 59 DCHECK(scriptState->world().isMainWorld()); | 59 DCHECK(scriptState->world().isMainWorld()); |
| 60 v8::Isolate* isolate = scriptState->isolate(); | 60 v8::Isolate* isolate = scriptState->isolate(); |
| 61 v8::Local<v8::Context> context = scriptState->context(); | 61 v8::Local<v8::Context> context = scriptState->context(); |
| 62 | 62 |
| 63 // TODO(dominicc): Make this check for constructors and not just | |
| 64 // functions when | |
| 65 // https://bugs.chromium.org/p/v8/issues/detail?id=4993 is fixed. | |
| 66 v8::Local<v8::Value> constructorValue = constructorScriptValue.v8Value(); | 63 v8::Local<v8::Value> constructorValue = constructorScriptValue.v8Value(); |
| 67 if (!constructorValue->IsFunction()) { | 64 if (!constructorValue->IsFunction()) { |
| 65 // Not even a function. |
| 68 exceptionState.throwTypeError( | 66 exceptionState.throwTypeError( |
| 69 "constructor argument is not a constructor"); | 67 "constructor argument is not a constructor"); |
| 70 return; | 68 return; |
| 71 } | 69 } |
| 72 v8::Local<v8::Object> constructor = constructorValue.As<v8::Object>(); | 70 v8::Local<v8::Object> constructor = constructorValue.As<v8::Object>(); |
| 71 if (!constructor->IsConstructor()) { |
| 72 exceptionState.throwTypeError( |
| 73 "constructor argument is not a constructor"); |
| 74 return; |
| 75 } |
| 73 | 76 |
| 74 // Raise an exception if the name is not valid. | 77 // Raise an exception if the name is not valid. |
| 75 if (!CustomElement::isValidName(name)) { | 78 if (!CustomElement::isValidName(name)) { |
| 76 exceptionState.throwDOMException( | 79 exceptionState.throwDOMException( |
| 77 SyntaxError, | 80 SyntaxError, |
| 78 "\"" + name + "\" is not a valid custom element name"); | 81 "\"" + name + "\" is not a valid custom element name"); |
| 79 return; | 82 return; |
| 80 } | 83 } |
| 81 | 84 |
| 82 // Raise an exception if the name is already in use. | 85 // Raise an exception if the name is already in use. |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 return m_v0.get() && m_v0->nameIsDefined(name); | 199 return m_v0.get() && m_v0->nameIsDefined(name); |
| 197 } | 200 } |
| 198 | 201 |
| 199 DEFINE_TRACE(CustomElementsRegistry) | 202 DEFINE_TRACE(CustomElementsRegistry) |
| 200 { | 203 { |
| 201 visitor->trace(m_definitions); | 204 visitor->trace(m_definitions); |
| 202 visitor->trace(m_v0); | 205 visitor->trace(m_v0); |
| 203 } | 206 } |
| 204 | 207 |
| 205 } // namespace blink | 208 } // namespace blink |
| OLD | NEW |