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

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

Issue 698423002: IDL union: nullable support (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « Source/bindings/scripts/idl_types.py ('k') | Source/bindings/scripts/v8_union.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 if idl_type.is_interface_type: 186 if idl_type.is_interface_type:
187 implemented_as_class = idl_type.implemented_as 187 implemented_as_class = idl_type.implemented_as
188 if raw_type: 188 if raw_type:
189 return implemented_as_class + '*' 189 return implemented_as_class + '*'
190 new_type = 'Member' if used_in_cpp_sequence else 'RawPtr' 190 new_type = 'Member' if used_in_cpp_sequence else 'RawPtr'
191 ptr_type = cpp_ptr_type(('PassRefPtr' if used_as_rvalue_type else 'RefPt r'), new_type, idl_type.gc_type) 191 ptr_type = cpp_ptr_type(('PassRefPtr' if used_as_rvalue_type else 'RefPt r'), new_type, idl_type.gc_type)
192 return cpp_template_type(ptr_type, implemented_as_class) 192 return cpp_template_type(ptr_type, implemented_as_class)
193 if idl_type.is_dictionary: 193 if idl_type.is_dictionary:
194 return base_idl_type 194 return base_idl_type
195 if idl_type.is_union_type: 195 if idl_type.is_union_type:
196 return idl_type.name 196 # Avoid "AOrNullOrB" for cpp type of (A? or B) because we generate
197 # V8AOrBOrNull to handle nulle for (A? or B), (A or B?) and (A or B)?
198 def member_cpp_name(idl_type):
199 if idl_type.is_nullable:
200 return idl_type.inner_type.name
201 return idl_type.name
202 return "Or".join(member_cpp_name(member)
203 for member in idl_type.member_types)
197 204
198 # Default, assume native type is a pointer with same type name as idl type 205 # Default, assume native type is a pointer with same type name as idl type
199 return base_idl_type + '*' 206 return base_idl_type + '*'
200 207
201 208
202 def cpp_type_initializer(idl_type): 209 def cpp_type_initializer(idl_type):
203 """Returns a string containing a C++ initialization statement for the 210 """Returns a string containing a C++ initialization statement for the
204 corresponding type. 211 corresponding type.
205 212
206 |idl_type| argument is of type IdlType. 213 |idl_type| argument is of type IdlType.
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 return '' 517 return ''
511 518
512 # Array or sequence types 519 # Array or sequence types
513 native_array_element_type = idl_type.native_array_element_type 520 native_array_element_type = idl_type.native_array_element_type
514 if native_array_element_type: 521 if native_array_element_type:
515 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index) 522 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index)
516 523
517 # Simple types 524 # Simple types
518 idl_type = idl_type.preprocessed_type 525 idl_type = idl_type.preprocessed_type
519 add_includes_for_type(idl_type) 526 add_includes_for_type(idl_type)
520 base_idl_type = idl_type.name if idl_type.is_union_type else idl_type.base_t ype 527 base_idl_type = idl_type.as_union_type.name if idl_type.is_union_type else i dl_type.base_type
521 528
522 if 'EnforceRange' in extended_attributes: 529 if 'EnforceRange' in extended_attributes:
523 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState']) 530 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState'])
524 elif 'Clamp' in extended_attributes: 531 elif 'Clamp' in extended_attributes:
525 arguments = ', '.join([v8_value, 'Clamp', 'exceptionState']) 532 arguments = ', '.join([v8_value, 'Clamp', 'exceptionState'])
526 elif idl_type.v8_conversion_needs_exception_state: 533 elif idl_type.v8_conversion_needs_exception_state:
527 arguments = ', '.join([v8_value, 'exceptionState']) 534 arguments = ', '.join([v8_value, 'exceptionState'])
528 else: 535 else:
529 arguments = v8_value 536 arguments = v8_value
530 537
531 if base_idl_type in V8_VALUE_TO_CPP_VALUE: 538 if base_idl_type in V8_VALUE_TO_CPP_VALUE:
532 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] 539 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type]
533 elif idl_type.is_array_buffer_or_view: 540 elif idl_type.is_array_buffer_or_view:
534 cpp_expression_format = ( 541 cpp_expression_format = (
535 '{v8_value}->Is{idl_type}() ? ' 542 '{v8_value}->Is{idl_type}() ? '
536 'V8{idl_type}::toImpl(v8::Handle<v8::{idl_type}>::Cast({v8_value})) : 0') 543 'V8{idl_type}::toImpl(v8::Handle<v8::{idl_type}>::Cast({v8_value})) : 0')
537 elif idl_type.is_dictionary or idl_type.is_union_type: 544 elif idl_type.use_output_parameter_for_result:
545 if idl_type.includes_nullable_type:
546 base_idl_type = idl_type.cpp_type + 'OrNull'
538 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va riable_name}, exceptionState)' 547 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va riable_name}, exceptionState)'
539 elif needs_type_check: 548 elif needs_type_check:
540 cpp_expression_format = ( 549 cpp_expression_format = (
541 'V8{idl_type}::toImplWithTypeCheck({isolate}, {v8_value})') 550 'V8{idl_type}::toImplWithTypeCheck({isolate}, {v8_value})')
542 else: 551 else:
543 cpp_expression_format = ( 552 cpp_expression_format = (
544 'V8{idl_type}::toImpl(v8::Handle<v8::Object>::Cast({v8_value}))') 553 'V8{idl_type}::toImpl(v8::Handle<v8::Object>::Cast({v8_value}))')
545 554
546 return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_t ype, v8_value=v8_value, variable_name=variable_name, isolate=isolate) 555 return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_t ype, v8_value=v8_value, variable_name=variable_name, isolate=isolate)
547 556
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 # Utility properties for nullable types 862 # Utility properties for nullable types
854 ################################################################################ 863 ################################################################################
855 864
856 865
857 def cpp_type_has_null_value(idl_type): 866 def cpp_type_has_null_value(idl_type):
858 # - String types (String/AtomicString) represent null as a null string, 867 # - String types (String/AtomicString) represent null as a null string,
859 # i.e. one for which String::isNull() returns true. 868 # i.e. one for which String::isNull() returns true.
860 # - Enum types, as they are implemented as Strings. 869 # - Enum types, as they are implemented as Strings.
861 # - Wrapper types (raw pointer or RefPtr/PassRefPtr) represent null as 870 # - Wrapper types (raw pointer or RefPtr/PassRefPtr) represent null as
862 # a null pointer. 871 # a null pointer.
872 # - Union types, as thier container classes can represent null value.
863 # - 'Object' type. We use ScriptValue for object type. 873 # - 'Object' type. We use ScriptValue for object type.
864 return (idl_type.is_string_type or idl_type.is_wrapper_type or 874 return (idl_type.is_string_type or idl_type.is_wrapper_type or
865 idl_type.is_enum or idl_type.base_type == 'object') 875 idl_type.is_enum or idl_type.is_union_type
876 or idl_type.base_type == 'object')
866 877
867 IdlTypeBase.cpp_type_has_null_value = property(cpp_type_has_null_value) 878 IdlTypeBase.cpp_type_has_null_value = property(cpp_type_has_null_value)
868 879
869 880
870 def is_implicit_nullable(idl_type): 881 def is_implicit_nullable(idl_type):
871 # Nullable type where the corresponding C++ type supports a null value. 882 # Nullable type where the corresponding C++ type supports a null value.
872 return idl_type.is_nullable and idl_type.cpp_type_has_null_value 883 return idl_type.is_nullable and idl_type.cpp_type_has_null_value
873 884
874 885
875 def is_explicit_nullable(idl_type): 886 def is_explicit_nullable(idl_type):
876 # Nullable type that isn't implicit nullable (see above.) For such types, 887 # Nullable type that isn't implicit nullable (see above.) For such types,
877 # we use Nullable<T> or similar explicit ways to represent a null value. 888 # we use Nullable<T> or similar explicit ways to represent a null value.
878 return idl_type.is_nullable and not idl_type.is_implicit_nullable 889 return idl_type.is_nullable and not idl_type.is_implicit_nullable
879 890
880 IdlTypeBase.is_implicit_nullable = property(is_implicit_nullable) 891 IdlTypeBase.is_implicit_nullable = property(is_implicit_nullable)
881 IdlUnionType.is_implicit_nullable = False 892 IdlUnionType.is_implicit_nullable = False
882 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable) 893 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable)
894
895
896 def number_of_nullable_member_types_union(idl_type):
897 # http://heycam.github.io/webidl/#dfn-number-of-nullable-member-types
898 count = 0
899 for member in idl_type.member_types:
900 if member.is_nullable:
901 count += 1
902 member = member.inner_type
903 if member.is_union_type:
904 count += number_of_nullable_member_types_union(member)
905 return count
906
907 IdlUnionType.number_of_nullable_member_types = property(
908 number_of_nullable_member_types_union)
909
910
911 def includes_nullable_type_union(idl_type):
912 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type
913 return idl_type.number_of_nullable_member_types == 1
914
915 IdlTypeBase.includes_nullable_type = False
916 IdlNullableType.includes_nullable_type = True
917 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union)
OLDNEW
« no previous file with comments | « Source/bindings/scripts/idl_types.py ('k') | Source/bindings/scripts/v8_union.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698