Chromium Code Reviews| 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 extended_attributes = argument.extended_attributes | 161 extended_attributes = argument.extended_attributes |
| 162 idl_type = argument.idl_type | 162 idl_type = argument.idl_type |
| 163 this_cpp_value = cpp_value(interface, method, index) | 163 this_cpp_value = cpp_value(interface, method, index) |
| 164 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 |
| 165 | 165 |
| 166 return { | 166 return { |
| 167 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut es, | 167 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut es, |
| 168 used_as_argument=True, | 168 used_as_argument=True, |
| 169 used_as_variadic_argument=argument.is _variadic), | 169 used_as_variadic_argument=argument.is _variadic), |
| 170 'cpp_value': this_cpp_value, | 170 'cpp_value': this_cpp_value, |
| 171 'default_value': default_value_to_cpp_value(argument), | |
|
Nils Barth (inactive)
2014/06/04 05:22:24
Using a property this is more cleanly:
argument.de
Jens Widell
2014/06/04 06:12:18
I'm using the argument's type to generate differen
Nils Barth (inactive)
2014/06/04 06:33:35
Ow, good point. (>.<)
2 possible approaches:
1. M
Jens Widell
2014/06/04 09:49:16
I ended up tentatively going for a third option:
| |
| 171 'enum_validation_expression': idl_type.enum_validation_expression, | 172 'enum_validation_expression': idl_type.enum_validation_expression, |
| 172 'has_default': 'Default' in extended_attributes, | 173 'has_default': 'Default' in extended_attributes, |
| 173 'has_event_listener_argument': any( | 174 'has_event_listener_argument': any( |
| 174 argument_so_far for argument_so_far in method.arguments[:index] | 175 argument_so_far for argument_so_far in method.arguments[:index] |
| 175 if argument_so_far.idl_type.name == 'EventListener'), | 176 if argument_so_far.idl_type.name == 'EventListener'), |
| 176 'has_type_checking_interface': | 177 'has_type_checking_interface': |
| 177 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface' ) or | 178 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface' ) or |
| 178 has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and | 179 has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and |
| 179 idl_type.is_wrapper_type, | 180 idl_type.is_wrapper_type, |
| 180 'has_type_checking_unrestricted': | 181 'has_type_checking_unrestricted': |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 | 279 |
| 279 return '%s(%s)' % (macro, ', '.join(macro_args)) | 280 return '%s(%s)' % (macro, ', '.join(macro_args)) |
| 280 | 281 |
| 281 | 282 |
| 282 def v8_value_to_local_cpp_value(argument, index): | 283 def v8_value_to_local_cpp_value(argument, index): |
| 283 extended_attributes = argument.extended_attributes | 284 extended_attributes = argument.extended_attributes |
| 284 idl_type = argument.idl_type | 285 idl_type = argument.idl_type |
| 285 name = argument.name | 286 name = argument.name |
| 286 if argument.is_variadic: | 287 if argument.is_variadic: |
| 287 return v8_value_to_local_cpp_variadic_value(argument, index) | 288 return v8_value_to_local_cpp_variadic_value(argument, index) |
| 288 # [Default=NullString] | 289 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]' % index, |
| 289 if (argument.is_optional and idl_type.name == 'String' and | |
| 290 extended_attributes.get('Default') == 'NullString'): | |
| 291 v8_value = 'argumentOrNull(info, %s)' % index | |
|
Nils Barth (inactive)
2014/06/04 06:33:36
You can get rid of argumentOrNull from V8Binding.h
| |
| 292 else: | |
| 293 v8_value = 'info[%s]' % index | |
| 294 return idl_type.v8_value_to_local_cpp_value(extended_attributes, v8_value, | |
| 295 name, index=index, declare_varia ble=False) | 290 name, index=index, declare_varia ble=False) |
| 296 | 291 |
| 297 | 292 |
| 293 def default_value_to_cpp_value(argument): | |
|
Nils Barth (inactive)
2014/06/04 05:22:24
Could you make this a property?
(For slickness and
| |
| 294 default_value = argument.default_value | |
|
Nils Barth (inactive)
2014/06/04 05:22:24
Might be clearer to also have:
value_type = defaul
| |
| 295 if default_value is None: | |
|
Nils Barth (inactive)
2014/06/04 05:22:24
if not default_value:
...per:
Use the "implicit" f
| |
| 296 return None | |
| 297 if default_value.value_type == 'DOMString': | |
| 298 if '"' in default_value.value or '\\' in default_value.value: | |
| 299 raise ValueError('Unsupported string value: %r' % default_value.valu e) | |
| 300 return 'String("%s")' % default_value.value | |
| 301 if default_value.value_type == 'integer': | |
| 302 return '%d' % default_value.value | |
|
Nils Barth (inactive)
2014/06/04 05:22:24
Could you put all this "string representation" log
| |
| 303 if default_value.value_type == 'float': | |
| 304 return '%g' % default_value.value | |
| 305 if default_value.value_type == 'boolean': | |
| 306 return 'true' if default_value.value else 'false' | |
| 307 if default_value.value_type == 'NULL': | |
| 308 if argument.idl_type.name in ('String', 'StringOrNull'): | |
| 309 return 'String()' | |
| 310 return 'nullptr' | |
| 311 | |
|
Nils Barth (inactive)
2014/06/04 05:22:24
...do you mean to implicitly return None here?
(..
Jens Widell
2014/06/04 06:12:18
Not really, no. I am handling all value types that
| |
| 312 | |
| 298 ################################################################################ | 313 ################################################################################ |
| 299 # Auxiliary functions | 314 # Auxiliary functions |
| 300 ################################################################################ | 315 ################################################################################ |
| 301 | 316 |
| 302 # [NotEnumerable] | 317 # [NotEnumerable] |
| 303 def property_attributes(method): | 318 def property_attributes(method): |
| 304 extended_attributes = method.extended_attributes | 319 extended_attributes = method.extended_attributes |
| 305 property_attributes_list = [] | 320 property_attributes_list = [] |
| 306 if 'NotEnumerable' in extended_attributes: | 321 if 'NotEnumerable' in extended_attributes: |
| 307 property_attributes_list.append('v8::DontEnum') | 322 property_attributes_list.append('v8::DontEnum') |
| 308 if 'ReadOnly' in extended_attributes: | 323 if 'ReadOnly' in extended_attributes: |
| 309 property_attributes_list.append('v8::ReadOnly') | 324 property_attributes_list.append('v8::ReadOnly') |
| 310 if property_attributes_list: | 325 if property_attributes_list: |
| 311 property_attributes_list.insert(0, 'v8::DontDelete') | 326 property_attributes_list.insert(0, 'v8::DontDelete') |
| 312 return property_attributes_list | 327 return property_attributes_list |
| 313 | 328 |
| 314 | 329 |
| 315 def union_arguments(idl_type): | 330 def union_arguments(idl_type): |
| 316 """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for u nion types, for use in setting return value""" | 331 """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for u nion types, for use in setting return value""" |
| 317 return [arg | 332 return [arg |
| 318 for i in range(len(idl_type.member_types)) | 333 for i in range(len(idl_type.member_types)) |
| 319 for arg in ['result%sEnabled' % i, 'result%s' % i]] | 334 for arg in ['result%sEnabled' % i, 'result%s' % i]] |
| 320 | 335 |
| 321 IdlType.union_arguments = property(lambda self: None) | 336 IdlType.union_arguments = property(lambda self: None) |
| 322 IdlUnionType.union_arguments = property(union_arguments) | 337 IdlUnionType.union_arguments = property(union_arguments) |
| OLD | NEW |