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

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

Issue 386963003: [WIP][NotForLand] IDL dictionary support (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 5 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 'Promise': 'ScriptPromise', 113 'Promise': 'ScriptPromise',
114 'ScriptValue': 'ScriptValue', 114 'ScriptValue': 'ScriptValue',
115 # FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345 529 115 # FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345 529
116 'XPathNSResolver': 'RefPtrWillBeRawPtr<XPathNSResolver>', 116 'XPathNSResolver': 'RefPtrWillBeRawPtr<XPathNSResolver>',
117 'boolean': 'bool', 117 'boolean': 'bool',
118 'unrestricted double': 'double', 118 'unrestricted double': 'double',
119 'unrestricted float': 'float', 119 'unrestricted float': 'float',
120 } 120 }
121 121
122 122
123 def cpp_type(idl_type, extended_attributes=None, raw_type=False, used_as_argumen t=False, used_as_variadic_argument=False, used_in_cpp_sequence=False): 123 # FIXME: too many flags.
124 def cpp_type(idl_type, extended_attributes=None, raw_type=False, used_as_argumen t=False, used_as_variadic_argument=False, used_as_member=False, used_as_return_t ype=False):
124 """Returns C++ type corresponding to IDL type. 125 """Returns C++ type corresponding to IDL type.
125 126
126 |idl_type| argument is of type IdlType, while return value is a string 127 |idl_type| argument is of type IdlType, while return value is a string
127 128
128 Args: 129 Args:
129 idl_type: 130 idl_type:
130 IdlType 131 IdlType
131 raw_type: 132 raw_type:
132 bool, True if idl_type's raw/primitive C++ type should be returned. 133 bool, True if idl_type's raw/primitive C++ type should be returned.
133 used_as_argument: 134 used_as_argument:
134 bool, True if the C++ type is used as an argument of a method. 135 bool, True if the C++ type is used as an argument of a method.
135 used_as_variadic_argument: 136 used_as_variadic_argument:
136 bool, True if the C++ type is used as a variadic argument of a metho d. 137 bool, True if the C++ type is used as a variadic argument of a metho d.
137 used_in_cpp_sequence: 138 used_as_member:
138 bool, True if the C++ type is used as an element of an array or sequ ence. 139 bool, True if the C++ type is used as a member of a container.
140 Containers can be an array, a sequence or a dictionary.
141 used_as_return_type:
142 bool, True if the C++ type is used as a return type of a method.
139 """ 143 """
140 def string_mode(): 144 def string_mode():
141 if extended_attributes.get('TreatNullAs') == 'EmptyString': 145 if extended_attributes.get('TreatNullAs') == 'EmptyString':
142 return 'TreatNullAsEmptyString' 146 return 'TreatNullAsEmptyString'
143 if idl_type.is_nullable or extended_attributes.get('TreatNullAs') == 'Nu llString': 147 if idl_type.is_nullable or extended_attributes.get('TreatNullAs') == 'Nu llString':
144 if extended_attributes.get('TreatUndefinedAs') == 'NullString': 148 if extended_attributes.get('TreatUndefinedAs') == 'NullString':
145 return 'TreatNullAndUndefinedAsNullString' 149 return 'TreatNullAndUndefinedAsNullString'
146 return 'TreatNullAsNullString' 150 return 'TreatNullAsNullString'
147 return '' 151 return ''
148 152
149 extended_attributes = extended_attributes or {} 153 extended_attributes = extended_attributes or {}
150 idl_type = idl_type.preprocessed_type 154 idl_type = idl_type.preprocessed_type
151 155
152 # Composite types 156 # Composite types
153 if used_as_variadic_argument: 157 if used_as_variadic_argument:
154 native_array_element_type = idl_type 158 native_array_element_type = idl_type
155 else: 159 else:
156 native_array_element_type = idl_type.native_array_element_type 160 native_array_element_type = idl_type.native_array_element_type
157 if native_array_element_type: 161 if native_array_element_type:
158 vector_type = cpp_ptr_type('Vector', 'HeapVector', native_array_element_ type.gc_type) 162 vector_type = cpp_ptr_type('Vector', 'HeapVector', native_array_element_ type.gc_type)
159 return cpp_template_type(vector_type, native_array_element_type.cpp_type _args(used_in_cpp_sequence=True)) 163 vector_template_type = cpp_template_type(vector_type, native_array_eleme nt_type.cpp_type_args(used_as_member=True))
164 if used_as_return_type:
165 return 'const %s&' % vector_template_type
166 return vector_template_type
160 167
161 # Simple types 168 # Simple types
162 base_idl_type = idl_type.base_type 169 base_idl_type = idl_type.base_type
163 170
164 if base_idl_type in CPP_TYPE_SAME_AS_IDL_TYPE: 171 if base_idl_type in CPP_TYPE_SAME_AS_IDL_TYPE:
165 return base_idl_type 172 return base_idl_type
166 if base_idl_type in CPP_INT_TYPES: 173 if base_idl_type in CPP_INT_TYPES:
167 return 'int' 174 return 'int'
168 if base_idl_type in CPP_UNSIGNED_TYPES: 175 if base_idl_type in CPP_UNSIGNED_TYPES:
169 return 'unsigned' 176 return 'unsigned'
170 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES: 177 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES:
171 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type] 178 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type]
172 179
173 if base_idl_type in NON_WRAPPER_TYPES: 180 if base_idl_type in NON_WRAPPER_TYPES:
174 return ('PassRefPtr<%s>' if used_as_argument else 'RefPtr<%s>') % base_i dl_type 181 return ('PassRefPtr<%s>' if used_as_argument or used_as_return_type else 'RefPtr<%s>') % base_idl_type
175 if idl_type.is_string_type: 182 if idl_type.is_string_type:
176 if not raw_type: 183 if not raw_type:
177 return 'String' 184 return 'String'
178 return 'V8StringResource<%s>' % string_mode() 185 return 'V8StringResource<%s>' % string_mode()
179 186
180 if idl_type.is_typed_array_element_type and raw_type: 187 if idl_type.is_typed_array_element_type and raw_type:
181 return base_idl_type + '*' 188 return base_idl_type + '*'
182 if idl_type.is_interface_type: 189 if idl_type.is_interface_type:
183 implemented_as_class = idl_type.implemented_as 190 implemented_as_class = idl_type.implemented_as
184 if raw_type: 191 if raw_type:
185 return implemented_as_class + '*' 192 return implemented_as_class + '*'
186 new_type = 'Member' if used_in_cpp_sequence else 'RawPtr' 193 new_type = 'Member' if used_as_member else 'RawPtr'
187 ptr_type = cpp_ptr_type(('PassRefPtr' if used_as_argument else 'RefPtr') , new_type, idl_type.gc_type) 194 ptr_type = cpp_ptr_type(('PassRefPtr' if used_as_argument or used_as_ret urn_type else 'RefPtr'), new_type, idl_type.gc_type)
188 return cpp_template_type(ptr_type, implemented_as_class) 195 return cpp_template_type(ptr_type, implemented_as_class)
189 # Default, assume native type is a pointer with same type name as idl type 196 # Default, assume native type is a pointer with same type name as idl type
190 return base_idl_type + '*' 197 return base_idl_type + '*'
191 198
192 199
193 def cpp_type_initializer(idl_type): 200 def cpp_type_initializer(idl_type):
194 """Returns a string containing a C++ initialization statement for the 201 """Returns a string containing a C++ initialization statement for the
195 corresponding type. 202 corresponding type.
196 203
197 |idl_type| argument is of type IdlType. 204 |idl_type| argument is of type IdlType.
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Han dle<v8::Value>(v8::Null({isolate}))', 723 'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Han dle<v8::Value>(v8::Null({isolate}))',
717 # General 724 # General
718 'array': 'v8Array({cpp_value}, {creation_context}, {isolate})', 725 'array': 'v8Array({cpp_value}, {creation_context}, {isolate})',
719 'DOMWrapper': 'toV8({cpp_value}, {creation_context}, {isolate})', 726 'DOMWrapper': 'toV8({cpp_value}, {creation_context}, {isolate})',
720 } 727 }
721 728
722 729
723 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='info.Holder()', extended_attributes=None): 730 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='info.Holder()', extended_attributes=None):
724 """Returns an expression that converts a C++ value to a V8 value.""" 731 """Returns an expression that converts a C++ value to a V8 value."""
725 # the isolate parameter is needed for callback interfaces 732 # the isolate parameter is needed for callback interfaces
733 if cpp_value == 'nullptr':
734 return 'v8::Null(%s)' % isolate
726 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes) 735 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes)
727 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) 736 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes)
728 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] 737 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type]
729 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context) 738 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context)
730 return statement 739 return statement
731 740
732 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value 741 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value
733 742
734 743
735 def literal_cpp_value(idl_type, idl_literal): 744 def literal_cpp_value(idl_type, idl_literal):
(...skipping 25 matching lines...) Expand all
761 770
762 def is_explicit_nullable(idl_type): 771 def is_explicit_nullable(idl_type):
763 # Nullable type that isn't implicit nullable (see above.) For such types, 772 # Nullable type that isn't implicit nullable (see above.) For such types,
764 # we use Nullable<T> or similar explicit ways to represent a null value. 773 # we use Nullable<T> or similar explicit ways to represent a null value.
765 return idl_type.is_nullable and not idl_type.is_implicit_nullable 774 return idl_type.is_nullable and not idl_type.is_implicit_nullable
766 775
767 IdlType.is_implicit_nullable = property(is_implicit_nullable) 776 IdlType.is_implicit_nullable = property(is_implicit_nullable)
768 IdlType.is_explicit_nullable = property(is_explicit_nullable) 777 IdlType.is_explicit_nullable = property(is_explicit_nullable)
769 IdlUnionType.is_implicit_nullable = False 778 IdlUnionType.is_implicit_nullable = False
770 IdlUnionType.is_explicit_nullable = property(is_explicit_nullable) 779 IdlUnionType.is_explicit_nullable = property(is_explicit_nullable)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698