OLD | NEW |
---|---|
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 22 matching lines...) Expand all Loading... | |
33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | 33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
34 """ | 34 """ |
35 | 35 |
36 from idl_types import IdlType, IdlUnionType, inherits_interface | 36 from idl_types import IdlType, IdlUnionType, inherits_interface |
37 from v8_globals import includes | 37 from v8_globals import includes |
38 import v8_types | 38 import v8_types |
39 import v8_utilities | 39 import v8_utilities |
40 from v8_utilities import has_extended_attribute_value | 40 from v8_utilities import has_extended_attribute_value |
41 | 41 |
42 | 42 |
43 def argument_needs_try_catch(argument): | |
Nils Barth (inactive)
2014/05/08 00:55:13
I would tend to write this as a single boolean, as
Jens Widell
2014/05/08 07:00:15
And I tend to split conditions into multiple state
Jens Widell
2014/05/08 16:38:05
Updated now. I formatted it
return not (
| |
44 # These cases are handled by separate code paths in the generate_argument() | |
45 # macro in Source/bindings/templates/methods.cpp. | |
46 if (argument['is_callback_interface'] or | |
47 argument['idl_type'] == 'SerializedScriptValue' or | |
48 argument['is_variadic_wrapper_type']): | |
haraken
2014/05/08 03:45:06
I wonder why this condition isn't something like "
Jens Widell
2014/05/08 06:22:06
The 'argument' here is the dictionary returned by
| |
49 return False | |
50 | |
51 # String and enumeration arguments converted using one of the TOSTRING_* | |
52 # macros in Source/bindings/v8/V8BindingMacros.h don't use a v8::TryCatch. | |
53 if argument['v8_value_to_local_cpp_value'].startswith('TOSTRING_'): | |
Nils Barth (inactive)
2014/05/08 00:55:13
How about checking for DOMString directly, as in:
Jens Widell
2014/05/08 06:22:06
I did try something similar (looking just at argum
Nils Barth (inactive)
2014/05/08 06:25:16
Got it, thanks for thoughtful reply.
Yup, fine to
| |
54 return False | |
55 | |
56 return True | |
57 | |
58 | |
43 def generate_method(interface, method): | 59 def generate_method(interface, method): |
44 arguments = method.arguments | 60 arguments = method.arguments |
45 extended_attributes = method.extended_attributes | 61 extended_attributes = method.extended_attributes |
46 idl_type = method.idl_type | 62 idl_type = method.idl_type |
47 is_static = method.is_static | 63 is_static = method.is_static |
48 name = method.name | 64 name = method.name |
49 | 65 |
50 idl_type.add_includes_for_type() | 66 idl_type.add_includes_for_type() |
51 this_cpp_value = cpp_value(interface, method, len(arguments)) | 67 this_cpp_value = cpp_value(interface, method, len(arguments)) |
52 | 68 |
(...skipping 19 matching lines...) Expand all Loading... | |
72 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') | 88 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') |
73 | 89 |
74 has_event_listener_argument = any( | 90 has_event_listener_argument = any( |
75 argument for argument in arguments | 91 argument for argument in arguments |
76 if argument.idl_type.name == 'EventListener') | 92 if argument.idl_type.name == 'EventListener') |
77 is_check_security_for_frame = ( | 93 is_check_security_for_frame = ( |
78 'CheckSecurity' in interface.extended_attributes and | 94 'CheckSecurity' in interface.extended_attributes and |
79 'DoNotCheckSecurity' not in extended_attributes) | 95 'DoNotCheckSecurity' not in extended_attributes) |
80 is_raises_exception = 'RaisesException' in extended_attributes | 96 is_raises_exception = 'RaisesException' in extended_attributes |
81 | 97 |
98 generated_arguments = [generate_argument(interface, method, argument, index) | |
99 for index, argument in enumerate(arguments)] | |
100 | |
82 return { | 101 return { |
83 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging] | 102 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging] |
84 'arguments': [generate_argument(interface, method, argument, index) | 103 'arguments': generated_arguments, |
85 for index, argument in enumerate(arguments)], | 104 'arguments_need_try_catch': any(argument_needs_try_catch(argument) |
105 for argument in generated_arguments), | |
86 'conditional_string': v8_utilities.conditional_string(method), | 106 'conditional_string': v8_utilities.conditional_string(method), |
87 'cpp_type': idl_type.cpp_type, | 107 'cpp_type': idl_type.cpp_type, |
88 'cpp_value': this_cpp_value, | 108 'cpp_value': this_cpp_value, |
89 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] | 109 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] |
90 'do_not_check_signature': not(is_static or | 110 'do_not_check_signature': not(is_static or |
91 v8_utilities.has_extended_attribute(method, | 111 v8_utilities.has_extended_attribute(method, |
92 ['DoNotCheckSecurity', 'DoNotCheckSignature', 'NotEnumerable', | 112 ['DoNotCheckSecurity', 'DoNotCheckSignature', 'NotEnumerable', |
93 'ReadOnly', 'RuntimeEnabled', 'Unforgeable'])), | 113 'ReadOnly', 'RuntimeEnabled', 'Unforgeable'])), |
94 'function_template': function_template(), | 114 'function_template': function_template(), |
95 'idl_type': idl_type.base_type, | 115 'idl_type': idl_type.base_type, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings] | 156 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings] |
137 } | 157 } |
138 | 158 |
139 | 159 |
140 def generate_argument(interface, method, argument, index): | 160 def generate_argument(interface, method, argument, index): |
141 extended_attributes = argument.extended_attributes | 161 extended_attributes = argument.extended_attributes |
142 idl_type = argument.idl_type | 162 idl_type = argument.idl_type |
143 this_cpp_value = cpp_value(interface, method, index) | 163 this_cpp_value = cpp_value(interface, method, index) |
144 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type | 164 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type |
145 | 165 |
166 if argument.is_variadic and not idl_type.is_wrapper_type: | |
haraken
2014/05/08 03:45:06
Would you elaborate on why we need this branch? I
Jens Widell
2014/05/08 06:22:06
I added it to get argument['cpp_type'] correct. Pr
Jens Widell
2014/05/08 16:53:05
So, the problem was variadic arguments, again. :-)
| |
167 element_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_a ttributes) | |
168 vector_type = v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc_ type) | |
169 cpp_type = v8_types.cpp_template_type(vector_type, element_cpp_type) | |
170 else: | |
171 cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribute s, | |
172 used_as_argument=not is_variadic_wrapp er_type, | |
173 used_in_cpp_sequence=is_variadic_wrapp er_type) | |
174 | |
146 return { | 175 return { |
147 'cpp_type': idl_type.cpp_type_args(used_in_cpp_sequence=is_variadic_wrap per_type), | 176 'cpp_type': cpp_type, |
148 'cpp_value': this_cpp_value, | 177 'cpp_value': this_cpp_value, |
149 'enum_validation_expression': idl_type.enum_validation_expression, | 178 'enum_validation_expression': idl_type.enum_validation_expression, |
150 'has_default': 'Default' in extended_attributes, | 179 'has_default': 'Default' in extended_attributes, |
151 'has_event_listener_argument': any( | 180 'has_event_listener_argument': any( |
152 argument_so_far for argument_so_far in method.arguments[:index] | 181 argument_so_far for argument_so_far in method.arguments[:index] |
153 if argument_so_far.idl_type.name == 'EventListener'), | 182 if argument_so_far.idl_type.name == 'EventListener'), |
154 'has_legacy_overload_string': # [LegacyOverloadString] | 183 'has_legacy_overload_string': # [LegacyOverloadString] |
155 'LegacyOverloadString' in extended_attributes, | 184 'LegacyOverloadString' in extended_attributes, |
156 'has_type_checking_interface': | 185 'has_type_checking_interface': |
157 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface' ) or | 186 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface' ) or |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 | 273 |
245 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else '' | 274 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else '' |
246 return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_w rappable=script_wrappable, release=release, for_main_world=for_main_world) | 275 return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_w rappable=script_wrappable, release=release, for_main_world=for_main_world) |
247 | 276 |
248 | 277 |
249 def v8_value_to_local_cpp_value(argument, index): | 278 def v8_value_to_local_cpp_value(argument, index): |
250 extended_attributes = argument.extended_attributes | 279 extended_attributes = argument.extended_attributes |
251 idl_type = argument.idl_type | 280 idl_type = argument.idl_type |
252 name = argument.name | 281 name = argument.name |
253 if argument.is_variadic: | 282 if argument.is_variadic: |
254 vector_type = v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc_ type) | 283 return 'TONATIVE_VOID_NO_DECL({name}, toNativeArguments<{cpp_type}>(info , {index}))'.format( |
255 return 'TONATIVE_VOID({vector_type}<{cpp_type}>, {name}, toNativeArgumen ts<{cpp_type}>(info, {index}))'.format( | 284 cpp_type=idl_type.cpp_type, name=name, |
256 vector_type=vector_type, cpp_type=idl_type.cpp_type, name=name, | |
257 index=index) | 285 index=index) |
258 # [Default=NullString] | 286 # [Default=NullString] |
259 if (argument.is_optional and idl_type.name == 'String' and | 287 if (argument.is_optional and idl_type.name == 'String' and |
260 extended_attributes.get('Default') == 'NullString'): | 288 extended_attributes.get('Default') == 'NullString'): |
261 v8_value = 'argumentOrNull(info, %s)' % index | 289 v8_value = 'argumentOrNull(info, %s)' % index |
262 else: | 290 else: |
263 v8_value = 'info[%s]' % index | 291 v8_value = 'info[%s]' % index |
264 return idl_type.v8_value_to_local_cpp_value(extended_attributes, v8_value, | 292 return idl_type.v8_value_to_local_cpp_value(extended_attributes, v8_value, |
265 name, index=index) | 293 name, index=index, declare_varia ble=False) |
266 | 294 |
267 | 295 |
268 ################################################################################ | 296 ################################################################################ |
269 # Auxiliary functions | 297 # Auxiliary functions |
270 ################################################################################ | 298 ################################################################################ |
271 | 299 |
272 # [NotEnumerable] | 300 # [NotEnumerable] |
273 def property_attributes(method): | 301 def property_attributes(method): |
274 extended_attributes = method.extended_attributes | 302 extended_attributes = method.extended_attributes |
275 property_attributes_list = [] | 303 property_attributes_list = [] |
276 if 'NotEnumerable' in extended_attributes: | 304 if 'NotEnumerable' in extended_attributes: |
277 property_attributes_list.append('v8::DontEnum') | 305 property_attributes_list.append('v8::DontEnum') |
278 if 'ReadOnly' in extended_attributes: | 306 if 'ReadOnly' in extended_attributes: |
279 property_attributes_list.append('v8::ReadOnly') | 307 property_attributes_list.append('v8::ReadOnly') |
280 if property_attributes_list: | 308 if property_attributes_list: |
281 property_attributes_list.insert(0, 'v8::DontDelete') | 309 property_attributes_list.insert(0, 'v8::DontDelete') |
282 return property_attributes_list | 310 return property_attributes_list |
283 | 311 |
284 | 312 |
285 def union_arguments(idl_type): | 313 def union_arguments(idl_type): |
286 """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for u nion types, for use in setting return value""" | 314 """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for u nion types, for use in setting return value""" |
287 return [arg | 315 return [arg |
288 for i in range(len(idl_type.member_types)) | 316 for i in range(len(idl_type.member_types)) |
289 for arg in ['result%sEnabled' % i, 'result%s' % i]] | 317 for arg in ['result%sEnabled' % i, 'result%s' % i]] |
290 | 318 |
291 IdlType.union_arguments = property(lambda self: None) | 319 IdlType.union_arguments = property(lambda self: None) |
292 IdlUnionType.union_arguments = property(union_arguments) | 320 IdlUnionType.union_arguments = property(union_arguments) |
OLD | NEW |