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