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 {# 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 #} | |
17 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain({{ v8_class}}::domTemplate(info.GetIsolate(), worldType(info.GetIsolate()))); | 21 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain({{ v8_class}}::domTemplate(info.GetIsolate(), worldType(info.GetIsolate()))); |
haraken
2014/02/06 07:57:44
I don't think we need this look up. I think we can
Nils Barth (inactive)
2014/02/06 08:40:14
Got it, added a FIXME.
| |
18 if (holder.IsEmpty()) | 22 if (holder.IsEmpty()) |
19 return; | 23 return; |
24 {% endif %}{# Window #} | |
20 {{cpp_class}}* imp = {{v8_class}}::toNative(holder); | 25 {{cpp_class}}* imp = {{v8_class}}::toNative(holder); |
21 {% endif %} | 26 {% 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}}"); | 27 v8::Handle<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{a ttribute.name}}"); |
24 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder()); | 28 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder()); |
25 if (!imp->{{attribute.cached_attribute_validation_method}}()) { | 29 if (!imp->{{attribute.cached_attribute_validation_method}}()) { |
26 v8::Handle<v8::Value> jsValue = getHiddenValue(info.GetIsolate(), info.H older(), propertyName); | 30 v8::Handle<v8::Value> jsValue = getHiddenValue(info.GetIsolate(), info.H older(), propertyName); |
27 if (!jsValue.IsEmpty()) { | 31 if (!jsValue.IsEmpty()) { |
28 v8SetReturnValue(info, jsValue); | 32 v8SetReturnValue(info, jsValue); |
29 return; | 33 return; |
30 } | 34 } |
31 } | 35 } |
32 {% elif not (attribute.is_static or attribute.is_unforgeable) %} | 36 {% elif not (attribute.is_static or attribute.is_unforgeable) %} |
33 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder()); | 37 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder()); |
34 {% endif %} | 38 {% endif %}{# imp #} |
35 {% if attribute.reflect_only %} | 39 {% if attribute.reflect_only %} |
36 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_origi nal}}; | 40 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_origi nal}}; |
37 {{release_only_check(attribute.reflect_only, attribute.reflect_missing, | 41 {{release_only_check(attribute.reflect_only, attribute.reflect_missing, |
38 attribute.reflect_invalid, attribute.reflect_empty) | 42 attribute.reflect_invalid, attribute.reflect_empty) |
39 | indent}} | 43 | indent}} |
40 {% endif %} | 44 {% endif %} |
41 {% if attribute.is_call_with_execution_context %} | 45 {% if attribute.is_call_with_execution_context %} |
42 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()) ; | 46 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()) ; |
43 {% endif %} | 47 {% endif %} |
44 {# Special cases #} | 48 {# Special cases #} |
45 {% if attribute.is_check_security_for_node or | 49 {% if attribute.is_check_security_for_node or |
46 attribute.is_getter_raises_exception %} | 50 attribute.is_getter_raises_exception %} |
47 ExceptionState exceptionState(ExceptionState::GetterContext, "{{attribute.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | 51 ExceptionState exceptionState(ExceptionState::GetterContext, "{{attribute.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); |
48 {% endif %} | 52 {% endif %} |
49 {% if attribute.is_check_security_for_node %} | 53 {% if attribute.is_check_security_for_node %} |
50 {# FIXME: consider using a local variable to not call getter twice #} | 54 {# FIXME: consider using a local variable to not call getter twice #} |
51 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), {{attribute .cpp_value}}, exceptionState)) { | 55 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), {{attribute .cpp_value}}, exceptionState)) { |
52 v8SetReturnValueNull(info); | 56 v8SetReturnValueNull(info); |
53 exceptionState.throwIfNeeded(); | 57 exceptionState.throwIfNeeded(); |
54 return; | 58 return; |
55 } | 59 } |
56 {% endif %} | 60 {% endif %} |
57 {% if attribute.is_getter_raises_exception %} | 61 {% if attribute.is_getter_raises_exception %} |
58 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_origi nal}}; | 62 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_origi nal}}; |
59 if (UNLIKELY(exceptionState.throwIfNeeded())) | 63 if (UNLIKELY(exceptionState.throwIfNeeded())) |
60 return; | 64 return; |
61 {% endif %} | 65 {% endif %} |
66 {% if interface_name == 'Window' and attribute.idl_type == 'EventHandler' %} | |
67 if (!imp->document()) | |
68 return; | |
69 {% endif %} | |
62 {% if attribute.is_nullable %} | 70 {% if attribute.is_nullable %} |
63 bool isNull = false; | 71 bool isNull = false; |
64 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_origi nal}}; | 72 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_origi nal}}; |
65 if (isNull) { | 73 if (isNull) { |
66 v8SetReturnValueNull(info); | 74 v8SetReturnValueNull(info); |
67 return; | 75 return; |
68 } | 76 } |
69 {% elif attribute.idl_type == 'EventHandler' or | 77 {% elif attribute.idl_type == 'EventHandler' or |
70 (attribute.cached_attribute_validation_method and | 78 (attribute.cached_attribute_validation_method and |
71 not attribute.is_getter_raises_exception) %}{# Already assigned #} | 79 not attribute.is_getter_raises_exception) %}{# Already assigned #} |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 {% endif %} | 192 {% endif %} |
185 {% if attribute.has_strict_type_checking %} | 193 {% if attribute.has_strict_type_checking %} |
186 {# Type checking for interface types (if interface not implemented, throw | 194 {# Type checking for interface types (if interface not implemented, throw |
187 TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} | 195 TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} |
188 if (!isUndefinedOrNull(jsValue) && !V8{{attribute.idl_type}}::hasInstance(js Value, info.GetIsolate())) { | 196 if (!isUndefinedOrNull(jsValue) && !V8{{attribute.idl_type}}::hasInstance(js Value, info.GetIsolate())) { |
189 exceptionState.throwTypeError("The provided value is not of type '{{attr ibute.idl_type}}'."); | 197 exceptionState.throwTypeError("The provided value is not of type '{{attr ibute.idl_type}}'."); |
190 exceptionState.throwIfNeeded(); | 198 exceptionState.throwIfNeeded(); |
191 return; | 199 return; |
192 } | 200 } |
193 {% endif %} | 201 {% endif %} |
194 {% if attribute.put_forwards %} | 202 {% if interface_name == 'Window' and attribute.idl_type == 'EventHandler' %} |
203 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder()); | |
haraken
2014/02/06 07:57:44
This branch is doing exactly the same thing as the
Nils Barth (inactive)
2014/02/06 08:40:14
You mean the {% elif not attribute.is_static %} br
| |
204 {% elif attribute.put_forwards %} | |
195 {{cpp_class}}* proxyImp = {{v8_class}}::toNative(info.Holder()); | 205 {{cpp_class}}* proxyImp = {{v8_class}}::toNative(info.Holder()); |
196 {{attribute.idl_type}}* imp = proxyImp->{{attribute.name}}(); | 206 {{attribute.idl_type}}* imp = proxyImp->{{attribute.name}}(); |
197 if (!imp) | 207 if (!imp) |
198 return; | 208 return; |
199 {% elif not attribute.is_static %} | 209 {% elif not attribute.is_static %} |
200 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder()); | 210 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder()); |
201 {% endif %} | 211 {% endif %}{# imp #} |
202 {% if attribute.idl_type == 'EventHandler' and interface_name == 'Window' %} | 212 {% if attribute.idl_type == 'EventHandler' and interface_name == 'Window' %} |
203 if (!imp->document()) | 213 if (!imp->document()) |
204 return; | 214 return; |
205 {% endif %} | 215 {% endif %} |
206 {% if attribute.idl_type != 'EventHandler' %} | 216 {% if attribute.idl_type != 'EventHandler' %} |
207 {{attribute.v8_value_to_local_cpp_value}}; | 217 {{attribute.v8_value_to_local_cpp_value}}; |
208 {% elif not is_node %}{# EventHandler hack #} | 218 {% elif not is_node %}{# EventHandler hack #} |
209 moveEventListenerToNewWrapper(info.Holder(), {{attribute.event_handler_gette r_expression}}, jsValue, {{v8_class}}::eventListenerCacheIndex, info.GetIsolate( )); | 219 moveEventListenerToNewWrapper(info.Holder(), {{attribute.event_handler_gette r_expression}}, jsValue, {{v8_class}}::eventListenerCacheIndex, info.GetIsolate( )); |
210 {% endif %} | 220 {% endif %} |
211 {% if attribute.enum_validation_expression %} | 221 {% if attribute.enum_validation_expression %} |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 {% endif %} | 278 {% endif %} |
269 {% if attribute.has_custom_setter %} | 279 {% if attribute.has_custom_setter %} |
270 {{v8_class}}::{{attribute.name}}AttributeSetterCustom(jsValue, info); | 280 {{v8_class}}::{{attribute.name}}AttributeSetterCustom(jsValue, info); |
271 {% else %} | 281 {% else %} |
272 {{cpp_class}}V8Internal::{{attribute.name}}AttributeSetter{{world_suffix}}(j sValue, info); | 282 {{cpp_class}}V8Internal::{{attribute.name}}AttributeSetter{{world_suffix}}(j sValue, info); |
273 {% endif %} | 283 {% endif %} |
274 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution"); | 284 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution"); |
275 } | 285 } |
276 {% endfilter %} | 286 {% endfilter %} |
277 {% endmacro %} | 287 {% endmacro %} |
OLD | NEW |