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): | |
44 return not (argument.get("is_callback_interface") or | |
Nils Barth (inactive)
2014/05/07 03:02:19
Single quotes.
Also, can't these just be usual key
Jens Widell
2014/05/07 10:34:46
Neither 'is_callback_interface' nor 'is_variadic_w
Nils Barth (inactive)
2014/05/08 00:55:13
Got it -- I thought it might be something like tha
| |
45 argument.get("idl_type") == "SerializedScriptValue" or | |
46 argument.get("is_variadic_wrapper_type")) | |
47 | |
48 | |
43 def generate_method(interface, method): | 49 def generate_method(interface, method): |
44 arguments = method.arguments | 50 arguments = method.arguments |
45 extended_attributes = method.extended_attributes | 51 extended_attributes = method.extended_attributes |
46 idl_type = method.idl_type | 52 idl_type = method.idl_type |
47 is_static = method.is_static | 53 is_static = method.is_static |
48 name = method.name | 54 name = method.name |
49 | 55 |
50 idl_type.add_includes_for_type() | 56 idl_type.add_includes_for_type() |
51 this_cpp_value = cpp_value(interface, method, len(arguments)) | 57 this_cpp_value = cpp_value(interface, method, len(arguments)) |
52 | 58 |
(...skipping 19 matching lines...) Expand all Loading... | |
72 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') | 78 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') |
73 | 79 |
74 has_event_listener_argument = any( | 80 has_event_listener_argument = any( |
75 argument for argument in arguments | 81 argument for argument in arguments |
76 if argument.idl_type.name == 'EventListener') | 82 if argument.idl_type.name == 'EventListener') |
77 is_check_security_for_frame = ( | 83 is_check_security_for_frame = ( |
78 'CheckSecurity' in interface.extended_attributes and | 84 'CheckSecurity' in interface.extended_attributes and |
79 'DoNotCheckSecurity' not in extended_attributes) | 85 'DoNotCheckSecurity' not in extended_attributes) |
80 is_raises_exception = 'RaisesException' in extended_attributes | 86 is_raises_exception = 'RaisesException' in extended_attributes |
81 | 87 |
88 generated_arguments = [generate_argument(interface, method, argument, index) | |
89 for index, argument in enumerate(arguments)] | |
90 | |
82 return { | 91 return { |
83 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging] | 92 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging] |
84 'arguments': [generate_argument(interface, method, argument, index) | 93 'arguments': generated_arguments, |
85 for index, argument in enumerate(arguments)], | 94 'arguments_need_try_catch': any( |
Nils Barth (inactive)
2014/05/07 03:02:19
Fix linebreaks, wrapping as follows:
'argu
| |
95 argument_needs_try_catch(argument) for argument in generated_argumen ts), | |
86 'conditional_string': v8_utilities.conditional_string(method), | 96 'conditional_string': v8_utilities.conditional_string(method), |
87 'cpp_type': idl_type.cpp_type, | 97 'cpp_type': idl_type.cpp_type, |
88 'cpp_value': this_cpp_value, | 98 'cpp_value': this_cpp_value, |
89 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] | 99 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] |
90 'do_not_check_signature': not(is_static or | 100 'do_not_check_signature': not(is_static or |
91 v8_utilities.has_extended_attribute(method, | 101 v8_utilities.has_extended_attribute(method, |
92 ['DoNotCheckSecurity', 'DoNotCheckSignature', 'NotEnumerable', | 102 ['DoNotCheckSecurity', 'DoNotCheckSignature', 'NotEnumerable', |
93 'ReadOnly', 'RuntimeEnabled', 'Unforgeable'])), | 103 'ReadOnly', 'RuntimeEnabled', 'Unforgeable'])), |
94 'function_template': function_template(), | 104 'function_template': function_template(), |
95 'idl_type': idl_type.base_type, | 105 '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] | 146 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings] |
137 } | 147 } |
138 | 148 |
139 | 149 |
140 def generate_argument(interface, method, argument, index): | 150 def generate_argument(interface, method, argument, index): |
141 extended_attributes = argument.extended_attributes | 151 extended_attributes = argument.extended_attributes |
142 idl_type = argument.idl_type | 152 idl_type = argument.idl_type |
143 this_cpp_value = cpp_value(interface, method, index) | 153 this_cpp_value = cpp_value(interface, method, index) |
144 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type | 154 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type |
145 | 155 |
156 if argument.is_variadic and not is_variadic_wrapper_type: | |
Nils Barth (inactive)
2014/05/07 03:02:19
Slightly more direct:
if argument.is_variadic and
| |
157 cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribute s, | |
Nils Barth (inactive)
2014/05/07 03:02:19
Prefer single assignment:
element_cpp_type = ...
| |
158 used_in_cpp_sequence=is_variadic_wrapp er_type) | |
Nils Barth (inactive)
2014/05/07 03:02:19
You can drop used_in_cpp_sequence, as it's always
| |
159 vector_type = v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc_ type) | |
160 cpp_type = v8_types.cpp_template_type(vector_type, cpp_type) | |
161 else: | |
162 cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribute s, | |
Nils Barth (inactive)
2014/05/07 03:02:19
Do we need to pass extended_attributes here?
(It'
Jens Widell
2014/05/07 10:34:46
Not passing it makes run-bindings-test fail with t
Nils Barth (inactive)
2014/05/08 00:55:13
Got it, looks like there is a use in constructors;
| |
163 used_as_argument=not is_variadic_wrapp er_type, | |
164 used_in_cpp_sequence=is_variadic_wrapp er_type) | |
165 | |
146 return { | 166 return { |
147 'cpp_type': idl_type.cpp_type_args(used_in_cpp_sequence=is_variadic_wrap per_type), | 167 'cpp_type': cpp_type, |
148 'cpp_value': this_cpp_value, | 168 'cpp_value': this_cpp_value, |
149 'enum_validation_expression': idl_type.enum_validation_expression, | 169 'enum_validation_expression': idl_type.enum_validation_expression, |
150 'has_default': 'Default' in extended_attributes, | 170 'has_default': 'Default' in extended_attributes, |
151 'has_event_listener_argument': any( | 171 'has_event_listener_argument': any( |
152 argument_so_far for argument_so_far in method.arguments[:index] | 172 argument_so_far for argument_so_far in method.arguments[:index] |
153 if argument_so_far.idl_type.name == 'EventListener'), | 173 if argument_so_far.idl_type.name == 'EventListener'), |
154 'has_legacy_overload_string': # [LegacyOverloadString] | 174 'has_legacy_overload_string': # [LegacyOverloadString] |
155 'LegacyOverloadString' in extended_attributes, | 175 'LegacyOverloadString' in extended_attributes, |
156 'has_type_checking_interface': | 176 'has_type_checking_interface': |
157 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface' ) or | 177 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface' ) or |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 | 263 |
244 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else '' | 264 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else '' |
245 return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_w rappable=script_wrappable, release=release, for_main_world=for_main_world) | 265 return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_w rappable=script_wrappable, release=release, for_main_world=for_main_world) |
246 | 266 |
247 | 267 |
248 def v8_value_to_local_cpp_value(argument, index): | 268 def v8_value_to_local_cpp_value(argument, index): |
249 extended_attributes = argument.extended_attributes | 269 extended_attributes = argument.extended_attributes |
250 idl_type = argument.idl_type | 270 idl_type = argument.idl_type |
251 name = argument.name | 271 name = argument.name |
252 if argument.is_variadic: | 272 if argument.is_variadic: |
253 vector_type = v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc_ type) | 273 return 'TONATIVE_VOID_NO_DECL({name}, toNativeArguments<{cpp_type}>(info , {index}))'.format( |
254 return 'TONATIVE_VOID({vector_type}<{cpp_type}>, {name}, toNativeArgumen ts<{cpp_type}>(info, {index}))'.format( | 274 cpp_type=idl_type.cpp_type, name=name, |
255 vector_type=vector_type, cpp_type=idl_type.cpp_type, name=name, | |
256 index=index) | 275 index=index) |
257 # [Default=NullString] | 276 # [Default=NullString] |
258 if (argument.is_optional and idl_type.name == 'String' and | 277 if (argument.is_optional and idl_type.name == 'String' and |
259 extended_attributes.get('Default') == 'NullString'): | 278 extended_attributes.get('Default') == 'NullString'): |
260 v8_value = 'argumentOrNull(info, %s)' % index | 279 v8_value = 'argumentOrNull(info, %s)' % index |
261 else: | 280 else: |
262 v8_value = 'info[%s]' % index | 281 v8_value = 'info[%s]' % index |
263 return idl_type.v8_value_to_local_cpp_value(extended_attributes, v8_value, | 282 return idl_type.v8_value_to_local_cpp_value(extended_attributes, v8_value, |
264 name, index=index) | 283 name, index=index, declare_varia ble=False) |
265 | 284 |
266 | 285 |
267 ################################################################################ | 286 ################################################################################ |
268 # Auxiliary functions | 287 # Auxiliary functions |
269 ################################################################################ | 288 ################################################################################ |
270 | 289 |
271 # [NotEnumerable] | 290 # [NotEnumerable] |
272 def property_attributes(method): | 291 def property_attributes(method): |
273 extended_attributes = method.extended_attributes | 292 extended_attributes = method.extended_attributes |
274 property_attributes_list = [] | 293 property_attributes_list = [] |
275 if 'NotEnumerable' in extended_attributes: | 294 if 'NotEnumerable' in extended_attributes: |
276 property_attributes_list.append('v8::DontEnum') | 295 property_attributes_list.append('v8::DontEnum') |
277 if 'ReadOnly' in extended_attributes: | 296 if 'ReadOnly' in extended_attributes: |
278 property_attributes_list.append('v8::ReadOnly') | 297 property_attributes_list.append('v8::ReadOnly') |
279 if property_attributes_list: | 298 if property_attributes_list: |
280 property_attributes_list.insert(0, 'v8::DontDelete') | 299 property_attributes_list.insert(0, 'v8::DontDelete') |
281 return property_attributes_list | 300 return property_attributes_list |
282 | 301 |
283 | 302 |
284 def union_arguments(idl_type): | 303 def union_arguments(idl_type): |
285 """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for u nion types, for use in setting return value""" | 304 """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for u nion types, for use in setting return value""" |
286 return [arg | 305 return [arg |
287 for i in range(len(idl_type.member_types)) | 306 for i in range(len(idl_type.member_types)) |
288 for arg in ['result%sEnabled' % i, 'result%s' % i]] | 307 for arg in ['result%sEnabled' % i, 'result%s' % i]] |
289 | 308 |
290 IdlType.union_arguments = property(lambda self: None) | 309 IdlType.union_arguments = property(lambda self: None) |
291 IdlUnionType.union_arguments = property(union_arguments) | 310 IdlUnionType.union_arguments = property(union_arguments) |
OLD | NEW |