Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: Source/bindings/templates/attributes.cpp

Issue 214143003: Bindings: use |holder| local variable in attribute getters and setters (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/bindings/tests/results/V8SVGTestInterface.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 {%- if attribute.is_expose_js_accessors %} 202 {%- if attribute.is_expose_js_accessors %}
205 v8::Local<v8::Value> jsValue, const v8::FunctionCallbackInfo<v8::Value>& info 203 v8::Local<v8::Value> jsValue, const v8::FunctionCallbackInfo<v8::Value>& info
206 {%- else %} 204 {%- else %}
207 v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info 205 v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info
208 {%- endif %}) 206 {%- endif %})
209 { 207 {
210 {% if attribute.is_reflect and attribute.idl_type == 'DOMString' and 208 {% if attribute.is_reflect and attribute.idl_type == 'DOMString' and
211 is_node %} 209 is_node %}
212 {% set cpp_class, v8_class = 'Element', 'V8Element' %} 210 {% set cpp_class, v8_class = 'Element', 'V8Element' %}
213 {% endif %} 211 {% endif %}
212 {# Local variables #}
213 {% if not attribute.is_static %}
214 v8::Handle<v8::Object> holder = info.Holder();
215 {% endif %}
214 {% if attribute.has_setter_exception_state %} 216 {% if attribute.has_setter_exception_state %}
215 ExceptionState exceptionState(ExceptionState::SetterContext, "{{attribute.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); 217 ExceptionState exceptionState(ExceptionState::SetterContext, "{{attribute.na me}}", "{{interface_name}}", holder, info.GetIsolate());
216 {% endif %} 218 {% endif %}
219 {# Type checking #}
217 {% if attribute.has_strict_type_checking %} 220 {% if attribute.has_strict_type_checking %}
218 {# Type checking for interface types (if interface not implemented, throw 221 {# Type checking for interface types (if interface not implemented, throw
219 TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} 222 TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #}
220 if (!isUndefinedOrNull(jsValue) && !V8{{attribute.idl_type}}::hasInstance(js Value, info.GetIsolate())) { 223 if (!isUndefinedOrNull(jsValue) && !V8{{attribute.idl_type}}::hasInstance(js Value, info.GetIsolate())) {
221 exceptionState.throwTypeError("The provided value is not of type '{{attr ibute.idl_type}}'."); 224 exceptionState.throwTypeError("The provided value is not of type '{{attr ibute.idl_type}}'.");
222 exceptionState.throwIfNeeded(); 225 exceptionState.throwIfNeeded();
223 return; 226 return;
224 } 227 }
225 {% endif %} 228 {% endif %}
226 {# impl #} 229 {# impl #}
227 {% if attribute.put_forwards %} 230 {% if attribute.put_forwards %}
228 {{cpp_class}}* proxyImpl = {{v8_class}}::toNative(info.Holder()); 231 {{cpp_class}}* proxyImpl = {{v8_class}}::toNative(holder);
229 {{attribute.ref_ptr}}<{{attribute.idl_type}}> impl = WTF::getPtr(proxyImpl-> {{attribute.name}}()); 232 {{attribute.ref_ptr}}<{{attribute.idl_type}}> impl = WTF::getPtr(proxyImpl-> {{attribute.name}}());
230 if (!impl) 233 if (!impl)
231 return; 234 return;
232 {% elif not attribute.is_static %} 235 {% elif not attribute.is_static %}
233 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); 236 {{cpp_class}}* impl = {{v8_class}}::toNative(holder);
234 {% endif %} 237 {% endif %}
235 {% if attribute.is_implemented_by and not attribute.is_static %} 238 {% if attribute.is_implemented_by and not attribute.is_static %}
236 ASSERT(impl); 239 ASSERT(impl);
237 {% endif %} 240 {% endif %}
238 {% if attribute.idl_type == 'EventHandler' and interface_name == 'Window' %} 241 {% if attribute.idl_type == 'EventHandler' and interface_name == 'Window' %}
239 if (!impl->document()) 242 if (!impl->document())
240 return; 243 return;
241 {% endif %} 244 {% endif %}
242 {# Convert JS value to C++ value #} 245 {# Convert JS value to C++ value #}
243 {% if attribute.idl_type != 'EventHandler' %} 246 {% if attribute.idl_type != 'EventHandler' %}
244 {{attribute.v8_value_to_local_cpp_value}}; 247 {{attribute.v8_value_to_local_cpp_value}};
245 {% elif not is_node %}{# EventHandler hack #} 248 {% elif not is_node %}{# EventHandler hack #}
246 moveEventListenerToNewWrapper(info.Holder(), {{attribute.event_handler_gette r_expression}}, jsValue, {{v8_class}}::eventListenerCacheIndex, info.GetIsolate( )); 249 moveEventListenerToNewWrapper(holder, {{attribute.event_handler_getter_expre ssion}}, jsValue, {{v8_class}}::eventListenerCacheIndex, info.GetIsolate());
247 {% endif %} 250 {% endif %}
248 {% if attribute.enum_validation_expression %} 251 {% if attribute.enum_validation_expression %}
249 {# Setter ignores invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enum s #} 252 {# Setter ignores invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enum s #}
250 String string = cppValue; 253 String string = cppValue;
251 if (!({{attribute.enum_validation_expression}})) 254 if (!({{attribute.enum_validation_expression}}))
252 return; 255 return;
253 {% endif %} 256 {% endif %}
254 {# Pre-set context #} 257 {# Pre-set context #}
255 {% if attribute.is_custom_element_callbacks or 258 {% if attribute.is_custom_element_callbacks or
256 (attribute.is_reflect and 259 (attribute.is_reflect and
257 not(attribute.idl_type == 'DOMString' and is_node)) %} 260 not(attribute.idl_type == 'DOMString' and is_node)) %}
258 {# Skip on compact node DOMString getters #} 261 {# Skip on compact node DOMString getters #}
259 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; 262 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope;
260 {% endif %} 263 {% endif %}
261 {% if attribute.is_call_with_execution_context or 264 {% if attribute.is_call_with_execution_context or
262 attribute.is_setter_call_with_execution_context %} 265 attribute.is_setter_call_with_execution_context %}
263 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()) ; 266 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()) ;
264 {% endif %} 267 {% endif %}
265 {# Set #} 268 {# Set #}
266 {{attribute.cpp_setter}}; 269 {{attribute.cpp_setter}};
267 {# Post-set #} 270 {# Post-set #}
268 {% if attribute.is_setter_raises_exception %} 271 {% if attribute.is_setter_raises_exception %}
269 exceptionState.throwIfNeeded(); 272 exceptionState.throwIfNeeded();
270 {% endif %} 273 {% endif %}
271 {% if attribute.cached_attribute_validation_method %} 274 {% if attribute.cached_attribute_validation_method %}
272 V8HiddenValue::deleteHiddenValue(info.GetIsolate(), info.Holder(), v8AtomicS tring(info.GetIsolate(), "{{attribute.name}}")); // Invalidate the cached value. 275 V8HiddenValue::deleteHiddenValue(info.GetIsolate(), holder, v8AtomicString(i nfo.GetIsolate(), "{{attribute.name}}")); // Invalidate the cached value.
273 {% endif %} 276 {% endif %}
274 } 277 }
275 {% endfilter %} 278 {% endfilter %}
276 {% endmacro %} 279 {% endmacro %}
277 280
278 281
279 {##############################################################################} 282 {##############################################################################}
280 {% macro attribute_setter_callback(attribute, world_suffix) %} 283 {% macro attribute_setter_callback(attribute, world_suffix) %}
281 {% filter conditional(attribute.conditional_string) %} 284 {% filter conditional(attribute.conditional_string) %}
282 static void {{attribute.name}}AttributeSetterCallback{{world_suffix}}( 285 static void {{attribute.name}}AttributeSetterCallback{{world_suffix}}(
(...skipping 25 matching lines...) Expand all
308 {% endif %} 311 {% endif %}
309 {% if attribute.has_custom_setter %} 312 {% if attribute.has_custom_setter %}
310 {{v8_class}}::{{attribute.name}}AttributeSetterCustom(jsValue, info); 313 {{v8_class}}::{{attribute.name}}AttributeSetterCustom(jsValue, info);
311 {% else %} 314 {% else %}
312 {{cpp_class}}V8Internal::{{attribute.name}}AttributeSetter{{world_suffix}}(j sValue, info); 315 {{cpp_class}}V8Internal::{{attribute.name}}AttributeSetter{{world_suffix}}(j sValue, info);
313 {% endif %} 316 {% endif %}
314 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution"); 317 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
315 } 318 }
316 {% endfilter %} 319 {% endfilter %}
317 {% endmacro %} 320 {% endmacro %}
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/tests/results/V8SVGTestInterface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698