| 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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 | 418 |
| 419 | 419 |
| 420 def includes_for_union_type(idl_type, extended_attributes=None): | 420 def includes_for_union_type(idl_type, extended_attributes=None): |
| 421 return set.union(*[member_type.includes_for_type(extended_attributes) | 421 return set.union(*[member_type.includes_for_type(extended_attributes) |
| 422 for member_type in idl_type.member_types]) | 422 for member_type in idl_type.member_types]) |
| 423 | 423 |
| 424 IdlUnionType.includes_for_type = includes_for_union_type | 424 IdlUnionType.includes_for_type = includes_for_union_type |
| 425 | 425 |
| 426 | 426 |
| 427 def includes_for_array_or_sequence_type(idl_type, extended_attributes=None): | 427 def includes_for_array_or_sequence_type(idl_type, extended_attributes=None): |
| 428 return idl_type.element_type.includes_for_type(extended_attributes) | 428 return set.union(set(['bindings/core/v8/IDLTypes.h', |
| 429 'bindings/core/v8/NativeValueTraitsImpl.h']), |
| 430 idl_type.element_type.includes_for_type(extended_attributes
)) |
| 429 | 431 |
| 430 IdlArrayOrSequenceType.includes_for_type = includes_for_array_or_sequence_type | 432 IdlArrayOrSequenceType.includes_for_type = includes_for_array_or_sequence_type |
| 431 | 433 |
| 432 | 434 |
| 433 def includes_for_record_type(idl_type, extended_attributes=None): | 435 def includes_for_record_type(idl_type, extended_attributes=None): |
| 434 return set.union(idl_type.key_type.includes_for_type(extended_attributes), | 436 return set.union(idl_type.key_type.includes_for_type(extended_attributes), |
| 435 idl_type.value_type.includes_for_type(extended_attributes)) | 437 idl_type.value_type.includes_for_type(extended_attributes)) |
| 436 | 438 |
| 437 IdlRecordType.includes_for_type = includes_for_record_type | 439 IdlRecordType.includes_for_type = includes_for_record_type |
| 438 | 440 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 native_value_traits_type_name(idl_type.val
ue_type)) | 573 native_value_traits_type_name(idl_type.val
ue_type)) |
| 572 elif idl_type.is_basic_type or idl_type.name == 'Promise': | 574 elif idl_type.is_basic_type or idl_type.name == 'Promise': |
| 573 name = 'IDL%s' % idl_type.name | 575 name = 'IDL%s' % idl_type.name |
| 574 elif idl_type.implemented_as is not None: | 576 elif idl_type.implemented_as is not None: |
| 575 name = idl_type.implemented_as | 577 name = idl_type.implemented_as |
| 576 else: | 578 else: |
| 577 name = idl_type.name | 579 name = idl_type.name |
| 578 return name | 580 return name |
| 579 | 581 |
| 580 | 582 |
| 581 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name
, index, isolate): | 583 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name
, isolate): |
| 582 if idl_type.name == 'void': | 584 if idl_type.name == 'void': |
| 583 return '' | 585 return '' |
| 584 | 586 |
| 585 # Array or sequence types | |
| 586 native_array_element_type = idl_type.native_array_element_type | |
| 587 if native_array_element_type: | |
| 588 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type
, v8_value, index, isolate) | |
| 589 | |
| 590 # Simple types | 587 # Simple types |
| 591 idl_type = idl_type.preprocessed_type | 588 idl_type = idl_type.preprocessed_type |
| 592 base_idl_type = idl_type.as_union_type.name if idl_type.is_union_type else i
dl_type.base_type | 589 base_idl_type = idl_type.as_union_type.name if idl_type.is_union_type else i
dl_type.base_type |
| 593 | 590 |
| 594 if 'FlexibleArrayBufferView' in extended_attributes: | 591 if 'FlexibleArrayBufferView' in extended_attributes: |
| 595 if base_idl_type not in ARRAY_BUFFER_VIEW_AND_TYPED_ARRAY_TYPES: | 592 if base_idl_type not in ARRAY_BUFFER_VIEW_AND_TYPED_ARRAY_TYPES: |
| 596 raise ValueError("Unrecognized base type for extended attribute 'Fle
xibleArrayBufferView': %s" % (idl_type.base_type)) | 593 raise ValueError("Unrecognized base type for extended attribute 'Fle
xibleArrayBufferView': %s" % (idl_type.base_type)) |
| 597 base_idl_type = 'FlexibleArrayBufferView' | 594 base_idl_type = 'FlexibleArrayBufferView' |
| 598 | 595 |
| 599 if idl_type.is_integer_type: | 596 if idl_type.is_integer_type: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 621 nullable = 'UnionTypeConversionMode::kNullable' if idl_type.includes_nul
lable_type \ | 618 nullable = 'UnionTypeConversionMode::kNullable' if idl_type.includes_nul
lable_type \ |
| 622 else 'UnionTypeConversionMode::kNotNullable' | 619 else 'UnionTypeConversionMode::kNotNullable' |
| 623 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va
riable_name}, %s, exceptionState)' % nullable | 620 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va
riable_name}, %s, exceptionState)' % nullable |
| 624 elif idl_type.use_output_parameter_for_result: | 621 elif idl_type.use_output_parameter_for_result: |
| 625 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va
riable_name}, exceptionState)' | 622 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va
riable_name}, exceptionState)' |
| 626 elif idl_type.is_callback_function: | 623 elif idl_type.is_callback_function: |
| 627 cpp_expression_format = ( | 624 cpp_expression_format = ( |
| 628 '{idl_type}::Create(ScriptState::Current({isolate}), {v8_value})') | 625 '{idl_type}::Create(ScriptState::Current({isolate}), {v8_value})') |
| 629 elif idl_type.v8_conversion_needs_exception_state: | 626 elif idl_type.v8_conversion_needs_exception_state: |
| 630 # Effectively, this if branch means everything with v8_conversion_needs_
exception_state == True | 627 # Effectively, this if branch means everything with v8_conversion_needs_
exception_state == True |
| 631 # except for unions, sequences and dictionary interfaces. | 628 # except for unions and dictionary interfaces. |
| 632 base_idl_type = native_value_traits_type_name(idl_type) | 629 base_idl_type = native_value_traits_type_name(idl_type) |
| 633 cpp_expression_format = ( | 630 cpp_expression_format = ( |
| 634 'NativeValueTraits<{idl_type}>::NativeValue({isolate}, {arguments})'
) | 631 'NativeValueTraits<{idl_type}>::NativeValue({isolate}, {arguments})'
) |
| 635 else: | 632 else: |
| 636 cpp_expression_format = ( | 633 cpp_expression_format = ( |
| 637 'V8{idl_type}::toImplWithTypeCheck({isolate}, {v8_value})') | 634 'V8{idl_type}::toImplWithTypeCheck({isolate}, {v8_value})') |
| 638 | 635 |
| 639 return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_t
ype, v8_value=v8_value, variable_name=variable_name, isolate=isolate) | 636 return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_t
ype, v8_value=v8_value, variable_name=variable_name, isolate=isolate) |
| 640 | 637 |
| 641 | 638 |
| 642 def v8_value_to_cpp_value_array_or_sequence(native_array_element_type, v8_value,
index, isolate='info.GetIsolate()'): | |
| 643 # Index is None for setters, index (starting at 0) for method arguments, | |
| 644 # and is used to provide a human-readable exception message | |
| 645 if index is None: | |
| 646 index = 0 # special case, meaning "setter" | |
| 647 else: | |
| 648 index += 1 # human-readable index | |
| 649 if (native_array_element_type.is_interface_type and | |
| 650 native_array_element_type.name != 'Dictionary'): | |
| 651 this_cpp_type = None | |
| 652 expression_format = 'ToMemberNativeArray<{native_array_element_type}>({v
8_value}, {index}, {isolate}, exceptionState)' | |
| 653 else: | |
| 654 this_cpp_type = native_array_element_type.cpp_type | |
| 655 if native_array_element_type.is_dictionary or native_array_element_type.
is_union_type: | |
| 656 vector_type = 'HeapVector' | |
| 657 else: | |
| 658 vector_type = 'Vector' | |
| 659 if native_array_element_type.is_primitive_type: | |
| 660 value_type = native_value_traits_type_name(native_array_element_type
) | |
| 661 expression_format = ('ToImplArray<%s<{cpp_type}>, %s>' | |
| 662 '({v8_value}, {index}, {isolate}, ' | |
| 663 'exceptionState)' % (vector_type, value_type)) | |
| 664 else: | |
| 665 expression_format = ('ToImplArray<%s<{cpp_type}>>' | |
| 666 '({v8_value}, {index}, {isolate}, ' | |
| 667 'exceptionState)' % vector_type) | |
| 668 | |
| 669 expression = expression_format.format(native_array_element_type=native_array
_element_type.name, cpp_type=this_cpp_type, | |
| 670 index=index, v8_value=v8_value, isolat
e=isolate) | |
| 671 return expression | |
| 672 | |
| 673 | |
| 674 # FIXME: this function should be refactored, as this takes too many flags. | 639 # FIXME: this function should be refactored, as this takes too many flags. |
| 675 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl
e_name, index=None, declare_variable=True, | 640 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl
e_name, declare_variable=True, |
| 676 isolate='info.GetIsolate()', bailout_return_valu
e=None, use_exception_state=False): | 641 isolate='info.GetIsolate()', bailout_return_valu
e=None, use_exception_state=False): |
| 677 """Returns an expression that converts a V8 value to a C++ value and stores
it as a local value.""" | 642 """Returns an expression that converts a V8 value to a C++ value and stores
it as a local value.""" |
| 678 | 643 |
| 679 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, raw_type=True) | 644 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, raw_type=True) |
| 680 idl_type = idl_type.preprocessed_type | 645 idl_type = idl_type.preprocessed_type |
| 681 | 646 |
| 682 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, v
ariable_name, index, isolate) | 647 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, v
ariable_name, isolate) |
| 683 | 648 |
| 684 # Optional expression that returns a value to be assigned to the local varia
ble. | 649 # Optional expression that returns a value to be assigned to the local varia
ble. |
| 685 assign_expression = None | 650 assign_expression = None |
| 686 # Optional void expression executed unconditionally. | 651 # Optional void expression executed unconditionally. |
| 687 set_expression = None | 652 set_expression = None |
| 688 # Optional expression that returns true if the conversion fails. | 653 # Optional expression that returns true if the conversion fails. |
| 689 check_expression = None | 654 check_expression = None |
| 690 # Optional expression used as the return value when returning. Only | 655 # Optional expression used as the return value when returning. Only |
| 691 # meaningful if 'check_expression' is not None. | 656 # meaningful if 'check_expression' is not None. |
| 692 return_expression = bailout_return_value | 657 return_expression = bailout_return_value |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable) | 1050 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable) |
| 1086 | 1051 |
| 1087 | 1052 |
| 1088 def includes_nullable_type_union(idl_type): | 1053 def includes_nullable_type_union(idl_type): |
| 1089 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type | 1054 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type |
| 1090 return idl_type.number_of_nullable_member_types == 1 | 1055 return idl_type.number_of_nullable_member_types == 1 |
| 1091 | 1056 |
| 1092 IdlTypeBase.includes_nullable_type = False | 1057 IdlTypeBase.includes_nullable_type = False |
| 1093 IdlNullableType.includes_nullable_type = True | 1058 IdlNullableType.includes_nullable_type = True |
| 1094 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) | 1059 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) |
| OLD | NEW |