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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 ])) | 73 ])) |
74 | 74 |
75 IdlType.is_array_buffer_or_view = property( | 75 IdlType.is_array_buffer_or_view = property( |
76 lambda self: self.base_type in ARRAY_BUFFER_AND_VIEW_TYPES) | 76 lambda self: self.base_type in ARRAY_BUFFER_AND_VIEW_TYPES) |
77 | 77 |
78 IdlType.is_typed_array = property( | 78 IdlType.is_typed_array = property( |
79 lambda self: self.base_type in TYPED_ARRAY_TYPES) | 79 lambda self: self.base_type in TYPED_ARRAY_TYPES) |
80 | 80 |
81 IdlType.is_wrapper_type = property( | 81 IdlType.is_wrapper_type = property( |
82 lambda self: (self.is_interface_type and | 82 lambda self: (self.is_interface_type and |
| 83 not self.is_callback_interface and |
83 self.base_type not in NON_WRAPPER_TYPES)) | 84 self.base_type not in NON_WRAPPER_TYPES)) |
84 | 85 |
85 | 86 |
86 ################################################################################ | 87 ################################################################################ |
87 # C++ types | 88 # C++ types |
88 ################################################################################ | 89 ################################################################################ |
89 | 90 |
90 CPP_TYPE_SAME_AS_IDL_TYPE = set([ | 91 CPP_TYPE_SAME_AS_IDL_TYPE = set([ |
91 'double', | 92 'double', |
92 'float', | 93 'float', |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 return expression | 604 return expression |
604 | 605 |
605 | 606 |
606 # FIXME: this function should be refactored, as this takes too many flags. | 607 # FIXME: this function should be refactored, as this takes too many flags. |
607 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl
e_name, index=None, declare_variable=True, isolate='info.GetIsolate()', bailout_
return_value=None, use_exception_state=False, restricted_float=False): | 608 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl
e_name, index=None, declare_variable=True, isolate='info.GetIsolate()', bailout_
return_value=None, use_exception_state=False, restricted_float=False): |
608 """Returns an expression that converts a V8 value to a C++ value and stores
it as a local value.""" | 609 """Returns an expression that converts a V8 value to a C++ value and stores
it as a local value.""" |
609 | 610 |
610 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, raw_type=True) | 611 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, raw_type=True) |
611 idl_type = idl_type.preprocessed_type | 612 idl_type = idl_type.preprocessed_type |
612 | 613 |
613 if idl_type.base_type in ('void', 'object', 'EventHandler', 'EventListener')
: | |
614 return { | |
615 'error_message': 'no V8 -> C++ conversion for IDL type: %s' % idl_ty
pe.name | |
616 } | |
617 | |
618 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, v
ariable_name, index, isolate, restricted_float=restricted_float) | 614 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, v
ariable_name, index, isolate, restricted_float=restricted_float) |
619 | 615 |
620 # Optional expression that returns a value to be assigned to the local varia
ble. | 616 # Optional expression that returns a value to be assigned to the local varia
ble. |
621 assign_expression = None | 617 assign_expression = None |
622 # Optional void expression executed unconditionally. | 618 # Optional void expression executed unconditionally. |
623 set_expression = None | 619 set_expression = None |
624 # Optional expression that returns true if the conversion fails. | 620 # Optional expression that returns true if the conversion fails. |
625 check_expression = None | 621 check_expression = None |
626 # Optional expression used as the return value when returning. Only | 622 # Optional expression used as the return value when returning. Only |
627 # meaningful if 'check_expression' is not None. | 623 # meaningful if 'check_expression' is not None. |
(...skipping 14 matching lines...) Expand all Loading... |
642 # Note: 'not idl_type.v8_conversion_needs_exception_state' implies | 638 # Note: 'not idl_type.v8_conversion_needs_exception_state' implies |
643 # 'idl_type.is_string_type', but there are types for which both are | 639 # 'idl_type.is_string_type', but there are types for which both are |
644 # true (ByteString and USVString), so using idl_type.is_string_type | 640 # true (ByteString and USVString), so using idl_type.is_string_type |
645 # as the condition here would be wrong. | 641 # as the condition here would be wrong. |
646 if not idl_type.v8_conversion_needs_exception_state: | 642 if not idl_type.v8_conversion_needs_exception_state: |
647 if use_exception_state: | 643 if use_exception_state: |
648 check_expression = '!%s.prepare(exceptionState)' % variable_
name | 644 check_expression = '!%s.prepare(exceptionState)' % variable_
name |
649 else: | 645 else: |
650 check_expression = '!%s.prepare()' % variable_name | 646 check_expression = '!%s.prepare()' % variable_name |
651 elif not idl_type.v8_conversion_is_trivial: | 647 elif not idl_type.v8_conversion_is_trivial: |
652 raise Exception('unclassified V8 -> C++ conversion for IDL type: %s' % i
dl_type.name) | 648 return { |
| 649 'error_message': 'no V8 -> C++ conversion for IDL type: %s' % idl_ty
pe.name |
| 650 } |
653 else: | 651 else: |
654 assign_expression = cpp_value | 652 assign_expression = cpp_value |
655 | 653 |
656 # Types that don't need error handling, and simply assign a value to the | 654 # Types that don't need error handling, and simply assign a value to the |
657 # local variable. | 655 # local variable. |
658 | 656 |
659 return { | 657 return { |
660 'assign_expression': assign_expression, | 658 'assign_expression': assign_expression, |
661 'check_expression': check_expression, | 659 'check_expression': check_expression, |
662 'cpp_type': this_cpp_type, | 660 'cpp_type': this_cpp_type, |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 number_of_nullable_member_types_union) | 977 number_of_nullable_member_types_union) |
980 | 978 |
981 | 979 |
982 def includes_nullable_type_union(idl_type): | 980 def includes_nullable_type_union(idl_type): |
983 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type | 981 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type |
984 return idl_type.number_of_nullable_member_types == 1 | 982 return idl_type.number_of_nullable_member_types == 1 |
985 | 983 |
986 IdlTypeBase.includes_nullable_type = False | 984 IdlTypeBase.includes_nullable_type = False |
987 IdlNullableType.includes_nullable_type = True | 985 IdlNullableType.includes_nullable_type = True |
988 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) | 986 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) |
OLD | NEW |