| 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 # [ImplementedAs] | 216 # [ImplementedAs] |
| 217 # This handles [ImplementedAs] on interface types, not [ImplementedAs] in the | 217 # This handles [ImplementedAs] on interface types, not [ImplementedAs] in the |
| 218 # interface being generated. e.g., given: | 218 # interface being generated. e.g., given: |
| 219 # Foo.idl: interface Foo {attribute Bar bar}; | 219 # Foo.idl: interface Foo {attribute Bar bar}; |
| 220 # Bar.idl: [ImplementedAs=Zork] interface Bar {}; | 220 # Bar.idl: [ImplementedAs=Zork] interface Bar {}; |
| 221 # when generating bindings for Foo, the [ImplementedAs] on Bar is needed. | 221 # when generating bindings for Foo, the [ImplementedAs] on Bar is needed. |
| 222 # This data is external to Foo.idl, and hence computed as global information in | 222 # This data is external to Foo.idl, and hence computed as global information in |
| 223 # compute_interfaces_info.py to avoid having to parse IDLs of all used interface
s. | 223 # compute_interfaces_info.py to avoid having to parse IDLs of all used interface
s. |
| 224 IdlType.implemented_as_interfaces = {} | 224 IdlType.implemented_as_interfaces = {} |
| 225 | 225 |
| 226 |
| 226 def implemented_as(idl_type): | 227 def implemented_as(idl_type): |
| 227 base_idl_type = idl_type.base_type | 228 base_idl_type = idl_type.base_type |
| 228 if base_idl_type in IdlType.implemented_as_interfaces: | 229 if base_idl_type in IdlType.implemented_as_interfaces: |
| 229 return IdlType.implemented_as_interfaces[base_idl_type] | 230 return IdlType.implemented_as_interfaces[base_idl_type] |
| 230 return base_idl_type | 231 return base_idl_type |
| 231 | 232 |
| 232 | 233 |
| 233 IdlType.implemented_as = property(implemented_as) | 234 IdlType.implemented_as = property(implemented_as) |
| 234 | 235 |
| 235 IdlType.set_implemented_as_interfaces = classmethod( | 236 IdlType.set_implemented_as_interfaces = classmethod( |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 expression_format = '(to{ref_ptr_type}NativeArray<{array_or_sequence_typ
e}, V8{array_or_sequence_type}>({v8_value}, {index}, info.GetIsolate()))' | 421 expression_format = '(to{ref_ptr_type}NativeArray<{array_or_sequence_typ
e}, V8{array_or_sequence_type}>({v8_value}, {index}, info.GetIsolate()))' |
| 421 add_includes_for_type(array_or_sequence_type) | 422 add_includes_for_type(array_or_sequence_type) |
| 422 else: | 423 else: |
| 423 ref_ptr_type = None | 424 ref_ptr_type = None |
| 424 this_cpp_type = array_or_sequence_type.cpp_type | 425 this_cpp_type = array_or_sequence_type.cpp_type |
| 425 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, info
.GetIsolate())' | 426 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, info
.GetIsolate())' |
| 426 expression = expression_format.format(array_or_sequence_type=array_or_sequen
ce_type.name, cpp_type=this_cpp_type, index=index, ref_ptr_type=ref_ptr_type, v8
_value=v8_value) | 427 expression = expression_format.format(array_or_sequence_type=array_or_sequen
ce_type.name, cpp_type=this_cpp_type, index=index, ref_ptr_type=ref_ptr_type, v8
_value=v8_value) |
| 427 return expression | 428 return expression |
| 428 | 429 |
| 429 | 430 |
| 430 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl
e_name, index=None): | 431 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl
e_name, index=None, async=False): |
| 431 """Returns an expression that converts a V8 value to a C++ value and stores
it as a local value.""" | 432 """Returns an expression that converts a V8 value to a C++ value and stores
it as a local value.""" |
| 432 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, used_as_argument=True) | 433 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, used_as_argument=True) |
| 433 | 434 |
| 434 idl_type = idl_type.preprocessed_type | 435 idl_type = idl_type.preprocessed_type |
| 435 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i
ndex) | 436 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i
ndex) |
| 436 args = [this_cpp_type, variable_name, cpp_value] | 437 args = [this_cpp_type, variable_name, cpp_value] |
| 437 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type
: | 438 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type
: |
| 438 macro = 'TOSTRING_VOID' | 439 macro = 'TOSTRING_VOID' |
| 439 elif idl_type.is_integer_type: | 440 elif idl_type.is_integer_type: |
| 440 macro = 'TONATIVE_VOID_EXCEPTIONSTATE' | 441 macro = 'TONATIVE_VOID_EXCEPTIONSTATE' |
| 441 args.append('exceptionState') | 442 args.append('exceptionState') |
| 442 else: | 443 else: |
| 443 macro = 'TONATIVE_VOID' | 444 macro = 'TONATIVE_VOID' |
| 444 | 445 |
| 446 if async: |
| 447 macro += '_ASYNC' |
| 448 args.append('info') |
| 449 |
| 445 return '%s(%s)' % (macro, ', '.join(args)) | 450 return '%s(%s)' % (macro, ', '.join(args)) |
| 446 | 451 |
| 452 |
| 447 IdlType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value | 453 IdlType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value |
| 448 IdlUnionType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value | 454 IdlUnionType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value |
| 449 | 455 |
| 450 | 456 |
| 451 ################################################################################ | 457 ################################################################################ |
| 452 # C++ -> V8 | 458 # C++ -> V8 |
| 453 ################################################################################ | 459 ################################################################################ |
| 454 | 460 |
| 455 def preprocess_idl_type(idl_type): | 461 def preprocess_idl_type(idl_type): |
| 456 if idl_type.is_enum: | 462 if idl_type.is_enum: |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea
tion_context='', extended_attributes=None): | 639 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea
tion_context='', extended_attributes=None): |
| 634 """Returns an expression that converts a C++ value to a V8 value.""" | 640 """Returns an expression that converts a C++ value to a V8 value.""" |
| 635 # the isolate parameter is needed for callback interfaces | 641 # the isolate parameter is needed for callback interfaces |
| 636 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext
ended_attributes) | 642 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext
ended_attributes) |
| 637 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) | 643 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) |
| 638 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] | 644 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] |
| 639 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat
ion_context=creation_context) | 645 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat
ion_context=creation_context) |
| 640 return statement | 646 return statement |
| 641 | 647 |
| 642 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value | 648 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value |
| OLD | NEW |