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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 | 474 |
475 | 475 |
476 def v8_conversion_needs_exception_state(idl_type): | 476 def v8_conversion_needs_exception_state(idl_type): |
477 return (idl_type.is_numeric_type or | 477 return (idl_type.is_numeric_type or |
478 idl_type.is_dictionary or | 478 idl_type.is_dictionary or |
479 idl_type.name in ('ByteString', 'ScalarValueString')) | 479 idl_type.name in ('ByteString', 'ScalarValueString')) |
480 | 480 |
481 IdlType.v8_conversion_needs_exception_state = property(v8_conversion_needs_excep
tion_state) | 481 IdlType.v8_conversion_needs_exception_state = property(v8_conversion_needs_excep
tion_state) |
482 | 482 |
483 | 483 |
| 484 def v8_conversion_is_trivial(idl_type): |
| 485 # The conversion is a simple expression that returns the converted value and |
| 486 # cannot raise an exception. |
| 487 return (idl_type.base_type == 'boolean' or |
| 488 idl_type.is_wrapper_type) |
| 489 |
| 490 IdlType.v8_conversion_is_trivial = property(v8_conversion_is_trivial) |
| 491 |
| 492 |
484 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, index, isolat
e): | 493 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, index, isolat
e): |
485 if idl_type.name == 'void': | 494 if idl_type.name == 'void': |
486 return '' | 495 return '' |
487 | 496 |
488 # Array or sequence types | 497 # Array or sequence types |
489 native_array_element_type = idl_type.native_array_element_type | 498 native_array_element_type = idl_type.native_array_element_type |
490 if native_array_element_type: | 499 if native_array_element_type: |
491 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type
, v8_value, index) | 500 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type
, v8_value, index) |
492 | 501 |
493 # Simple types | 502 # Simple types |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, raw_type=True) | 559 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, raw_type=True) |
551 | 560 |
552 idl_type = idl_type.preprocessed_type | 561 idl_type = idl_type.preprocessed_type |
553 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i
ndex, isolate) | 562 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i
ndex, isolate) |
554 args = [variable_name, cpp_value] | 563 args = [variable_name, cpp_value] |
555 if idl_type.base_type == 'DOMString': | 564 if idl_type.base_type == 'DOMString': |
556 macro = 'TOSTRING_DEFAULT' if used_in_private_script else 'TOSTRING_VOID
' | 565 macro = 'TOSTRING_DEFAULT' if used_in_private_script else 'TOSTRING_VOID
' |
557 elif idl_type.v8_conversion_needs_exception_state: | 566 elif idl_type.v8_conversion_needs_exception_state: |
558 macro = 'TONATIVE_DEFAULT_EXCEPTIONSTATE' if used_in_private_script else
'TONATIVE_VOID_EXCEPTIONSTATE' | 567 macro = 'TONATIVE_DEFAULT_EXCEPTIONSTATE' if used_in_private_script else
'TONATIVE_VOID_EXCEPTIONSTATE' |
559 args.append('exceptionState') | 568 args.append('exceptionState') |
| 569 elif idl_type.v8_conversion_is_trivial: |
| 570 assignment = '%s = %s' % (variable_name, cpp_value) |
| 571 if declare_variable: |
| 572 return '%s %s' % (this_cpp_type, assignment) |
| 573 return assignment |
560 else: | 574 else: |
561 macro = 'TONATIVE_DEFAULT' if used_in_private_script else 'TONATIVE_VOID
' | 575 macro = 'TONATIVE_DEFAULT' if used_in_private_script else 'TONATIVE_VOID
' |
562 | 576 |
563 if used_in_private_script: | 577 if used_in_private_script: |
564 args.append('false') | 578 args.append('false') |
565 | 579 |
566 # Macros come in several variants, to minimize expensive creation of | 580 # Macros come in several variants, to minimize expensive creation of |
567 # v8::TryCatch. | 581 # v8::TryCatch. |
568 suffix = '' | 582 suffix = '' |
569 | 583 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 | 837 |
824 | 838 |
825 def is_explicit_nullable(idl_type): | 839 def is_explicit_nullable(idl_type): |
826 # Nullable type that isn't implicit nullable (see above.) For such types, | 840 # Nullable type that isn't implicit nullable (see above.) For such types, |
827 # we use Nullable<T> or similar explicit ways to represent a null value. | 841 # we use Nullable<T> or similar explicit ways to represent a null value. |
828 return idl_type.is_nullable and not idl_type.is_implicit_nullable | 842 return idl_type.is_nullable and not idl_type.is_implicit_nullable |
829 | 843 |
830 IdlTypeBase.is_implicit_nullable = property(is_implicit_nullable) | 844 IdlTypeBase.is_implicit_nullable = property(is_implicit_nullable) |
831 IdlUnionType.is_implicit_nullable = False | 845 IdlUnionType.is_implicit_nullable = False |
832 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable) | 846 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable) |
OLD | NEW |