Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: Source/bindings/scripts/v8_types.py

Issue 946973005: IDL: Drop value conversion (V8 -> C++) macros from generated code (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: drop throw_expression, re-add set_expression Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 void expression executed unconditionally.
613 set_expression = None
614 # Optional expression that returns true if the conversion fails.
615 check_expression = None
616 # Optional expression used as the return value when returning. Only
617 # meaningful if 'check_expression' is not None.
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 use_exception_state:
624 check_expression = 'exceptionState.hadException()'
625 else:
626 check_expression = 'exceptionState.throwIfNeeded()'
616 627
617 if idl_type.v8_conversion_needs_exception_state: 628 if idl_type.is_dictionary or idl_type.is_union_type:
618 macro = 'TONATIVE_DEFAULT_EXCEPTIONSTATE' if used_in_private_script else 'TONATIVE_VOID_EXCEPTIONSTATE' 629 set_expression = cpp_value
619 elif return_promise or needs_exception_state_for_string:
620 macro = 'TOSTRING_VOID_EXCEPTIONSTATE'
621 else: 630 else:
622 macro = 'TOSTRING_DEFAULT' if used_in_private_script else 'TOSTRING_ VOID' 631 assign_expression = cpp_value
623 632 # Note: 'not idl_type.v8_conversion_needs_exception_state' implies
624 if macro.endswith('_EXCEPTIONSTATE'): 633 # 'idl_type.is_string_type', but there are types for which both are
625 args.append('exceptionState') 634 # true (ByteString and USVString), so using idl_type.is_string_type
626 635 # as the condition here would be wrong.
627 if used_in_private_script: 636 if not idl_type.v8_conversion_needs_exception_state:
628 args.append('false') 637 if use_exception_state:
629 638 check_expression = '!%s.prepare(exceptionState)' % variable_ name
630 suffix = '' 639 else:
631 640 check_expression = '!%s.prepare()' % variable_name
632 if return_promise: 641 elif not idl_type.v8_conversion_is_trivial:
633 suffix += '_PROMISE' 642 raise Exception('unclassified V8 -> C++ conversion for IDL type: %s' % i dl_type.name)
634 args.append('info') 643 else:
635 if macro.endswith('_EXCEPTIONSTATE'): 644 assign_expression = cpp_value
636 args.append('ScriptState::current(%s)' % isolate)
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 645
haraken 2015/02/24 17:28:13 Although your CL is an improvement, the above exce
645 # Types that don't need error handling, and simply assign a value to the 646 # Types that don't need error handling, and simply assign a value to the
646 # local variable. 647 # local variable.
647 648
648 if not idl_type.v8_conversion_is_trivial: 649 return {
649 raise Exception('unclassified V8 -> C++ conversion for IDL type: %s' % i dl_type.name) 650 'assign_expression': assign_expression,
650 651 'check_expression': check_expression,
651 assignment = '%s = %s' % (variable_name, cpp_value) 652 'cpp_type': this_cpp_type,
652 if declare_variable: 653 'cpp_name': variable_name,
653 return '%s %s' % (this_cpp_type, assignment) 654 'declare_variable': declare_variable,
654 return assignment 655 'return_expression': bailout_return_value,
656 'set_expression': set_expression,
657 }
655 658
656 659
657 IdlTypeBase.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value 660 IdlTypeBase.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value
658 661
659 662
660 def use_output_parameter_for_result(idl_type): 663 def use_output_parameter_for_result(idl_type):
661 """True when methods/getters which return the given idl_type should 664 """True when methods/getters which return the given idl_type should
662 take the output argument. 665 take the output argument.
663 """ 666 """
664 return idl_type.is_dictionary or idl_type.is_union_type 667 return idl_type.is_dictionary or idl_type.is_union_type
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 number_of_nullable_member_types_union) 969 number_of_nullable_member_types_union)
967 970
968 971
969 def includes_nullable_type_union(idl_type): 972 def includes_nullable_type_union(idl_type):
970 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type 973 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type
971 return idl_type.number_of_nullable_member_types == 1 974 return idl_type.number_of_nullable_member_types == 1
972 975
973 IdlTypeBase.includes_nullable_type = False 976 IdlTypeBase.includes_nullable_type = False
974 IdlNullableType.includes_nullable_type = True 977 IdlNullableType.includes_nullable_type = True
975 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) 978 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698