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, index=None, declare_variable=True, isolate='info.GetIsolate()', bailout_ return_value=None, use_exception_state=False, restricted_float=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 { |
605 'error_message': 'no V8 -> C++ conversion for IDL type: %s' % idl_ty pe.name | |
606 } | |
605 | 607 |
606 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, v ariable_name, index, isolate, restricted_float=restricted_float) | 608 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, v ariable_name, index, isolate, restricted_float=restricted_float) |
607 | 609 |
608 if idl_type.is_dictionary or idl_type.is_union_type: | 610 # Optional expression that returns a value to be assigned to the local varia ble. |
609 return 'TONATIVE_VOID_EXCEPTIONSTATE_ARGINTERNAL(%s, exceptionState)' % cpp_value | 611 assign_expression = None |
612 # Optional expression that returns true if the conversion fails. | |
613 check_expression = None | |
614 # Next two: only meaningful if 'check_expression' is not None. | |
615 # Optional expression executed before returning. | |
616 throw_expression = None | |
617 # Optional expression used as the return value when returning. | |
618 return_expression = bailout_return_value | |
610 | 619 |
611 if idl_type.is_string_type or idl_type.v8_conversion_needs_exception_state: | 620 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 | 621 # Types for which conversion can fail and that need error handling. |
613 # to take care of this. | |
614 | 622 |
615 args = [variable_name, cpp_value] | 623 if idl_type.is_dictionary or idl_type.is_union_type: |
616 | 624 check_expression = '!' + cpp_value |
617 if idl_type.v8_conversion_needs_exception_state: | 625 if not use_exception_state: |
618 macro = 'TONATIVE_DEFAULT_EXCEPTIONSTATE' if used_in_private_script else 'TONATIVE_VOID_EXCEPTIONSTATE' | 626 throw_expression = 'exceptionState.throwIfNeeded()' |
619 elif return_promise or needs_exception_state_for_string: | |
620 macro = 'TOSTRING_VOID_EXCEPTIONSTATE' | |
621 else: | 627 else: |
622 macro = 'TOSTRING_DEFAULT' if used_in_private_script else 'TOSTRING_ VOID' | 628 assign_expression = cpp_value |
623 | 629 if idl_type.v8_conversion_needs_exception_state: |
624 if macro.endswith('_EXCEPTIONSTATE'): | 630 if use_exception_state: |
625 args.append('exceptionState') | 631 check_expression = 'exceptionState.hadException()' |
626 | 632 else: |
627 if used_in_private_script: | 633 check_expression = 'exceptionState.throwIfNeeded()' |
haraken
2015/02/24 15:59:38
It seems a bit confusing that we use exceptionStat
Jens Widell
2015/02/24 16:15:58
Yeah, "use_exception_state" is not a variable name
| |
628 args.append('false') | 634 else: # idl_type.is_string_type |
629 | 635 if use_exception_state: |
630 suffix = '' | 636 check_expression = '!%s.prepare(exceptionState)' % variable_ name |
631 | 637 else: |
632 if return_promise: | 638 check_expression = '!%s.prepare()' % variable_name |
633 suffix += '_PROMISE' | 639 elif not idl_type.v8_conversion_is_trivial: |
634 args.append('info') | 640 raise Exception('unclassified V8 -> C++ conversion for IDL type: %s' % i dl_type.name) |
635 if macro.endswith('_EXCEPTIONSTATE'): | 641 else: |
636 args.append('ScriptState::current(%s)' % isolate) | 642 assign_expression = cpp_value |
637 | |
638 if declare_variable: | |
639 args.insert(0, this_cpp_type) | |
640 else: | |
641 suffix += '_INTERNAL' | |
642 | |
643 return '%s(%s)' % (macro + suffix, ', '.join(args)) | |
644 | 643 |
645 # Types that don't need error handling, and simply assign a value to the | 644 # Types that don't need error handling, and simply assign a value to the |
646 # local variable. | 645 # local variable. |
647 | 646 |
648 if not idl_type.v8_conversion_is_trivial: | 647 return { |
649 raise Exception('unclassified V8 -> C++ conversion for IDL type: %s' % i dl_type.name) | 648 'assign_expression': assign_expression, |
650 | 649 'check_expression': check_expression, |
651 assignment = '%s = %s' % (variable_name, cpp_value) | 650 'cpp_type': this_cpp_type, |
652 if declare_variable: | 651 'cpp_name': variable_name, |
653 return '%s %s' % (this_cpp_type, assignment) | 652 'declare_variable': declare_variable, |
654 return assignment | 653 'return_expression': bailout_return_value, |
654 'throw_expression': throw_expression, | |
655 } | |
655 | 656 |
656 | 657 |
657 IdlTypeBase.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value | 658 IdlTypeBase.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value |
658 | 659 |
659 | 660 |
660 def use_output_parameter_for_result(idl_type): | 661 def use_output_parameter_for_result(idl_type): |
661 """True when methods/getters which return the given idl_type should | 662 """True when methods/getters which return the given idl_type should |
662 take the output argument. | 663 take the output argument. |
663 """ | 664 """ |
664 return idl_type.is_dictionary or idl_type.is_union_type | 665 return idl_type.is_dictionary or idl_type.is_union_type |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
966 number_of_nullable_member_types_union) | 967 number_of_nullable_member_types_union) |
967 | 968 |
968 | 969 |
969 def includes_nullable_type_union(idl_type): | 970 def includes_nullable_type_union(idl_type): |
970 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type | 971 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type |
971 return idl_type.number_of_nullable_member_types == 1 | 972 return idl_type.number_of_nullable_member_types == 1 |
972 | 973 |
973 IdlTypeBase.includes_nullable_type = False | 974 IdlTypeBase.includes_nullable_type = False |
974 IdlNullableType.includes_nullable_type = True | 975 IdlNullableType.includes_nullable_type = True |
975 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) | 976 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) |
OLD | NEW |