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 "bindings/core/v8/ScriptCustomElementDefinitionBuilder.h" | 5 #include "bindings/core/v8/ScriptCustomElementDefinitionBuilder.h" |
6 | 6 |
7 #include "bindings/core/v8/DOMWrapperWorld.h" | 7 #include "bindings/core/v8/DOMWrapperWorld.h" |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptCustomElementDefinition.h" | 9 #include "bindings/core/v8/ScriptCustomElementDefinition.h" |
10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 | 53 |
54 // Constructor is already registered. | 54 // Constructor is already registered. |
55 m_exceptionState.throwDOMException( | 55 m_exceptionState.throwDOMException( |
56 NotSupportedError, | 56 NotSupportedError, |
57 "this constructor has already been used with this registry"); | 57 "this constructor has already been used with this registry"); |
58 return false; | 58 return false; |
59 } | 59 } |
60 return true; | 60 return true; |
61 } | 61 } |
62 | 62 |
63 bool ScriptCustomElementDefinitionBuilder::getValue( | |
64 const v8::Local<v8::Object>& object, const char* name, | |
65 v8::Local<v8::Value>& value) const | |
66 { | |
67 v8::Isolate* isolate = m_scriptState->isolate(); | |
68 v8::Local<v8::Context> context = m_scriptState->context(); | |
69 v8::Local<v8::String> nameString = v8AtomicString(isolate, name); | |
70 return v8Call(object->Get(context, nameString), value); | |
71 } | |
72 | |
63 bool ScriptCustomElementDefinitionBuilder::checkPrototype() | 73 bool ScriptCustomElementDefinitionBuilder::checkPrototype() |
64 { | 74 { |
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; | 75 v8::Local<v8::Value> prototypeValue; |
70 if (!v8Call( | 76 if (!getValue(m_constructor, "prototype", prototypeValue)) |
71 m_constructor->Get(context, prototypeString), prototypeValue)) { | |
72 return false; | 77 return false; |
73 } | |
74 if (!prototypeValue->IsObject()) { | 78 if (!prototypeValue->IsObject()) { |
75 m_exceptionState.throwTypeError( | 79 m_exceptionState.throwTypeError( |
76 "constructor prototype is not an object"); | 80 "constructor prototype is not an object"); |
77 return false; | 81 return false; |
78 } | 82 } |
79 m_prototype = prototypeValue.As<v8::Object>(); | 83 m_prototype = prototypeValue.As<v8::Object>(); |
80 // If retrieving the prototype destroyed the context, indicate that | 84 // If retrieving the prototype destroyed the context, indicate that |
81 // defining the element should not proceed. | 85 // defining the element should not proceed. |
82 return true; | 86 return true; |
83 } | 87 } |
84 | 88 |
89 bool ScriptCustomElementDefinitionBuilder::getCallable(const char* name, | |
90 v8::Local<v8::Object>& callback) const | |
91 { | |
92 v8::Local<v8::Value> value; | |
93 if (!getValue(m_prototype, name, value)) | |
94 return false; | |
95 if (value->IsUndefined()) | |
96 return true; | |
97 if (!value->IsObject()) { | |
98 m_exceptionState.throwTypeError( | |
99 String::format("\"%s\" is not an object", name)); | |
100 return false; | |
101 } | |
102 callback = value.As<v8::Object>(); | |
103 if (!callback->IsCallable()) { | |
104 m_exceptionState.throwTypeError( | |
105 String::format("\"%s\" is not callable", name)); | |
106 return false; | |
107 } | |
108 return true; | |
109 } | |
110 | |
111 bool ScriptCustomElementDefinitionBuilder::cacheProperties() | |
112 { | |
113 v8::Local<v8::Value> observedAttributesValue; | |
114 if (!getValue(m_constructor, "observedAttributes", observedAttributesValue)) | |
yosin_UTC9
2016/06/01 06:33:33
Can we have const char* for these bar string liter
kojii
2016/06/01 07:19:27
Done.
| |
115 return false; | |
116 if (!observedAttributesValue->IsUndefined()) { | |
117 m_observedAttributes = toImplArray<Vector<AtomicString>>( | |
118 observedAttributesValue, 0, m_scriptState->isolate(), | |
119 m_exceptionState); | |
120 if (m_exceptionState.hadException()) | |
121 return false; | |
122 } | |
123 | |
124 return getCallable("connectedCallback", m_connectedCallback) | |
125 && getCallable("disconnectedCallback", m_disconnectedCallback) | |
126 && getCallable("attributeChangedCallback", m_attributeChangedCallback); | |
127 } | |
128 | |
85 CustomElementDefinition* ScriptCustomElementDefinitionBuilder::build( | 129 CustomElementDefinition* ScriptCustomElementDefinitionBuilder::build( |
86 const CustomElementDescriptor& descriptor) | 130 const CustomElementDescriptor& descriptor) |
87 { | 131 { |
88 return ScriptCustomElementDefinition::create( | 132 return ScriptCustomElementDefinition::create( |
89 m_scriptState.get(), | 133 m_scriptState.get(), |
90 m_registry, | 134 m_registry, |
91 descriptor, | 135 descriptor, |
92 m_constructor, | 136 m_constructor, |
93 m_prototype); | 137 m_prototype, |
138 m_connectedCallback, | |
139 m_disconnectedCallback, | |
140 m_attributeChangedCallback, | |
141 m_observedAttributes); | |
94 } | 142 } |
95 | 143 |
96 } // namespace blink | 144 } // namespace blink |
OLD | NEW |