Chromium Code Reviews| 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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 # V8 -> C++ | 469 # V8 -> C++ |
| 470 ################################################################################ | 470 ################################################################################ |
| 471 | 471 |
| 472 V8_VALUE_TO_CPP_VALUE = { | 472 V8_VALUE_TO_CPP_VALUE = { |
| 473 # Basic | 473 # Basic |
| 474 'Date': 'toCoreDate({v8_value})', | 474 'Date': 'toCoreDate({v8_value})', |
| 475 'DOMString': '{v8_value}', | 475 'DOMString': '{v8_value}', |
| 476 'ByteString': 'toByteString({arguments})', | 476 'ByteString': 'toByteString({arguments})', |
| 477 'USVString': 'toUSVString({arguments})', | 477 'USVString': 'toUSVString({arguments})', |
| 478 'boolean': '{v8_value}->BooleanValue()', | 478 'boolean': '{v8_value}->BooleanValue()', |
| 479 'float': 'toFloat({arguments})', | 479 'float': 'toRestrictedFloat({arguments})', |
| 480 'unrestricted float': 'toFloat({arguments})', | 480 'unrestricted float': 'toFloat({arguments})', |
| 481 'double': 'toDouble({arguments})', | 481 'double': 'toRestrictedDouble({arguments})', |
| 482 'unrestricted double': 'toDouble({arguments})', | 482 'unrestricted double': 'toDouble({arguments})', |
| 483 'byte': 'toInt8({arguments})', | 483 'byte': 'toInt8({arguments})', |
| 484 'octet': 'toUInt8({arguments})', | 484 'octet': 'toUInt8({arguments})', |
| 485 'short': 'toInt16({arguments})', | 485 'short': 'toInt16({arguments})', |
| 486 'unsigned short': 'toUInt16({arguments})', | 486 'unsigned short': 'toUInt16({arguments})', |
| 487 'long': 'toInt32({arguments})', | 487 'long': 'toInt32({arguments})', |
| 488 'unsigned long': 'toUInt32({arguments})', | 488 'unsigned long': 'toUInt32({arguments})', |
| 489 'long long': 'toInt64({arguments})', | 489 'long long': 'toInt64({arguments})', |
| 490 'unsigned long long': 'toUInt64({arguments})', | 490 'unsigned long long': 'toUInt64({arguments})', |
| 491 # Interface types | 491 # Interface types |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 | 523 |
| 524 def v8_conversion_is_trivial(idl_type): | 524 def v8_conversion_is_trivial(idl_type): |
| 525 # The conversion is a simple expression that returns the converted value and | 525 # The conversion is a simple expression that returns the converted value and |
| 526 # cannot raise an exception. | 526 # cannot raise an exception. |
| 527 return (idl_type.base_type in TRIVIAL_CONVERSIONS or | 527 return (idl_type.base_type in TRIVIAL_CONVERSIONS or |
| 528 idl_type.is_wrapper_type) | 528 idl_type.is_wrapper_type) |
| 529 | 529 |
| 530 IdlType.v8_conversion_is_trivial = property(v8_conversion_is_trivial) | 530 IdlType.v8_conversion_is_trivial = property(v8_conversion_is_trivial) |
| 531 | 531 |
| 532 | 532 |
| 533 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name , index, isolate): | 533 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name , index, isolate, restricted_float=False): |
| 534 if idl_type.name == 'void': | 534 if idl_type.name == 'void': |
| 535 return '' | 535 return '' |
| 536 | 536 |
| 537 # Array or sequence types | 537 # Array or sequence types |
| 538 native_array_element_type = idl_type.native_array_element_type | 538 native_array_element_type = idl_type.native_array_element_type |
| 539 if native_array_element_type: | 539 if native_array_element_type: |
| 540 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index, isolate) | 540 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index, isolate) |
| 541 | 541 |
| 542 # Simple types | 542 # Simple types |
| 543 idl_type = idl_type.preprocessed_type | 543 idl_type = idl_type.preprocessed_type |
| 544 add_includes_for_type(idl_type) | 544 add_includes_for_type(idl_type) |
| 545 base_idl_type = idl_type.as_union_type.name if idl_type.is_union_type else i dl_type.base_type | 545 base_idl_type = idl_type.as_union_type.name if idl_type.is_union_type else i dl_type.base_type |
| 546 | 546 |
| 547 if 'EnforceRange' in extended_attributes: | 547 if 'EnforceRange' in extended_attributes: |
| 548 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState']) | 548 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState']) |
| 549 elif 'Clamp' in extended_attributes: | 549 elif 'Clamp' in extended_attributes: |
| 550 arguments = ', '.join([v8_value, 'Clamp', 'exceptionState']) | 550 arguments = ', '.join([v8_value, 'Clamp', 'exceptionState']) |
| 551 elif idl_type.v8_conversion_needs_exception_state: | 551 elif idl_type.v8_conversion_needs_exception_state: |
| 552 arguments = ', '.join([v8_value, 'exceptionState']) | 552 arguments = ', '.join([v8_value, 'exceptionState']) |
| 553 else: | 553 else: |
| 554 arguments = v8_value | 554 arguments = v8_value |
| 555 | 555 |
| 556 if base_idl_type in V8_VALUE_TO_CPP_VALUE: | 556 if base_idl_type in V8_VALUE_TO_CPP_VALUE: |
| 557 if base_idl_type in ('float', 'double') and not restricted_float: | |
|
Jens Widell
2015/01/21 13:35:10
This is king of backwards. The ultimate solution i
bashi
2015/01/22 02:11:14
I'm not suggesting to do in this CL, but I think i
haraken
2015/01/22 02:43:05
Yes, let's try to drop TypeChecking=Unrestricted :
| |
| 558 base_idl_type = 'unrestricted ' + base_idl_type | |
| 557 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] | 559 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] |
| 558 elif idl_type.is_array_buffer_or_view: | 560 elif idl_type.is_array_buffer_or_view: |
| 559 cpp_expression_format = ( | 561 cpp_expression_format = ( |
| 560 '{v8_value}->Is{idl_type}() ? ' | 562 '{v8_value}->Is{idl_type}() ? ' |
| 561 'V8{idl_type}::toImpl(v8::Local<v8::{idl_type}>::Cast({v8_value})) : 0') | 563 'V8{idl_type}::toImpl(v8::Local<v8::{idl_type}>::Cast({v8_value})) : 0') |
| 562 elif idl_type.use_output_parameter_for_result: | 564 elif idl_type.use_output_parameter_for_result: |
| 563 if idl_type.includes_nullable_type: | 565 if idl_type.includes_nullable_type: |
| 564 base_idl_type = idl_type.cpp_type + 'OrNull' | 566 base_idl_type = idl_type.cpp_type + 'OrNull' |
| 565 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va riable_name}, exceptionState)' | 567 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va riable_name}, exceptionState)' |
| 566 else: | 568 else: |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 585 add_includes_for_type(native_array_element_type) | 587 add_includes_for_type(native_array_element_type) |
| 586 else: | 588 else: |
| 587 ref_ptr_type = None | 589 ref_ptr_type = None |
| 588 this_cpp_type = native_array_element_type.cpp_type | 590 this_cpp_type = native_array_element_type.cpp_type |
| 589 expression_format = 'toImplArray<{cpp_type}>({v8_value}, {index}, {isola te}, exceptionState)' | 591 expression_format = 'toImplArray<{cpp_type}>({v8_value}, {index}, {isola te}, exceptionState)' |
| 590 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) |
| 591 return expression | 593 return expression |
| 592 | 594 |
| 593 | 595 |
| 594 # 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. |
| 595 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): | 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): |
| 596 """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.""" |
| 597 | 599 |
| 598 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) |
| 599 idl_type = idl_type.preprocessed_type | 601 idl_type = idl_type.preprocessed_type |
| 600 | 602 |
| 601 if idl_type.base_type in ('void', 'object', 'EventHandler', 'EventListener') : | 603 if idl_type.base_type in ('void', 'object', 'EventHandler', 'EventListener') : |
| 602 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 |
| 603 | 605 |
| 604 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, v ariable_name, index, isolate) | 606 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, v ariable_name, index, isolate, restricted_float=restricted_float) |
| 605 | 607 |
| 606 if idl_type.is_dictionary or idl_type.is_union_type: | 608 if idl_type.is_dictionary or idl_type.is_union_type: |
| 607 return 'TONATIVE_VOID_EXCEPTIONSTATE_ARGINTERNAL(%s, exceptionState)' % cpp_value | 609 return 'TONATIVE_VOID_EXCEPTIONSTATE_ARGINTERNAL(%s, exceptionState)' % cpp_value |
| 608 | 610 |
| 609 if idl_type.is_string_type or idl_type.v8_conversion_needs_exception_state: | 611 if idl_type.is_string_type or idl_type.v8_conversion_needs_exception_state: |
| 610 # Types that need error handling and use one of a group of (C++) macros | 612 # Types that need error handling and use one of a group of (C++) macros |
| 611 # to take care of this. | 613 # to take care of this. |
| 612 | 614 |
| 613 args = [variable_name, cpp_value] | 615 args = [variable_name, cpp_value] |
| 614 | 616 |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 945 number_of_nullable_member_types_union) | 947 number_of_nullable_member_types_union) |
| 946 | 948 |
| 947 | 949 |
| 948 def includes_nullable_type_union(idl_type): | 950 def includes_nullable_type_union(idl_type): |
| 949 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type | 951 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type |
| 950 return idl_type.number_of_nullable_member_types == 1 | 952 return idl_type.number_of_nullable_member_types == 1 |
| 951 | 953 |
| 952 IdlTypeBase.includes_nullable_type = False | 954 IdlTypeBase.includes_nullable_type = False |
| 953 IdlNullableType.includes_nullable_type = True | 955 IdlNullableType.includes_nullable_type = True |
| 954 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) | 956 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) |
| OLD | NEW |