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

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
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), as well as (A or B)?
haraken 2014/11/07 18:06:31 to handle nulle for ... => for (A? or B), (A or B?
bashi 2014/11/08 07:10:34 Done.
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 member_names = "Or".join([member_cpp_name(member)
Jens Widell 2014/11/07 10:58:19 Drop the [] to make it a generator expression inst
bashi 2014/11/08 07:10:34 Done.
203 for member in idl_type.member_types])
204 return member_names
197 205
198 # Default, assume native type is a pointer with same type name as idl type 206 # Default, assume native type is a pointer with same type name as idl type
199 return base_idl_type + '*' 207 return base_idl_type + '*'
200 208
201 209
202 def cpp_type_initializer(idl_type): 210 def cpp_type_initializer(idl_type):
203 """Returns a string containing a C++ initialization statement for the 211 """Returns a string containing a C++ initialization statement for the
204 corresponding type. 212 corresponding type.
205 213
206 |idl_type| argument is of type IdlType. 214 |idl_type| argument is of type IdlType.
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 return '' 518 return ''
511 519
512 # Array or sequence types 520 # Array or sequence types
513 native_array_element_type = idl_type.native_array_element_type 521 native_array_element_type = idl_type.native_array_element_type
514 if native_array_element_type: 522 if native_array_element_type:
515 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index) 523 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index)
516 524
517 # Simple types 525 # Simple types
518 idl_type = idl_type.preprocessed_type 526 idl_type = idl_type.preprocessed_type
519 add_includes_for_type(idl_type) 527 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 528 base_idl_type = idl_type.as_union_type.name if idl_type.is_union_type else i dl_type.base_type
521 529
522 if 'EnforceRange' in extended_attributes: 530 if 'EnforceRange' in extended_attributes:
523 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState']) 531 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState'])
524 elif 'Clamp' in extended_attributes: 532 elif 'Clamp' in extended_attributes:
525 arguments = ', '.join([v8_value, 'Clamp', 'exceptionState']) 533 arguments = ', '.join([v8_value, 'Clamp', 'exceptionState'])
526 elif idl_type.v8_conversion_needs_exception_state: 534 elif idl_type.v8_conversion_needs_exception_state:
527 arguments = ', '.join([v8_value, 'exceptionState']) 535 arguments = ', '.join([v8_value, 'exceptionState'])
528 else: 536 else:
529 arguments = v8_value 537 arguments = v8_value
530 538
531 if base_idl_type in V8_VALUE_TO_CPP_VALUE: 539 if base_idl_type in V8_VALUE_TO_CPP_VALUE:
532 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] 540 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type]
533 elif idl_type.is_array_buffer_or_view: 541 elif idl_type.is_array_buffer_or_view:
534 cpp_expression_format = ( 542 cpp_expression_format = (
535 '{v8_value}->Is{idl_type}() ? ' 543 '{v8_value}->Is{idl_type}() ? '
536 'V8{idl_type}::toImpl(v8::Handle<v8::{idl_type}>::Cast({v8_value})) : 0') 544 '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: 545 elif idl_type.use_output_parameter_for_result:
546 if idl_type.includes_nullable_type:
547 base_idl_type = idl_type.cpp_type + 'OrNull'
538 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va riable_name}, exceptionState)' 548 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va riable_name}, exceptionState)'
539 elif needs_type_check: 549 elif needs_type_check:
540 cpp_expression_format = ( 550 cpp_expression_format = (
541 'V8{idl_type}::toImplWithTypeCheck({isolate}, {v8_value})') 551 'V8{idl_type}::toImplWithTypeCheck({isolate}, {v8_value})')
542 else: 552 else:
543 cpp_expression_format = ( 553 cpp_expression_format = (
544 'V8{idl_type}::toImpl(v8::Handle<v8::Object>::Cast({v8_value}))') 554 'V8{idl_type}::toImpl(v8::Handle<v8::Object>::Cast({v8_value}))')
545 555
546 return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_t ype, v8_value=v8_value, variable_name=variable_name, isolate=isolate) 556 return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_t ype, v8_value=v8_value, variable_name=variable_name, isolate=isolate)
547 557
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 # Utility properties for nullable types 863 # Utility properties for nullable types
854 ################################################################################ 864 ################################################################################
855 865
856 866
857 def cpp_type_has_null_value(idl_type): 867 def cpp_type_has_null_value(idl_type):
858 # - String types (String/AtomicString) represent null as a null string, 868 # - String types (String/AtomicString) represent null as a null string,
859 # i.e. one for which String::isNull() returns true. 869 # i.e. one for which String::isNull() returns true.
860 # - Enum types, as they are implemented as Strings. 870 # - Enum types, as they are implemented as Strings.
861 # - Wrapper types (raw pointer or RefPtr/PassRefPtr) represent null as 871 # - Wrapper types (raw pointer or RefPtr/PassRefPtr) represent null as
862 # a null pointer. 872 # a null pointer.
873 # - Union types, as thier container classes can represent null value.
863 # - 'Object' type. We use ScriptValue for object type. 874 # - 'Object' type. We use ScriptValue for object type.
864 return (idl_type.is_string_type or idl_type.is_wrapper_type or 875 return (idl_type.is_string_type or idl_type.is_wrapper_type or
865 idl_type.is_enum or idl_type.base_type == 'object') 876 idl_type.is_enum or idl_type.is_union_type
877 or idl_type.base_type == 'object')
866 878
867 IdlTypeBase.cpp_type_has_null_value = property(cpp_type_has_null_value) 879 IdlTypeBase.cpp_type_has_null_value = property(cpp_type_has_null_value)
868 880
869 881
870 def is_implicit_nullable(idl_type): 882 def is_implicit_nullable(idl_type):
871 # Nullable type where the corresponding C++ type supports a null value. 883 # 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 884 return idl_type.is_nullable and idl_type.cpp_type_has_null_value
873 885
874 886
875 def is_explicit_nullable(idl_type): 887 def is_explicit_nullable(idl_type):
876 # Nullable type that isn't implicit nullable (see above.) For such types, 888 # 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. 889 # 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 890 return idl_type.is_nullable and not idl_type.is_implicit_nullable
879 891
880 IdlTypeBase.is_implicit_nullable = property(is_implicit_nullable) 892 IdlTypeBase.is_implicit_nullable = property(is_implicit_nullable)
881 IdlUnionType.is_implicit_nullable = False 893 IdlUnionType.is_implicit_nullable = False
882 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable) 894 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable)
895
896
897 def number_of_nullable_member_types_union(idl_type):
898 # http://heycam.github.io/webidl/#dfn-number-of-nullable-member-types
899 count = 0
900 for member in idl_type.member_types:
901 if member.is_nullable:
902 count += 1
903 member = member.inner_type
904 if member.is_union_type:
905 count += number_of_nullable_member_types_union(member)
906 return count
907
908 IdlUnionType.number_of_nullable_member_types = property(
909 number_of_nullable_member_types_union)
910
911
912 def includes_nullable_type_union(idl_type):
913 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type
914 return idl_type.number_of_nullable_member_types == 1
915
916 IdlTypeBase.includes_nullable_type = False
917 IdlNullableType.includes_nullable_type = True
918 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698