OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "bindings/core/v8/ScriptCustomElementDefinitionBuilder.h" |
| 6 |
| 7 #include "bindings/core/v8/DOMWrapperWorld.h" |
| 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "bindings/core/v8/ScriptCustomElementDefinition.h" |
| 10 #include "bindings/core/v8/ScriptState.h" |
| 11 #include "bindings/core/v8/ScriptValue.h" |
| 12 #include "bindings/core/v8/V8Binding.h" |
| 13 #include "bindings/core/v8/V8BindingMacros.h" |
| 14 #include "core/dom/ExceptionCode.h" |
| 15 |
| 16 namespace blink { |
| 17 |
| 18 ScriptCustomElementDefinitionBuilder::ScriptCustomElementDefinitionBuilder( |
| 19 ScriptState* scriptState, |
| 20 CustomElementsRegistry* registry, |
| 21 const ScriptValue& constructor, |
| 22 ExceptionState& exceptionState) |
| 23 : m_scriptState(scriptState) |
| 24 , m_registry(registry) |
| 25 , m_constructorValue(constructor.v8Value()) |
| 26 , m_exceptionState(exceptionState) |
| 27 { |
| 28 } |
| 29 |
| 30 bool ScriptCustomElementDefinitionBuilder::checkConstructorIntrinsics() |
| 31 { |
| 32 DCHECK(m_scriptState->world().isMainWorld()); |
| 33 |
| 34 // The signature of CustomElementsRegistry.define says this is a |
| 35 // Function |
| 36 // https://html.spec.whatwg.org/multipage/scripting.html#customelementsregis
try |
| 37 CHECK(m_constructorValue->IsFunction()); |
| 38 m_constructor = m_constructorValue.As<v8::Object>(); |
| 39 if (!m_constructor->IsConstructor()) { |
| 40 m_exceptionState.throwTypeError( |
| 41 "constructor argument is not a constructor"); |
| 42 return false; |
| 43 } |
| 44 return true; |
| 45 } |
| 46 |
| 47 bool ScriptCustomElementDefinitionBuilder::checkConstructorNotRegistered() |
| 48 { |
| 49 if (ScriptCustomElementDefinition::forConstructor( |
| 50 m_scriptState.get(), |
| 51 m_registry, |
| 52 m_constructor)) { |
| 53 |
| 54 // Constructor is already registered. |
| 55 m_exceptionState.throwDOMException( |
| 56 NotSupportedError, |
| 57 "this constructor has already been used with this registry"); |
| 58 return false; |
| 59 } |
| 60 return true; |
| 61 } |
| 62 |
| 63 bool ScriptCustomElementDefinitionBuilder::checkPrototype() |
| 64 { |
| 65 v8::Isolate* isolate = m_scriptState->isolate(); |
| 66 v8::Local<v8::Context> context = m_scriptState->context(); |
| 67 v8::Local<v8::String> prototypeString = |
| 68 v8AtomicString(isolate, "prototype"); |
| 69 v8::Local<v8::Value> prototypeValue; |
| 70 if (!v8Call( |
| 71 m_constructor->Get(context, prototypeString), prototypeValue)) { |
| 72 return false; |
| 73 } |
| 74 if (!prototypeValue->IsObject()) { |
| 75 m_exceptionState.throwTypeError( |
| 76 "constructor prototype is not an object"); |
| 77 return false; |
| 78 } |
| 79 m_prototype = prototypeValue.As<v8::Object>(); |
| 80 // If retrieving the prototype destroyed the context, indicate that |
| 81 // defining the element should not proceed. |
| 82 return true; |
| 83 } |
| 84 |
| 85 CustomElementDefinition* ScriptCustomElementDefinitionBuilder::build( |
| 86 const CustomElementDescriptor& descriptor) |
| 87 { |
| 88 return ScriptCustomElementDefinition::create( |
| 89 m_scriptState.get(), |
| 90 m_registry, |
| 91 descriptor, |
| 92 m_constructor, |
| 93 m_prototype); |
| 94 } |
| 95 |
| 96 } // namespace blink |
OLD | NEW |