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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 add_includes_for_type(native_array_element_type) | 587 add_includes_for_type(native_array_element_type) |
588 else: | 588 else: |
589 ref_ptr_type = None | 589 ref_ptr_type = None |
590 this_cpp_type = native_array_element_type.cpp_type | 590 this_cpp_type = native_array_element_type.cpp_type |
591 expression_format = 'toImplArray<{cpp_type}>({v8_value}, {index}, {isola
te}, exceptionState)' | 591 expression_format = 'toImplArray<{cpp_type}>({v8_value}, {index}, {isola
te}, exceptionState)' |
592 expression = expression_format.format(native_array_element_type=native_array
_element_type.name, cpp_type=this_cpp_type, index=index, ref_ptr_type=ref_ptr_ty
pe, v8_value=v8_value, isolate=isolate) | 592 expression = expression_format.format(native_array_element_type=native_array
_element_type.name, cpp_type=this_cpp_type, index=index, ref_ptr_type=ref_ptr_ty
pe, v8_value=v8_value, isolate=isolate) |
593 return expression | 593 return expression |
594 | 594 |
595 | 595 |
596 # FIXME: this function should be refactored, as this takes too many flags. | 596 # FIXME: this function should be refactored, as this takes too many flags. |
597 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl
e_name=None, index=None, declare_variable=True, isolate='info.GetIsolate()', use
d_in_private_script=False, return_promise=False, needs_exception_state_for_strin
g=False, restricted_float=False): | 597 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl
e_name=None, index=None, declare_variable=True, isolate='info.GetIsolate()', use
d_in_private_script=False, return_promise=False, needs_exception_state_for_strin
g=False, restricted_float=False, no_throw=False): |
598 """Returns an expression that converts a V8 value to a C++ value and stores
it as a local value.""" | 598 """Returns an expression that converts a V8 value to a C++ value and stores
it as a local value.""" |
599 | 599 |
600 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, raw_type=True) | 600 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, raw_type=True) |
601 idl_type = idl_type.preprocessed_type | 601 idl_type = idl_type.preprocessed_type |
602 | 602 |
603 if idl_type.base_type in ('void', 'object', 'EventHandler', 'EventListener')
: | 603 if idl_type.base_type in ('void', 'object', 'EventHandler', 'EventListener')
: |
604 return '/* no V8 -> C++ conversion for IDL type: %s */' % idl_type.name | 604 return '/* no V8 -> C++ conversion for IDL type: %s */' % idl_type.name |
605 | 605 |
606 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, v
ariable_name, index, isolate, restricted_float=restricted_float) | 606 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, v
ariable_name, index, isolate, restricted_float=restricted_float) |
607 | 607 |
| 608 if no_throw: |
| 609 no_throw = '_NOTHROW' |
| 610 else: |
| 611 no_throw = '' |
| 612 |
608 if idl_type.is_dictionary or idl_type.is_union_type: | 613 if idl_type.is_dictionary or idl_type.is_union_type: |
609 return 'TONATIVE_VOID_EXCEPTIONSTATE_ARGINTERNAL(%s, exceptionState)' %
cpp_value | 614 return 'TONATIVE_VOID_EXCEPTIONSTATE_ARGINTERNAL%s(%s, exceptionState)'
% (no_throw, cpp_value) |
610 | 615 |
611 if idl_type.is_string_type or idl_type.v8_conversion_needs_exception_state: | 616 if idl_type.is_string_type or idl_type.v8_conversion_needs_exception_state: |
612 # Types that need error handling and use one of a group of (C++) macros | 617 # Types that need error handling and use one of a group of (C++) macros |
613 # to take care of this. | 618 # to take care of this. |
614 | 619 |
615 args = [variable_name, cpp_value] | 620 args = [variable_name, cpp_value] |
616 | 621 |
617 if idl_type.v8_conversion_needs_exception_state: | 622 if idl_type.v8_conversion_needs_exception_state: |
618 macro = 'TONATIVE_DEFAULT_EXCEPTIONSTATE' if used_in_private_script
else 'TONATIVE_VOID_EXCEPTIONSTATE' | 623 macro = 'TONATIVE_DEFAULT_EXCEPTIONSTATE' if used_in_private_script
else 'TONATIVE_VOID_EXCEPTIONSTATE' |
619 elif return_promise or needs_exception_state_for_string: | 624 elif return_promise or needs_exception_state_for_string: |
(...skipping 13 matching lines...) Expand all Loading... |
633 suffix += '_PROMISE' | 638 suffix += '_PROMISE' |
634 args.append('info') | 639 args.append('info') |
635 if macro.endswith('_EXCEPTIONSTATE'): | 640 if macro.endswith('_EXCEPTIONSTATE'): |
636 args.append('ScriptState::current(%s)' % isolate) | 641 args.append('ScriptState::current(%s)' % isolate) |
637 | 642 |
638 if declare_variable: | 643 if declare_variable: |
639 args.insert(0, this_cpp_type) | 644 args.insert(0, this_cpp_type) |
640 else: | 645 else: |
641 suffix += '_INTERNAL' | 646 suffix += '_INTERNAL' |
642 | 647 |
| 648 if macro != 'TOSTRING_VOID_EXCEPTIONSTATE': |
| 649 suffix += no_throw |
| 650 |
643 return '%s(%s)' % (macro + suffix, ', '.join(args)) | 651 return '%s(%s)' % (macro + suffix, ', '.join(args)) |
644 | 652 |
645 # Types that don't need error handling, and simply assign a value to the | 653 # Types that don't need error handling, and simply assign a value to the |
646 # local variable. | 654 # local variable. |
647 | 655 |
648 if not idl_type.v8_conversion_is_trivial: | 656 if not idl_type.v8_conversion_is_trivial: |
649 raise Exception('unclassified V8 -> C++ conversion for IDL type: %s' % i
dl_type.name) | 657 raise Exception('unclassified V8 -> C++ conversion for IDL type: %s' % i
dl_type.name) |
650 | 658 |
651 assignment = '%s = %s' % (variable_name, cpp_value) | 659 assignment = '%s = %s' % (variable_name, cpp_value) |
652 if declare_variable: | 660 if declare_variable: |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 number_of_nullable_member_types_union) | 974 number_of_nullable_member_types_union) |
967 | 975 |
968 | 976 |
969 def includes_nullable_type_union(idl_type): | 977 def includes_nullable_type_union(idl_type): |
970 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type | 978 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type |
971 return idl_type.number_of_nullable_member_types == 1 | 979 return idl_type.number_of_nullable_member_types == 1 |
972 | 980 |
973 IdlTypeBase.includes_nullable_type = False | 981 IdlTypeBase.includes_nullable_type = False |
974 IdlNullableType.includes_nullable_type = True | 982 IdlNullableType.includes_nullable_type = True |
975 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) | 983 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) |
OLD | NEW |