OLD | NEW |
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 # generate_argument() macro in Source/bindings/templates/methods.cpp. | 60 # generate_argument() macro in Source/bindings/templates/methods.cpp. |
61 idl_type.is_callback_interface or | 61 idl_type.is_callback_interface or |
62 base_type == 'SerializedScriptValue' or | 62 base_type == 'SerializedScriptValue' or |
63 (argument.is_variadic and idl_type.is_wrapper_type) or | 63 (argument.is_variadic and idl_type.is_wrapper_type) or |
64 # String and enumeration arguments converted using one of the | 64 # String and enumeration arguments converted using one of the |
65 # TOSTRING_* macros in Source/bindings/v8/V8BindingMacros.h don't | 65 # TOSTRING_* macros in Source/bindings/v8/V8BindingMacros.h don't |
66 # use a v8::TryCatch. | 66 # use a v8::TryCatch. |
67 (base_type == 'DOMString' and not argument.is_variadic)) | 67 (base_type == 'DOMString' and not argument.is_variadic)) |
68 | 68 |
69 | 69 |
| 70 def argument_is_explicit_optional(method, index): |
| 71 argument = method.arguments[index] |
| 72 if not(argument.is_optional and |
| 73 not argument.default_value and |
| 74 not 'Default' in argument.extended_attributes): |
| 75 # Argument itself is not optional, or has a default value. |
| 76 return False |
| 77 for following in method.arguments[index + 1:]: |
| 78 if (following.default_value or |
| 79 'Default' in following.extended_attributes): |
| 80 # A following argument has a default value. |
| 81 return True |
| 82 return False |
| 83 |
| 84 |
70 def generate_method(interface, method): | 85 def generate_method(interface, method): |
71 arguments = method.arguments | 86 arguments = method.arguments |
72 extended_attributes = method.extended_attributes | 87 extended_attributes = method.extended_attributes |
73 idl_type = method.idl_type | 88 idl_type = method.idl_type |
74 is_static = method.is_static | 89 is_static = method.is_static |
75 name = method.name | 90 name = method.name |
76 | 91 |
77 idl_type.add_includes_for_type() | 92 idl_type.add_includes_for_type() |
78 this_cpp_value = cpp_value(interface, method, len(arguments)) | 93 this_cpp_value = cpp_value(interface, method, len(arguments)) |
79 | 94 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 'has_type_checking_unrestricted': | 211 'has_type_checking_unrestricted': |
197 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestrict
ed') or | 212 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestrict
ed') or |
198 has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted'
)) and | 213 has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted'
)) and |
199 idl_type.name in ('Float', 'Double'), | 214 idl_type.name in ('Float', 'Double'), |
200 # Dictionary is special-cased, but arrays and sequences shouldn't be | 215 # Dictionary is special-cased, but arrays and sequences shouldn't be |
201 'idl_type': not idl_type.array_or_sequence_type and idl_type.base_type, | 216 'idl_type': not idl_type.array_or_sequence_type and idl_type.base_type, |
202 'idl_type_object': idl_type, | 217 'idl_type_object': idl_type, |
203 'index': index, | 218 'index': index, |
204 'is_clamp': 'Clamp' in extended_attributes, | 219 'is_clamp': 'Clamp' in extended_attributes, |
205 'is_callback_interface': idl_type.is_callback_interface, | 220 'is_callback_interface': idl_type.is_callback_interface, |
| 221 'is_explicit_optional': argument_is_explicit_optional(method, index), |
206 'is_nullable': idl_type.is_nullable, | 222 'is_nullable': idl_type.is_nullable, |
207 'is_optional': argument.is_optional, | 223 'is_optional': argument.is_optional, |
208 'is_variadic_wrapper_type': is_variadic_wrapper_type, | 224 'is_variadic_wrapper_type': is_variadic_wrapper_type, |
209 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc
_type), | 225 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc
_type), |
210 'is_wrapper_type': idl_type.is_wrapper_type, | 226 'is_wrapper_type': idl_type.is_wrapper_type, |
211 'name': argument.name, | 227 'name': argument.name, |
212 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), | 228 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), |
213 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), | 229 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), |
214 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind
ex), | 230 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind
ex), |
215 } | 231 } |
216 | 232 |
217 | 233 |
218 ################################################################################ | 234 ################################################################################ |
219 # Value handling | 235 # Value handling |
220 ################################################################################ | 236 ################################################################################ |
221 | 237 |
222 def cpp_value(interface, method, number_of_arguments): | 238 def cpp_value(interface, method, number_of_arguments): |
223 def cpp_argument(argument): | 239 def cpp_argument(index): |
| 240 argument = method.arguments[index] |
224 idl_type = argument.idl_type | 241 idl_type = argument.idl_type |
225 if idl_type.name == 'EventListener': | 242 if idl_type.name == 'EventListener': |
226 if (interface.name == 'EventTarget' and | 243 if (interface.name == 'EventTarget' and |
227 method.name == 'removeEventListener'): | 244 method.name == 'removeEventListener'): |
228 # FIXME: remove this special case by moving get() into | 245 # FIXME: remove this special case by moving get() into |
229 # EventTarget::removeEventListener | 246 # EventTarget::removeEventListener |
230 return '%s.get()' % argument.name | 247 return '%s.get()' % argument.name |
231 return argument.name | 248 return argument.name |
232 if (idl_type.is_callback_interface or | 249 if (idl_type.is_callback_interface or |
233 idl_type.name in ['NodeFilter', 'XPathNSResolver']): | 250 idl_type.name in ['NodeFilter', 'XPathNSResolver']): |
234 # FIXME: remove this special case | 251 # FIXME: remove this special case |
235 return '%s.release()' % argument.name | 252 return '%s.release()' % argument.name |
| 253 if argument_is_explicit_optional(method, index): |
| 254 return 'makeOptional({name}, {name}Missing)'.format( |
| 255 name=argument.name) |
236 return argument.name | 256 return argument.name |
237 | 257 |
238 # Truncate omitted optional arguments | |
239 arguments = method.arguments[:number_of_arguments] | |
240 cpp_arguments = v8_utilities.call_with_arguments(method) | 258 cpp_arguments = v8_utilities.call_with_arguments(method) |
241 # Members of IDL partial interface definitions are implemented in C++ as | 259 # Members of IDL partial interface definitions are implemented in C++ as |
242 # static member functions, which for instance members (non-static members) | 260 # static member functions, which for instance members (non-static members) |
243 # take *impl as their first argument | 261 # take *impl as their first argument |
244 if ('PartialInterfaceImplementedAs' in method.extended_attributes and | 262 if ('PartialInterfaceImplementedAs' in method.extended_attributes and |
245 not method.is_static): | 263 not method.is_static): |
246 cpp_arguments.append('*impl') | 264 cpp_arguments.append('*impl') |
247 cpp_arguments.extend(cpp_argument(argument) for argument in arguments) | 265 cpp_arguments.extend(cpp_argument(index) |
| 266 for index in range(number_of_arguments)) |
248 this_union_arguments = method.idl_type and method.idl_type.union_arguments | 267 this_union_arguments = method.idl_type and method.idl_type.union_arguments |
249 if this_union_arguments: | 268 if this_union_arguments: |
250 cpp_arguments.extend(this_union_arguments) | 269 cpp_arguments.extend(this_union_arguments) |
251 | 270 |
252 if 'RaisesException' in method.extended_attributes: | 271 if 'RaisesException' in method.extended_attributes: |
253 cpp_arguments.append('exceptionState') | 272 cpp_arguments.append('exceptionState') |
254 | 273 |
255 if method.name == 'Constructor': | 274 if method.name == 'Constructor': |
256 base_name = 'create' | 275 base_name = 'create' |
257 elif method.name == 'NamedConstructor': | 276 elif method.name == 'NamedConstructor': |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 | 342 |
324 | 343 |
325 def union_arguments(idl_type): | 344 def union_arguments(idl_type): |
326 """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for u
nion types, for use in setting return value""" | 345 """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for u
nion types, for use in setting return value""" |
327 return [arg | 346 return [arg |
328 for i in range(len(idl_type.member_types)) | 347 for i in range(len(idl_type.member_types)) |
329 for arg in ['result%sEnabled' % i, 'result%s' % i]] | 348 for arg in ['result%sEnabled' % i, 'result%s' % i]] |
330 | 349 |
331 IdlType.union_arguments = property(lambda self: None) | 350 IdlType.union_arguments = property(lambda self: None) |
332 IdlUnionType.union_arguments = property(union_arguments) | 351 IdlUnionType.union_arguments = property(union_arguments) |
OLD | NEW |