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

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

Powered by Google App Engine
This is Rietveld 408576698