OLD | NEW |
---|---|
1 {##############################################################################} | 1 {##############################################################################} |
2 {% macro attribute_getter(attribute, world_suffix) %} | 2 {% macro attribute_getter(attribute, world_suffix) %} |
3 {% filter conditional(attribute.conditional_string) %} | 3 {% filter conditional(attribute.conditional_string) %} |
4 static void {{attribute.name}}AttributeGetter{{world_suffix}}( | 4 static void {{attribute.name}}AttributeGetter{{world_suffix}}( |
5 {%- if attribute.is_expose_js_accessors %} | 5 {%- if attribute.is_expose_js_accessors %} |
6 const v8::FunctionCallbackInfo<v8::Value>& info | 6 const v8::FunctionCallbackInfo<v8::Value>& info |
7 {%- else %} | 7 {%- else %} |
8 const v8::PropertyCallbackInfo<v8::Value>& info | 8 const v8::PropertyCallbackInfo<v8::Value>& info |
9 {%- endif %}) | 9 {%- endif %}) |
10 { | 10 { |
11 {% if attribute.is_reflect and not attribute.is_url and | 11 {% if attribute.is_reflect and not attribute.is_url and |
12 attribute.idl_type == 'DOMString' and is_node %} | 12 attribute.idl_type == 'DOMString' and is_node %} |
13 {% set cpp_class, v8_class = 'Element', 'V8Element' %} | 13 {% set cpp_class, v8_class = 'Element', 'V8Element' %} |
14 {% endif %} | 14 {% endif %} |
15 {# impl #} | 15 {# holder #} |
16 {# FIXME: use a local variable for holder more often and simplify below #} | 16 {% if attribute.is_unforgeable and interface_name != 'Window' %} |
17 {% if attribute.is_unforgeable or | 17 {# perform lookup first #} |
18 interface_name == 'Window' and attribute.idl_type == 'EventHandler' %} | |
19 {% if interface_name == 'Window' %} | |
20 v8::Handle<v8::Object> holder = info.Holder(); | |
21 {% else %}{# perform lookup first #} | |
22 {# FIXME: can we remove this lookup? #} | 18 {# FIXME: can we remove this lookup? #} |
23 v8::Handle<v8::Object> holder = {{v8_class}}::findInstanceInPrototypeChain(i nfo.This(), info.GetIsolate()); | 19 v8::Handle<v8::Object> holder = {{v8_class}}::findInstanceInPrototypeChain(i nfo.This(), info.GetIsolate()); |
24 if (holder.IsEmpty()) | 20 if (holder.IsEmpty()) |
25 return; | 21 return; |
26 {% endif %}{# Window #} | 22 {% elif not attribute.is_static %} |
23 v8::Handle<v8::Object> holder = info.Holder(); | |
24 {% endif %} | |
25 {# impl #} | |
26 {% if attribute.cached_attribute_validation_method %} | |
27 v8::Handle<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{a ttribute.name}}"); | |
27 {{cpp_class}}* impl = {{v8_class}}::toNative(holder); | 28 {{cpp_class}}* impl = {{v8_class}}::toNative(holder); |
28 {% elif attribute.cached_attribute_validation_method %} | |
29 v8::Handle<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{a ttribute.name}}"); | |
30 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); | |
31 if (!impl->{{attribute.cached_attribute_validation_method}}()) { | 29 if (!impl->{{attribute.cached_attribute_validation_method}}()) { |
32 v8::Handle<v8::Value> jsValue = V8HiddenValue::getHiddenValue(info.GetIs olate(), info.Holder(), propertyName); | 30 v8::Handle<v8::Value> jsValue = V8HiddenValue::getHiddenValue(info.GetIs olate(), holder, propertyName); |
33 if (!jsValue.IsEmpty()) { | 31 if (!jsValue.IsEmpty()) { |
34 v8SetReturnValue(info, jsValue); | 32 v8SetReturnValue(info, jsValue); |
35 return; | 33 return; |
36 } | 34 } |
37 } | 35 } |
38 {% elif not (attribute.is_static or attribute.is_unforgeable) %} | 36 {% elif not attribute.is_static %} |
39 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); | 37 {{cpp_class}}* impl = {{v8_class}}::toNative(holder); |
40 {% endif %} | 38 {% endif %} |
41 {% if attribute.is_implemented_by and not attribute.is_static %} | 39 {% if attribute.is_implemented_by and not attribute.is_static %} |
42 ASSERT(impl); | 40 ASSERT(impl); |
43 {% endif %} | 41 {% endif %} |
44 {% if interface_name == 'Window' and attribute.idl_type == 'EventHandler' %} | 42 {% if interface_name == 'Window' and attribute.idl_type == 'EventHandler' %} |
45 if (!impl->document()) | 43 if (!impl->document()) |
46 return; | 44 return; |
47 {% endif %} | 45 {% endif %} |
48 {# Local variables #} | 46 {# Local variables #} |
49 {% if attribute.is_call_with_execution_context %} | 47 {% if attribute.is_call_with_execution_context %} |
50 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()) ; | 48 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()) ; |
51 {% endif %} | 49 {% endif %} |
52 {% if attribute.is_check_security_for_node or | 50 {% if attribute.is_check_security_for_node or |
53 attribute.is_getter_raises_exception %} | 51 attribute.is_getter_raises_exception %} |
54 ExceptionState exceptionState(ExceptionState::GetterContext, "{{attribute.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | 52 ExceptionState exceptionState(ExceptionState::GetterContext, "{{attribute.na me}}", "{{interface_name}}", holder, info.GetIsolate()); |
55 {% endif %} | 53 {% endif %} |
56 {% if attribute.is_nullable %} | 54 {% if attribute.is_nullable %} |
57 bool isNull = false; | 55 bool isNull = false; |
58 {% endif %} | 56 {% endif %} |
59 {# FIXME: consider always using a local variable for value #} | 57 {# FIXME: consider always using a local variable for value #} |
60 {% if attribute.cached_attribute_validation_method or | 58 {% if attribute.cached_attribute_validation_method or |
61 attribute.is_getter_raises_exception or | 59 attribute.is_getter_raises_exception or |
62 attribute.is_nullable or | 60 attribute.is_nullable or |
63 attribute.reflect_only or | 61 attribute.reflect_only or |
64 attribute.idl_type == 'EventHandler' %} | 62 attribute.idl_type == 'EventHandler' %} |
(...skipping 17 matching lines...) Expand all Loading... | |
82 attribute.reflect_invalid, attribute.reflect_empty) | 80 attribute.reflect_invalid, attribute.reflect_empty) |
83 | indent}} | 81 | indent}} |
84 {% endif %} | 82 {% endif %} |
85 {% if attribute.is_nullable %} | 83 {% if attribute.is_nullable %} |
86 if (isNull) { | 84 if (isNull) { |
87 v8SetReturnValueNull(info); | 85 v8SetReturnValueNull(info); |
88 return; | 86 return; |
89 } | 87 } |
90 {% endif %} | 88 {% endif %} |
91 {% if attribute.cached_attribute_validation_method %} | 89 {% if attribute.cached_attribute_validation_method %} |
92 V8HiddenValue::setHiddenValue(info.GetIsolate(), info.Holder(), propertyName , {{attribute.cpp_value}}.v8Value()); | 90 V8HiddenValue::setHiddenValue(info.GetIsolate(), holder, propertyName, {{att ribute.cpp_value}}.v8Value()); |
93 {% endif %} | 91 {% endif %} |
94 {# v8SetReturnValue #} | 92 {# v8SetReturnValue #} |
95 {% if attribute.is_keep_alive_for_gc %} | 93 {% if attribute.is_keep_alive_for_gc %} |
96 {# FIXME: merge local variable assignment with above #} | 94 {# FIXME: merge local variable assignment with above #} |
97 {{attribute.cpp_type}} result({{attribute.cpp_value}}); | 95 {{attribute.cpp_type}} result({{attribute.cpp_value}}); |
98 if (result && DOMDataStore::setReturnValueFromWrapper{{world_suffix}}<{{attr ibute.v8_type}}>(info.GetReturnValue(), result.get())) | 96 if (result && DOMDataStore::setReturnValueFromWrapper{{world_suffix}}<{{attr ibute.v8_type}}>(info.GetReturnValue(), result.get())) |
99 return; | 97 return; |
100 v8::Handle<v8::Value> wrapper = toV8(result.get(), info.Holder(), info.GetIs olate()); | 98 v8::Handle<v8::Value> wrapper = toV8(result.get(), holder, info.GetIsolate() ); |
101 if (!wrapper.IsEmpty()) { | 99 if (!wrapper.IsEmpty()) { |
102 V8HiddenValue::setHiddenValue(info.GetIsolate(), info.Holder(), v8Atomic String(info.GetIsolate(), "{{attribute.name}}"), wrapper); | 100 V8HiddenValue::setHiddenValue(info.GetIsolate(), holder, v8AtomicString( info.GetIsolate(), "{{attribute.name}}"), wrapper); |
103 {{attribute.v8_set_return_value}}; | 101 {{attribute.v8_set_return_value}}; |
104 } | 102 } |
105 {% elif world_suffix %} | 103 {% elif world_suffix %} |
106 {{attribute.v8_set_return_value_for_main_world}}; | 104 {{attribute.v8_set_return_value_for_main_world}}; |
107 {% else %} | 105 {% else %} |
108 {{attribute.v8_set_return_value}}; | 106 {{attribute.v8_set_return_value}}; |
109 {% endif %} | 107 {% endif %} |
110 } | 108 } |
111 {% endfilter %} | 109 {% endfilter %} |
112 {% endmacro %} | 110 {% endmacro %} |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 {%- if attribute.is_expose_js_accessors %} | 203 {%- if attribute.is_expose_js_accessors %} |
206 v8::Local<v8::Value> jsValue, const v8::FunctionCallbackInfo<v8::Value>& info | 204 v8::Local<v8::Value> jsValue, const v8::FunctionCallbackInfo<v8::Value>& info |
207 {%- else %} | 205 {%- else %} |
208 v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info | 206 v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info |
209 {%- endif %}) | 207 {%- endif %}) |
210 { | 208 { |
211 {% if attribute.is_reflect and attribute.idl_type == 'DOMString' and | 209 {% if attribute.is_reflect and attribute.idl_type == 'DOMString' and |
212 is_node %} | 210 is_node %} |
213 {% set cpp_class, v8_class = 'Element', 'V8Element' %} | 211 {% set cpp_class, v8_class = 'Element', 'V8Element' %} |
214 {% endif %} | 212 {% endif %} |
213 {# Local variables #} | |
214 {% if not attribute.is_static %} | |
215 v8::Handle<v8::Object> holder = info.Holder(); | |
Nils Barth (inactive)
2014/03/27 05:19:46
I've added this for consistency, and b/c it's shor
| |
216 {% endif %} | |
215 {% if attribute.has_setter_exception_state %} | 217 {% if attribute.has_setter_exception_state %} |
216 ExceptionState exceptionState(ExceptionState::SetterContext, "{{attribute.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | 218 ExceptionState exceptionState(ExceptionState::SetterContext, "{{attribute.na me}}", "{{interface_name}}", holder, info.GetIsolate()); |
217 {% endif %} | 219 {% endif %} |
220 {# Type checking #} | |
218 {% if attribute.has_strict_type_checking %} | 221 {% if attribute.has_strict_type_checking %} |
219 {# Type checking for interface types (if interface not implemented, throw | 222 {# Type checking for interface types (if interface not implemented, throw |
220 TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} | 223 TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} |
221 if (!isUndefinedOrNull(jsValue) && !V8{{attribute.idl_type}}::hasInstance(js Value, info.GetIsolate())) { | 224 if (!isUndefinedOrNull(jsValue) && !V8{{attribute.idl_type}}::hasInstance(js Value, info.GetIsolate())) { |
222 exceptionState.throwTypeError("The provided value is not of type '{{attr ibute.idl_type}}'."); | 225 exceptionState.throwTypeError("The provided value is not of type '{{attr ibute.idl_type}}'."); |
223 exceptionState.throwIfNeeded(); | 226 exceptionState.throwIfNeeded(); |
224 return; | 227 return; |
225 } | 228 } |
226 {% endif %} | 229 {% endif %} |
227 {# impl #} | 230 {# impl #} |
228 {% if attribute.put_forwards %} | 231 {% if attribute.put_forwards %} |
229 {{cpp_class}}* proxyImpl = {{v8_class}}::toNative(info.Holder()); | 232 {{cpp_class}}* proxyImpl = {{v8_class}}::toNative(holder); |
230 {{attribute.ref_ptr}}<{{attribute.idl_type}}> impl = WTF::getPtr(proxyImpl-> {{attribute.name}}()); | 233 {{attribute.ref_ptr}}<{{attribute.idl_type}}> impl = WTF::getPtr(proxyImpl-> {{attribute.name}}()); |
231 if (!impl) | 234 if (!impl) |
232 return; | 235 return; |
233 {% elif not attribute.is_static %} | 236 {% elif not attribute.is_static %} |
234 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); | 237 {{cpp_class}}* impl = {{v8_class}}::toNative(holder); |
235 {% endif %} | 238 {% endif %} |
236 {% if attribute.is_implemented_by and not attribute.is_static %} | 239 {% if attribute.is_implemented_by and not attribute.is_static %} |
237 ASSERT(impl); | 240 ASSERT(impl); |
238 {% endif %} | 241 {% endif %} |
239 {% if attribute.idl_type == 'EventHandler' and interface_name == 'Window' %} | 242 {% if attribute.idl_type == 'EventHandler' and interface_name == 'Window' %} |
240 if (!impl->document()) | 243 if (!impl->document()) |
241 return; | 244 return; |
242 {% endif %} | 245 {% endif %} |
243 {# Convert JS value to C++ value #} | 246 {# Convert JS value to C++ value #} |
244 {% if attribute.idl_type != 'EventHandler' %} | 247 {% if attribute.idl_type != 'EventHandler' %} |
245 {{attribute.v8_value_to_local_cpp_value}}; | 248 {{attribute.v8_value_to_local_cpp_value}}; |
246 {% elif not is_node %}{# EventHandler hack #} | 249 {% elif not is_node %}{# EventHandler hack #} |
247 moveEventListenerToNewWrapper(info.Holder(), {{attribute.event_handler_gette r_expression}}, jsValue, {{v8_class}}::eventListenerCacheIndex, info.GetIsolate( )); | 250 moveEventListenerToNewWrapper(holder, {{attribute.event_handler_getter_expre ssion}}, jsValue, {{v8_class}}::eventListenerCacheIndex, info.GetIsolate()); |
248 {% endif %} | 251 {% endif %} |
249 {% if attribute.enum_validation_expression %} | 252 {% if attribute.enum_validation_expression %} |
250 {# Setter ignores invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enum s #} | 253 {# Setter ignores invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enum s #} |
251 String string = cppValue; | 254 String string = cppValue; |
252 if (!({{attribute.enum_validation_expression}})) | 255 if (!({{attribute.enum_validation_expression}})) |
253 return; | 256 return; |
254 {% endif %} | 257 {% endif %} |
255 {# Pre-set context #} | 258 {# Pre-set context #} |
256 {% if attribute.is_custom_element_callbacks or | 259 {% if attribute.is_custom_element_callbacks or |
257 (attribute.is_reflect and | 260 (attribute.is_reflect and |
258 not(attribute.idl_type == 'DOMString' and is_node)) %} | 261 not(attribute.idl_type == 'DOMString' and is_node)) %} |
259 {# Skip on compact node DOMString getters #} | 262 {# Skip on compact node DOMString getters #} |
260 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; | 263 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; |
261 {% endif %} | 264 {% endif %} |
262 {% if attribute.is_call_with_execution_context or | 265 {% if attribute.is_call_with_execution_context or |
263 attribute.is_setter_call_with_execution_context %} | 266 attribute.is_setter_call_with_execution_context %} |
264 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()) ; | 267 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()) ; |
265 {% endif %} | 268 {% endif %} |
266 {# Set #} | 269 {# Set #} |
267 {{attribute.cpp_setter}}; | 270 {{attribute.cpp_setter}}; |
268 {# Post-set #} | 271 {# Post-set #} |
269 {% if attribute.is_setter_raises_exception %} | 272 {% if attribute.is_setter_raises_exception %} |
270 exceptionState.throwIfNeeded(); | 273 exceptionState.throwIfNeeded(); |
271 {% endif %} | 274 {% endif %} |
272 {% if attribute.cached_attribute_validation_method %} | 275 {% if attribute.cached_attribute_validation_method %} |
273 V8HiddenValue::deleteHiddenValue(info.GetIsolate(), info.Holder(), v8AtomicS tring(info.GetIsolate(), "{{attribute.name}}")); // Invalidate the cached value. | 276 V8HiddenValue::deleteHiddenValue(info.GetIsolate(), holder, v8AtomicString(i nfo.GetIsolate(), "{{attribute.name}}")); // Invalidate the cached value. |
274 {% endif %} | 277 {% endif %} |
275 } | 278 } |
276 {% endfilter %} | 279 {% endfilter %} |
277 {% endmacro %} | 280 {% endmacro %} |
278 | 281 |
279 | 282 |
280 {##############################################################################} | 283 {##############################################################################} |
281 {% macro attribute_setter_callback(attribute, world_suffix) %} | 284 {% macro attribute_setter_callback(attribute, world_suffix) %} |
282 {% filter conditional(attribute.conditional_string) %} | 285 {% filter conditional(attribute.conditional_string) %} |
283 static void {{attribute.name}}AttributeSetterCallback{{world_suffix}}( | 286 static void {{attribute.name}}AttributeSetterCallback{{world_suffix}}( |
(...skipping 25 matching lines...) Expand all Loading... | |
309 {% endif %} | 312 {% endif %} |
310 {% if attribute.has_custom_setter %} | 313 {% if attribute.has_custom_setter %} |
311 {{v8_class}}::{{attribute.name}}AttributeSetterCustom(jsValue, info); | 314 {{v8_class}}::{{attribute.name}}AttributeSetterCustom(jsValue, info); |
312 {% else %} | 315 {% else %} |
313 {{cpp_class}}V8Internal::{{attribute.name}}AttributeSetter{{world_suffix}}(j sValue, info); | 316 {{cpp_class}}V8Internal::{{attribute.name}}AttributeSetter{{world_suffix}}(j sValue, info); |
314 {% endif %} | 317 {% endif %} |
315 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution"); | 318 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution"); |
316 } | 319 } |
317 {% endfilter %} | 320 {% endfilter %} |
318 {% endmacro %} | 321 {% endmacro %} |
OLD | NEW |