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

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

Issue 140663012: IDL compiler: Window-specific code + Window-only features (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased Created 6 years, 10 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 | « Source/bindings/scripts/unstable/v8_types.py ('k') | Source/bindings/templates/interface.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 {# FIXME: Perl skips most of function, but this seems unnecessary #} 14 {# FIXME: Perl skips most of function, but this seems unnecessary #}
15 {% endif %} 15 {% endif %}
16 {% if attribute.is_unforgeable %} 16 {% if attribute.is_unforgeable or
17 interface_name == 'Window' and attribute.idl_type == 'EventHandler' %}
18 {% if interface_name == 'Window' %}
19 v8::Handle<v8::Object> holder = info.Holder();
20 {% else %}{# perform lookup first #}
21 {# FIXME: can we remove this lookup? #}
17 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain({{ v8_class}}::domTemplate(info.GetIsolate(), worldType(info.GetIsolate()))); 22 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain({{ v8_class}}::domTemplate(info.GetIsolate(), worldType(info.GetIsolate())));
18 if (holder.IsEmpty()) 23 if (holder.IsEmpty())
19 return; 24 return;
25 {% endif %}{# Window #}
20 {{cpp_class}}* imp = {{v8_class}}::toNative(holder); 26 {{cpp_class}}* imp = {{v8_class}}::toNative(holder);
21 {% endif %} 27 {% elif attribute.cached_attribute_validation_method %}
22 {% if attribute.cached_attribute_validation_method %}
23 v8::Handle<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{a ttribute.name}}"); 28 v8::Handle<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{a ttribute.name}}");
24 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder()); 29 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder());
25 if (!imp->{{attribute.cached_attribute_validation_method}}()) { 30 if (!imp->{{attribute.cached_attribute_validation_method}}()) {
26 v8::Handle<v8::Value> jsValue = getHiddenValue(info.GetIsolate(), info.H older(), propertyName); 31 v8::Handle<v8::Value> jsValue = getHiddenValue(info.GetIsolate(), info.H older(), propertyName);
27 if (!jsValue.IsEmpty()) { 32 if (!jsValue.IsEmpty()) {
28 v8SetReturnValue(info, jsValue); 33 v8SetReturnValue(info, jsValue);
29 return; 34 return;
30 } 35 }
31 } 36 }
32 {% elif not (attribute.is_static or attribute.is_unforgeable) %} 37 {% elif not (attribute.is_static or attribute.is_unforgeable) %}
33 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder()); 38 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder());
34 {% endif %} 39 {% endif %}{# imp #}
35 {% if attribute.reflect_only %} 40 {% if attribute.reflect_only %}
36 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_origi nal}}; 41 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_origi nal}};
37 {{release_only_check(attribute.reflect_only, attribute.reflect_missing, 42 {{release_only_check(attribute.reflect_only, attribute.reflect_missing,
38 attribute.reflect_invalid, attribute.reflect_empty) 43 attribute.reflect_invalid, attribute.reflect_empty)
39 | indent}} 44 | indent}}
40 {% endif %} 45 {% endif %}
41 {% if attribute.is_call_with_execution_context %} 46 {% if attribute.is_call_with_execution_context %}
42 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()) ; 47 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()) ;
43 {% endif %} 48 {% endif %}
44 {# Special cases #} 49 {# Special cases #}
45 {% if attribute.is_check_security_for_node or 50 {% if attribute.is_check_security_for_node or
46 attribute.is_getter_raises_exception %} 51 attribute.is_getter_raises_exception %}
47 ExceptionState exceptionState(ExceptionState::GetterContext, "{{attribute.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); 52 ExceptionState exceptionState(ExceptionState::GetterContext, "{{attribute.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate());
48 {% endif %} 53 {% endif %}
49 {% if attribute.is_check_security_for_node %} 54 {% if attribute.is_check_security_for_node %}
50 {# FIXME: consider using a local variable to not call getter twice #} 55 {# FIXME: consider using a local variable to not call getter twice #}
51 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), {{attribute .cpp_value}}, exceptionState)) { 56 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), {{attribute .cpp_value}}, exceptionState)) {
52 v8SetReturnValueNull(info); 57 v8SetReturnValueNull(info);
53 exceptionState.throwIfNeeded(); 58 exceptionState.throwIfNeeded();
54 return; 59 return;
55 } 60 }
56 {% endif %} 61 {% endif %}
57 {% if attribute.is_getter_raises_exception %} 62 {% if attribute.is_getter_raises_exception %}
58 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_origi nal}}; 63 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_origi nal}};
59 if (UNLIKELY(exceptionState.throwIfNeeded())) 64 if (UNLIKELY(exceptionState.throwIfNeeded()))
60 return; 65 return;
61 {% endif %} 66 {% endif %}
67 {% if interface_name == 'Window' and attribute.idl_type == 'EventHandler' %}
68 if (!imp->document())
69 return;
70 {% endif %}
62 {% if attribute.is_nullable %} 71 {% if attribute.is_nullable %}
63 bool isNull = false; 72 bool isNull = false;
64 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_origi nal}}; 73 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_origi nal}};
65 if (isNull) { 74 if (isNull) {
66 v8SetReturnValueNull(info); 75 v8SetReturnValueNull(info);
67 return; 76 return;
68 } 77 }
69 {% elif attribute.idl_type == 'EventHandler' or 78 {% elif attribute.idl_type == 'EventHandler' or
70 (attribute.cached_attribute_validation_method and 79 (attribute.cached_attribute_validation_method and
71 not attribute.is_getter_raises_exception) %}{# Already assigned #} 80 not attribute.is_getter_raises_exception) %}{# Already assigned #}
72 {# FIXME: consider merging all these assign to local variable statements #} 81 {# FIXME: consider merging all these assign to local variable statements #}
73 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_origi nal}}; 82 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_origi nal}};
74 {% endif %} 83 {% endif %}
75 {% if attribute.cached_attribute_validation_method %} 84 {% if attribute.cached_attribute_validation_method %}
76 setHiddenValue(info.GetIsolate(), info.Holder(), propertyName, {{attribute.c pp_value}}.v8Value()); 85 setHiddenValue(info.GetIsolate(), info.Holder(), propertyName, {{attribute.c pp_value}}.v8Value());
77 {% endif %} 86 {% endif %}
78 {# End special cases #} 87 {# End special cases #}
79 {% if attribute.is_keep_alive_for_gc %} 88 {% if attribute.is_keep_alive_for_gc %}
80 {{attribute.cpp_type}} result = {{attribute.cpp_value}}; 89 {{attribute.cpp_type}} result = {{attribute.cpp_value}};
81 if (result && DOMDataStore::setReturnValueFromWrapper<{{attribute.v8_type}}> (info.GetReturnValue(), result.get())) 90 if (result && DOMDataStore::setReturnValueFromWrapper{{world_suffix}}<{{attr ibute.v8_type}}>(info.GetReturnValue(), result.get()))
82 return; 91 return;
83 v8::Handle<v8::Value> wrapper = toV8(result.get(), info.Holder(), info.GetIs olate()); 92 v8::Handle<v8::Value> wrapper = toV8(result.get(), info.Holder(), info.GetIs olate());
84 if (!wrapper.IsEmpty()) { 93 if (!wrapper.IsEmpty()) {
85 setHiddenValue(info.GetIsolate(), info.Holder(), "{{attribute.name}}", w rapper); 94 setHiddenValue(info.GetIsolate(), info.Holder(), "{{attribute.name}}", w rapper);
86 {{attribute.v8_set_return_value}}; 95 {{attribute.v8_set_return_value}};
87 } 96 }
88 {% else %} 97 {% else %}
89 {% if world_suffix %} 98 {% if world_suffix %}
90 {{attribute.v8_set_return_value_for_main_world}}; 99 {{attribute.v8_set_return_value_for_main_world}};
91 {% else %} 100 {% else %}
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 return; 200 return;
192 } 201 }
193 {% endif %} 202 {% endif %}
194 {% if attribute.put_forwards %} 203 {% if attribute.put_forwards %}
195 {{cpp_class}}* proxyImp = {{v8_class}}::toNative(info.Holder()); 204 {{cpp_class}}* proxyImp = {{v8_class}}::toNative(info.Holder());
196 {{attribute.idl_type}}* imp = proxyImp->{{attribute.name}}(); 205 {{attribute.idl_type}}* imp = proxyImp->{{attribute.name}}();
197 if (!imp) 206 if (!imp)
198 return; 207 return;
199 {% elif not attribute.is_static %} 208 {% elif not attribute.is_static %}
200 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder()); 209 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder());
201 {% endif %} 210 {% endif %}{# imp #}
202 {% if attribute.idl_type == 'EventHandler' and interface_name == 'Window' %} 211 {% if attribute.idl_type == 'EventHandler' and interface_name == 'Window' %}
203 if (!imp->document()) 212 if (!imp->document())
204 return; 213 return;
205 {% endif %} 214 {% endif %}
206 {% if attribute.idl_type != 'EventHandler' %} 215 {% if attribute.idl_type != 'EventHandler' %}
207 {{attribute.v8_value_to_local_cpp_value}}; 216 {{attribute.v8_value_to_local_cpp_value}};
208 {% elif not is_node %}{# EventHandler hack #} 217 {% elif not is_node %}{# EventHandler hack #}
209 moveEventListenerToNewWrapper(info.Holder(), {{attribute.event_handler_gette r_expression}}, jsValue, {{v8_class}}::eventListenerCacheIndex, info.GetIsolate( )); 218 moveEventListenerToNewWrapper(info.Holder(), {{attribute.event_handler_gette r_expression}}, jsValue, {{v8_class}}::eventListenerCacheIndex, info.GetIsolate( ));
210 {% endif %} 219 {% endif %}
211 {% if attribute.enum_validation_expression %} 220 {% if attribute.enum_validation_expression %}
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 {% endif %} 277 {% endif %}
269 {% if attribute.has_custom_setter %} 278 {% if attribute.has_custom_setter %}
270 {{v8_class}}::{{attribute.name}}AttributeSetterCustom(jsValue, info); 279 {{v8_class}}::{{attribute.name}}AttributeSetterCustom(jsValue, info);
271 {% else %} 280 {% else %}
272 {{cpp_class}}V8Internal::{{attribute.name}}AttributeSetter{{world_suffix}}(j sValue, info); 281 {{cpp_class}}V8Internal::{{attribute.name}}AttributeSetter{{world_suffix}}(j sValue, info);
273 {% endif %} 282 {% endif %}
274 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution"); 283 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
275 } 284 }
276 {% endfilter %} 285 {% endfilter %}
277 {% endmacro %} 286 {% endmacro %}
OLDNEW
« no previous file with comments | « Source/bindings/scripts/unstable/v8_types.py ('k') | Source/bindings/templates/interface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698