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

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

Issue 808373002: IDL: Simplify [TypeChecking=Interface] code generation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years 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 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 522
523 def v8_conversion_is_trivial(idl_type): 523 def v8_conversion_is_trivial(idl_type):
524 # The conversion is a simple expression that returns the converted value and 524 # The conversion is a simple expression that returns the converted value and
525 # cannot raise an exception. 525 # cannot raise an exception.
526 return (idl_type.base_type in TRIVIAL_CONVERSIONS or 526 return (idl_type.base_type in TRIVIAL_CONVERSIONS or
527 idl_type.is_wrapper_type) 527 idl_type.is_wrapper_type)
528 528
529 IdlType.v8_conversion_is_trivial = property(v8_conversion_is_trivial) 529 IdlType.v8_conversion_is_trivial = property(v8_conversion_is_trivial)
530 530
531 531
532 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name , needs_type_check, index, isolate): 532 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name , index, isolate):
533 if idl_type.name == 'void': 533 if idl_type.name == 'void':
534 return '' 534 return ''
535 535
536 # Array or sequence types 536 # Array or sequence types
537 native_array_element_type = idl_type.native_array_element_type 537 native_array_element_type = idl_type.native_array_element_type
538 if native_array_element_type: 538 if native_array_element_type:
539 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index, isolate) 539 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index, isolate)
540 540
541 # Simple types 541 # Simple types
542 idl_type = idl_type.preprocessed_type 542 idl_type = idl_type.preprocessed_type
(...skipping 12 matching lines...) Expand all
555 if base_idl_type in V8_VALUE_TO_CPP_VALUE: 555 if base_idl_type in V8_VALUE_TO_CPP_VALUE:
556 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] 556 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type]
557 elif idl_type.is_array_buffer_or_view: 557 elif idl_type.is_array_buffer_or_view:
558 cpp_expression_format = ( 558 cpp_expression_format = (
559 '{v8_value}->Is{idl_type}() ? ' 559 '{v8_value}->Is{idl_type}() ? '
560 'V8{idl_type}::toImpl(v8::Handle<v8::{idl_type}>::Cast({v8_value})) : 0') 560 'V8{idl_type}::toImpl(v8::Handle<v8::{idl_type}>::Cast({v8_value})) : 0')
561 elif idl_type.use_output_parameter_for_result: 561 elif idl_type.use_output_parameter_for_result:
562 if idl_type.includes_nullable_type: 562 if idl_type.includes_nullable_type:
563 base_idl_type = idl_type.cpp_type + 'OrNull' 563 base_idl_type = idl_type.cpp_type + 'OrNull'
564 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va riable_name}, exceptionState)' 564 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va riable_name}, exceptionState)'
565 elif needs_type_check: 565 else:
566 cpp_expression_format = ( 566 cpp_expression_format = (
567 'V8{idl_type}::toImplWithTypeCheck({isolate}, {v8_value})') 567 'V8{idl_type}::toImplWithTypeCheck({isolate}, {v8_value})')
568 else:
569 cpp_expression_format = (
570 'V8{idl_type}::toImpl(v8::Handle<v8::Object>::Cast({v8_value}))')
571 568
572 return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_t ype, v8_value=v8_value, variable_name=variable_name, isolate=isolate) 569 return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_t ype, v8_value=v8_value, variable_name=variable_name, isolate=isolate)
573 570
574 571
575 def v8_value_to_cpp_value_array_or_sequence(native_array_element_type, v8_value, index, isolate='info.GetIsolate()'): 572 def v8_value_to_cpp_value_array_or_sequence(native_array_element_type, v8_value, index, isolate='info.GetIsolate()'):
576 # Index is None for setters, index (starting at 0) for method arguments, 573 # Index is None for setters, index (starting at 0) for method arguments,
577 # and is used to provide a human-readable exception message 574 # and is used to provide a human-readable exception message
578 if index is None: 575 if index is None:
579 index = 0 # special case, meaning "setter" 576 index = 0 # special case, meaning "setter"
580 else: 577 else:
581 index += 1 # human-readable index 578 index += 1 # human-readable index
582 if (native_array_element_type.is_interface_type and 579 if (native_array_element_type.is_interface_type and
583 native_array_element_type.name != 'Dictionary'): 580 native_array_element_type.name != 'Dictionary'):
584 this_cpp_type = None 581 this_cpp_type = None
585 ref_ptr_type = cpp_ptr_type('RefPtr', 'Member', native_array_element_typ e.gc_type) 582 ref_ptr_type = cpp_ptr_type('RefPtr', 'Member', native_array_element_typ e.gc_type)
586 expression_format = '(to{ref_ptr_type}NativeArray<{native_array_element_ type}, V8{native_array_element_type}>({v8_value}, {index}, {isolate}, exceptionS tate))' 583 expression_format = '(to{ref_ptr_type}NativeArray<{native_array_element_ type}, V8{native_array_element_type}>({v8_value}, {index}, {isolate}, exceptionS tate))'
587 add_includes_for_type(native_array_element_type) 584 add_includes_for_type(native_array_element_type)
588 else: 585 else:
589 ref_ptr_type = None 586 ref_ptr_type = None
590 this_cpp_type = native_array_element_type.cpp_type 587 this_cpp_type = native_array_element_type.cpp_type
591 expression_format = 'toImplArray<{cpp_type}>({v8_value}, {index}, {isola te}, exceptionState)' 588 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) 589 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 590 return expression
594 591
595 592
596 # FIXME: this function should be refactored, as this takes too many flags. 593 # 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, needs_type_check=True, index=None, declare_variable=True, isolate=' info.GetIsolate()', used_in_private_script=False, return_promise=False, needs_ex ception_state_for_string=False): 594 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):
598 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value.""" 595 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value."""
599 596
600 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, raw_type=True) 597 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, raw_type=True)
601 idl_type = idl_type.preprocessed_type 598 idl_type = idl_type.preprocessed_type
602 599
603 if idl_type.base_type in ('void', 'object', 'EventHandler', 'EventListener') : 600 if idl_type.base_type in ('void', 'object', 'EventHandler', 'EventListener') :
604 return '/* no V8 -> C++ conversion for IDL type: %s */' % idl_type.name 601 return '/* no V8 -> C++ conversion for IDL type: %s */' % idl_type.name
605 602
606 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, v ariable_name, needs_type_check, index, isolate) 603 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, v ariable_name, index, isolate)
607 604
608 if idl_type.is_dictionary or idl_type.is_union_type: 605 if idl_type.is_dictionary or idl_type.is_union_type:
609 return 'TONATIVE_VOID_EXCEPTIONSTATE_ARGINTERNAL(%s, exceptionState)' % cpp_value 606 return 'TONATIVE_VOID_EXCEPTIONSTATE_ARGINTERNAL(%s, exceptionState)' % cpp_value
610 607
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 args = [variable_name, cpp_value]
616 613
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 number_of_nullable_member_types_union) 944 number_of_nullable_member_types_union)
948 945
949 946
950 def includes_nullable_type_union(idl_type): 947 def includes_nullable_type_union(idl_type):
951 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type 948 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type
952 return idl_type.number_of_nullable_member_types == 1 949 return idl_type.number_of_nullable_member_types == 1
953 950
954 IdlTypeBase.includes_nullable_type = False 951 IdlTypeBase.includes_nullable_type = False
955 IdlNullableType.includes_nullable_type = True 952 IdlNullableType.includes_nullable_type = True
956 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) 953 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698