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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 "constructor prototype is not an object"); | 106 "constructor prototype is not an object"); |
107 return false; | 107 return false; |
108 } | 108 } |
109 m_prototype = prototypeValue.As<v8::Object>(); | 109 m_prototype = prototypeValue.As<v8::Object>(); |
110 // If retrieving the prototype destroyed the context, indicate that | 110 // If retrieving the prototype destroyed the context, indicate that |
111 // defining the element should not proceed. | 111 // defining the element should not proceed. |
112 return true; | 112 return true; |
113 } | 113 } |
114 | 114 |
115 bool ScriptCustomElementDefinitionBuilder::callableForName(const String& name, | 115 bool ScriptCustomElementDefinitionBuilder::callableForName(const String& name, |
116 v8::Local<v8::Object>& callback) const | 116 v8::Local<v8::Function>& callback) const |
117 { | 117 { |
118 v8::Local<v8::Value> value; | 118 v8::Local<v8::Value> value; |
119 if (!valueForName(m_prototype, name, value)) | 119 if (!valueForName(m_prototype, name, value)) |
120 return false; | 120 return false; |
121 // "undefined" means "omitted", so return true. | 121 // "undefined" means "omitted", so return true. |
122 if (value->IsUndefined()) | 122 if (value->IsUndefined()) |
123 return true; | 123 return true; |
124 if (!value->IsObject()) { | 124 if (!value->IsFunction()) { |
125 m_exceptionState.throwTypeError( | 125 m_exceptionState.throwTypeError( |
126 String::format("\"%s\" is not an object", name.ascii().data())); | 126 String::format("\"%s\" is not a callable object", name.ascii().data(
))); |
127 return false; | 127 return false; |
128 } | 128 } |
129 callback = value.As<v8::Object>(); | 129 callback = value.As<v8::Function>(); |
130 if (!callback->IsCallable()) { | |
131 m_exceptionState.throwTypeError( | |
132 String::format("\"%s\" is not callable", name.ascii().data())); | |
133 return false; | |
134 } | |
135 return true; | 130 return true; |
136 } | 131 } |
137 | 132 |
138 bool ScriptCustomElementDefinitionBuilder::retrieveObservedAttributes() | 133 bool ScriptCustomElementDefinitionBuilder::retrieveObservedAttributes() |
139 { | 134 { |
140 const String kObservedAttributes = "observedAttributes"; | 135 const String kObservedAttributes = "observedAttributes"; |
141 v8::Local<v8::Value> observedAttributesValue; | 136 v8::Local<v8::Value> observedAttributesValue; |
142 if (!valueForName(m_constructor, kObservedAttributes, observedAttributesValu
e)) | 137 if (!valueForName(m_constructor, kObservedAttributes, observedAttributesValu
e)) |
143 return false; | 138 return false; |
144 if (observedAttributesValue->IsUndefined()) | 139 if (observedAttributesValue->IsUndefined()) |
(...skipping 10 matching lines...) Expand all Loading... |
155 return true; | 150 return true; |
156 } | 151 } |
157 | 152 |
158 bool ScriptCustomElementDefinitionBuilder::rememberOriginalProperties() | 153 bool ScriptCustomElementDefinitionBuilder::rememberOriginalProperties() |
159 { | 154 { |
160 // Spec requires to use values of these properties at the point | 155 // Spec requires to use values of these properties at the point |
161 // CustomElementDefinition is built, even if JS changes them afterwards. | 156 // CustomElementDefinition is built, even if JS changes them afterwards. |
162 const String kConnectedCallback = "connectedCallback"; | 157 const String kConnectedCallback = "connectedCallback"; |
163 const String kDisconnectedCallback = "disconnectedCallback"; | 158 const String kDisconnectedCallback = "disconnectedCallback"; |
164 const String kAttributeChangedCallback = "attributeChangedCallback"; | 159 const String kAttributeChangedCallback = "attributeChangedCallback"; |
165 return retrieveObservedAttributes() | 160 return callableForName(kConnectedCallback, m_connectedCallback) |
166 && callableForName(kConnectedCallback, m_connectedCallback) | |
167 && callableForName(kDisconnectedCallback, m_disconnectedCallback) | 161 && callableForName(kDisconnectedCallback, m_disconnectedCallback) |
168 && callableForName(kAttributeChangedCallback, m_attributeChangedCallback
); | 162 && callableForName(kAttributeChangedCallback, m_attributeChangedCallback
) |
| 163 && (m_attributeChangedCallback.IsEmpty() || retrieveObservedAttributes()
); |
169 } | 164 } |
170 | 165 |
171 CustomElementDefinition* ScriptCustomElementDefinitionBuilder::build( | 166 CustomElementDefinition* ScriptCustomElementDefinitionBuilder::build( |
172 const CustomElementDescriptor& descriptor) | 167 const CustomElementDescriptor& descriptor) |
173 { | 168 { |
174 return ScriptCustomElementDefinition::create( | 169 return ScriptCustomElementDefinition::create( |
175 m_scriptState.get(), | 170 m_scriptState.get(), |
176 m_registry, | 171 m_registry, |
177 descriptor, | 172 descriptor, |
178 m_constructor, | 173 m_constructor, |
179 m_prototype, | 174 m_prototype, |
180 m_connectedCallback, | 175 m_connectedCallback, |
181 m_disconnectedCallback, | 176 m_disconnectedCallback, |
182 m_attributeChangedCallback, | 177 m_attributeChangedCallback, |
183 m_observedAttributes); | 178 m_observedAttributes); |
184 } | 179 } |
185 | 180 |
186 } // namespace blink | 181 } // namespace blink |
OLD | NEW |