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 '/* 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 idl_type.is_dictionary or idl_type.is_union_type: | |
609 return 'TONATIVE_VOID_EXCEPTIONSTATE_ARGINTERNAL(%s, exceptionState)' % cpp_value | |
610 | |
611 if idl_type.is_string_type or idl_type.v8_conversion_needs_exception_state: | 608 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 | 609 # Types that need error handling and use one of a group of (C++) macros |
613 # to take care of this. | 610 # to take care of this. |
614 | 611 |
615 args = [variable_name, cpp_value] | 612 arguments = [] |
616 | |
617 if idl_type.v8_conversion_needs_exception_state: | |
618 macro = 'TONATIVE_DEFAULT_EXCEPTIONSTATE' if used_in_private_script else 'TONATIVE_VOID_EXCEPTIONSTATE' | |
619 elif return_promise or needs_exception_state_for_string: | |
620 macro = 'TOSTRING_VOID_EXCEPTIONSTATE' | |
621 else: | |
622 macro = 'TOSTRING_DEFAULT' if used_in_private_script else 'TOSTRING_ VOID' | |
623 | |
624 if macro.endswith('_EXCEPTIONSTATE'): | |
625 args.append('exceptionState') | |
626 | |
627 if used_in_private_script: | |
628 args.append('false') | |
629 | |
630 suffix = '' | |
631 | |
632 if return_promise: | |
633 suffix += '_PROMISE' | |
634 args.append('info') | |
635 if macro.endswith('_EXCEPTIONSTATE'): | |
636 args.append('ScriptState::current(%s)' % isolate) | |
637 | 613 |
638 if declare_variable: | 614 if declare_variable: |
639 args.insert(0, this_cpp_type) | 615 macro = 'TONATIVE_DECLARE' |
616 arguments.extend([this_cpp_type, variable_name]) | |
640 else: | 617 else: |
641 suffix += '_INTERNAL' | 618 macro = 'TONATIVE_CONVERT' |
642 | 619 |
643 return '%s(%s)' % (macro + suffix, ', '.join(args)) | 620 if idl_type.is_dictionary or idl_type.is_union_type: |
621 arguments.append(cpp_value) | |
622 if not use_exception_state: | |
bashi
2015/02/23 23:44:06
When could |use_exception_state| be False for dict
Jens Widell
2015/02/24 07:31:43
(Sorry about the poor documentation.)
Here, 'idl_
| |
623 bailout_return_value = 'exceptionState.throwException()' | |
624 elif idl_type.v8_conversion_needs_exception_state: | |
625 if use_exception_state: | |
626 helper = 'convertAndCheck' | |
627 else: | |
628 helper = 'convertAndThrow' | |
629 arguments.append('%s(%s = %s, exceptionState)' % (helper, variable_n ame, cpp_value)) | |
630 else: # idl_type.is_string_type | |
631 if use_exception_state: | |
632 arguments.append('(%s = %s).prepare(exceptionState)' % (variable _name, v8_value)) | |
633 else: | |
634 arguments.append('(%s = %s).prepare()' % (variable_name, v8_valu e)) | |
635 | |
636 if bailout_return_value: | |
637 arguments.append('return ' + bailout_return_value) | |
638 else: | |
639 arguments.append('return') | |
640 | |
641 return '%s(%s)' % (macro, ', '.join(arguments)) | |
644 | 642 |
645 # Types that don't need error handling, and simply assign a value to the | 643 # Types that don't need error handling, and simply assign a value to the |
646 # local variable. | 644 # local variable. |
647 | 645 |
648 if not idl_type.v8_conversion_is_trivial: | 646 if not idl_type.v8_conversion_is_trivial: |
649 raise Exception('unclassified V8 -> C++ conversion for IDL type: %s' % i dl_type.name) | 647 raise Exception('unclassified V8 -> C++ conversion for IDL type: %s' % i dl_type.name) |
650 | 648 |
651 assignment = '%s = %s' % (variable_name, cpp_value) | 649 assignment = '%s = %s' % (variable_name, cpp_value) |
652 if declare_variable: | 650 if declare_variable: |
653 return '%s %s' % (this_cpp_type, assignment) | 651 return '%s %s' % (this_cpp_type, assignment) |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
966 number_of_nullable_member_types_union) | 964 number_of_nullable_member_types_union) |
967 | 965 |
968 | 966 |
969 def includes_nullable_type_union(idl_type): | 967 def includes_nullable_type_union(idl_type): |
970 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type | 968 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type |
971 return idl_type.number_of_nullable_member_types == 1 | 969 return idl_type.number_of_nullable_member_types == 1 |
972 | 970 |
973 IdlTypeBase.includes_nullable_type = False | 971 IdlTypeBase.includes_nullable_type = False |
974 IdlNullableType.includes_nullable_type = True | 972 IdlNullableType.includes_nullable_type = True |
975 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) | 973 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) |
OLD | NEW |