| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 | 83 |
| 84 def method_context(interface, method): | 84 def method_context(interface, method): |
| 85 arguments = method.arguments | 85 arguments = method.arguments |
| 86 extended_attributes = method.extended_attributes | 86 extended_attributes = method.extended_attributes |
| 87 idl_type = method.idl_type | 87 idl_type = method.idl_type |
| 88 is_static = method.is_static | 88 is_static = method.is_static |
| 89 name = method.name | 89 name = method.name |
| 90 | 90 |
| 91 idl_type.add_includes_for_type() | 91 idl_type.add_includes_for_type() |
| 92 this_cpp_value = cpp_value(interface, method, len(arguments)) | 92 this_cpp_value = cpp_value(interface, method) |
| 93 | 93 |
| 94 def function_template(): | 94 def function_template(): |
| 95 if is_static: | 95 if is_static: |
| 96 return 'functionTemplate' | 96 return 'functionTemplate' |
| 97 if 'Unforgeable' in extended_attributes: | 97 if 'Unforgeable' in extended_attributes: |
| 98 return 'instanceTemplate' | 98 return 'instanceTemplate' |
| 99 return 'prototypeTemplate' | 99 return 'prototypeTemplate' |
| 100 | 100 |
| 101 is_implemented_in_private_script = 'ImplementedInPrivateScript' in extended_
attributes | 101 is_implemented_in_private_script = 'ImplementedInPrivateScript' in extended_
attributes |
| 102 if is_implemented_in_private_script: | 102 if is_implemented_in_private_script: |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 'use_local_result': use_local_result(method), | 198 'use_local_result': use_local_result(method), |
| 199 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), | 199 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), |
| 200 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), | 200 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), |
| 201 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended
_attributes else [''], # [PerWorldBindings], | 201 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended
_attributes else [''], # [PerWorldBindings], |
| 202 } | 202 } |
| 203 | 203 |
| 204 | 204 |
| 205 def argument_context(interface, method, argument, index): | 205 def argument_context(interface, method, argument, index): |
| 206 extended_attributes = argument.extended_attributes | 206 extended_attributes = argument.extended_attributes |
| 207 idl_type = argument.idl_type | 207 idl_type = argument.idl_type |
| 208 this_cpp_value = cpp_value(interface, method, index) | |
| 209 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type | 208 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type |
| 210 return_promise = (method.idl_type.name == 'Promise' if method.idl_type | 209 return_promise = (method.idl_type.name == 'Promise' if method.idl_type |
| 211 else False) | 210 else False) |
| 212 | 211 |
| 212 is_explicit_optional = argument.is_optional and not argument.default_value |
| 213 if is_explicit_optional: |
| 214 includes.add('bindings/core/v8/Optional.h') |
| 215 |
| 213 if ('ImplementedInPrivateScript' in extended_attributes and | 216 if ('ImplementedInPrivateScript' in extended_attributes and |
| 214 not idl_type.is_wrapper_type and | 217 not idl_type.is_wrapper_type and |
| 215 not idl_type.is_basic_type): | 218 not idl_type.is_basic_type): |
| 216 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') | 219 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') |
| 217 | 220 |
| 218 return { | 221 return { |
| 219 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut
es, | 222 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut
es, |
| 220 raw_type=True, | 223 raw_type=True, |
| 221 used_as_variadic_argument=argument.is
_variadic), | 224 used_as_variadic_argument=argument.is
_variadic), |
| 222 'cpp_value': this_cpp_value, | 225 'cpp_type_initializer': idl_type.cpp_type_initializer, |
| 223 # FIXME: check that the default value's type is compatible with the argu
ment's | 226 # FIXME: check that the default value's type is compatible with the argu
ment's |
| 224 'default_value': argument.default_cpp_value, | 227 'default_value': argument.default_cpp_value, |
| 225 'enum_validation_expression': idl_type.enum_validation_expression, | 228 'enum_validation_expression': idl_type.enum_validation_expression, |
| 226 'handle': '%sHandle' % argument.name, | 229 'handle': '%sHandle' % argument.name, |
| 227 # FIXME: remove once [Default] removed and just use argument.default_val
ue | |
| 228 'has_default': 'Default' in extended_attributes or argument.default_valu
e, | |
| 229 'has_type_checking_interface': | 230 'has_type_checking_interface': |
| 230 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface'
) or | 231 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface'
) or |
| 231 has_extended_attribute_value(method, 'TypeChecking', 'Interface'))
and | 232 has_extended_attribute_value(method, 'TypeChecking', 'Interface'))
and |
| 232 idl_type.is_wrapper_type, | 233 idl_type.is_wrapper_type, |
| 233 'has_type_checking_unrestricted': | 234 'has_type_checking_unrestricted': |
| 234 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestrict
ed') or | 235 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestrict
ed') or |
| 235 has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted'
)) and | 236 has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted'
)) and |
| 236 idl_type.name in ('Float', 'Double'), | 237 idl_type.name in ('Float', 'Double'), |
| 237 # Dictionary is special-cased, but arrays and sequences shouldn't be | 238 # Dictionary is special-cased, but arrays and sequences shouldn't be |
| 238 'idl_type': idl_type.base_type, | 239 'idl_type': idl_type.base_type, |
| 239 'idl_type_object': idl_type, | 240 'idl_type_object': idl_type, |
| 240 'index': index, | 241 'index': index, |
| 241 'is_clamp': 'Clamp' in extended_attributes, | 242 'is_clamp': 'Clamp' in extended_attributes, |
| 242 'is_callback_interface': idl_type.is_callback_interface, | 243 'is_callback_interface': idl_type.is_callback_interface, |
| 244 'is_explicit_optional': is_explicit_optional, |
| 243 'is_nullable': idl_type.is_nullable, | 245 'is_nullable': idl_type.is_nullable, |
| 244 'is_optional': argument.is_optional, | 246 'is_optional': argument.is_optional, |
| 245 'is_variadic_wrapper_type': is_variadic_wrapper_type, | 247 'is_variadic_wrapper_type': is_variadic_wrapper_type, |
| 246 'is_wrapper_type': idl_type.is_wrapper_type, | 248 'is_wrapper_type': idl_type.is_wrapper_type, |
| 247 'name': argument.name, | 249 'name': argument.name, |
| 248 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( | 250 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( |
| 249 argument.name, isolate='scriptState->isolate()', | 251 argument.name, isolate='scriptState->isolate()', |
| 250 creation_context='scriptState->context()->Global()'), | 252 creation_context='scriptState->context()->Global()'), |
| 251 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), | |
| 252 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), | |
| 253 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind
ex, return_promise=return_promise), | 253 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind
ex, return_promise=return_promise), |
| 254 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc
_type), | 254 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc
_type), |
| 255 } | 255 } |
| 256 | 256 |
| 257 | 257 |
| 258 def argument_declarations_for_private_script(interface, method): | 258 def argument_declarations_for_private_script(interface, method): |
| 259 argument_declarations = ['LocalFrame* frame'] | 259 argument_declarations = ['LocalFrame* frame'] |
| 260 argument_declarations.append('%s* holderImpl' % interface.name) | 260 argument_declarations.append('%s* holderImpl' % interface.name) |
| 261 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args( | 261 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args( |
| 262 used_as_rvalue_type=True), argument.name) for argument in method.argumen
ts]) | 262 used_as_rvalue_type=True), argument.name) for argument in method.argumen
ts]) |
| 263 if method.idl_type.name != 'void': | 263 if method.idl_type.name != 'void': |
| 264 argument_declarations.append('%s* %s' % (method.idl_type.cpp_type, 'resu
lt')) | 264 argument_declarations.append('%s* %s' % (method.idl_type.cpp_type, 'resu
lt')) |
| 265 return argument_declarations | 265 return argument_declarations |
| 266 | 266 |
| 267 | 267 |
| 268 ################################################################################ | 268 ################################################################################ |
| 269 # Value handling | 269 # Value handling |
| 270 ################################################################################ | 270 ################################################################################ |
| 271 | 271 |
| 272 def cpp_value(interface, method, number_of_arguments): | 272 def cpp_value(interface, method): |
| 273 def cpp_argument(argument): | 273 def cpp_argument(argument): |
| 274 idl_type = argument.idl_type | 274 idl_type = argument.idl_type |
| 275 if argument.is_optional and not argument.default_value: |
| 276 cpp_type_optional = v8_types.cpp_template_type( |
| 277 'Optional', idl_type.cpp_type_args( |
| 278 extended_attributes=argument.extended_attributes, |
| 279 raw_type=idl_type.preprocessed_type.is_string_type, |
| 280 used_in_cpp_sequence=True)) |
| 281 return '{cpp_type_optional}({name}, {name}Missing)'.format( |
| 282 cpp_type_optional=cpp_type_optional, |
| 283 name=argument.name) |
| 275 if idl_type.name == 'EventListener': | 284 if idl_type.name == 'EventListener': |
| 276 return argument.name | 285 return argument.name |
| 277 if (idl_type.is_callback_interface or | 286 if (idl_type.is_callback_interface or |
| 278 idl_type.name in ['NodeFilter', 'NodeFilterOrNull', | 287 idl_type.name in ['NodeFilter', 'NodeFilterOrNull', |
| 279 'XPathNSResolver', 'XPathNSResolverOrNull']): | 288 'XPathNSResolver', 'XPathNSResolverOrNull']): |
| 280 # FIXME: remove this special case | 289 # FIXME: remove this special case |
| 281 return '%s.release()' % argument.name | 290 return '%s.release()' % argument.name |
| 282 return argument.name | 291 return argument.name |
| 283 | 292 |
| 284 # Truncate omitted optional arguments | |
| 285 arguments = method.arguments[:number_of_arguments] | |
| 286 cpp_arguments = [] | 293 cpp_arguments = [] |
| 287 if 'ImplementedInPrivateScript' in method.extended_attributes: | 294 if 'ImplementedInPrivateScript' in method.extended_attributes: |
| 288 cpp_arguments.append('toFrameIfNotDetached(info.GetIsolate()->GetCurrent
Context())') | 295 cpp_arguments.append('toFrameIfNotDetached(info.GetIsolate()->GetCurrent
Context())') |
| 289 cpp_arguments.append('impl') | 296 cpp_arguments.append('impl') |
| 290 | 297 |
| 291 if method.is_constructor: | 298 if method.is_constructor: |
| 292 call_with_values = interface.extended_attributes.get('ConstructorCallWit
h') | 299 call_with_values = interface.extended_attributes.get('ConstructorCallWit
h') |
| 293 else: | 300 else: |
| 294 call_with_values = method.extended_attributes.get('CallWith') | 301 call_with_values = method.extended_attributes.get('CallWith') |
| 295 cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values)) | 302 cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values)) |
| 296 | 303 |
| 297 # Members of IDL partial interface definitions are implemented in C++ as | 304 # Members of IDL partial interface definitions are implemented in C++ as |
| 298 # static member functions, which for instance members (non-static members) | 305 # static member functions, which for instance members (non-static members) |
| 299 # take *impl as their first argument | 306 # take *impl as their first argument |
| 300 if ('PartialInterfaceImplementedAs' in method.extended_attributes and | 307 if ('PartialInterfaceImplementedAs' in method.extended_attributes and |
| 301 not 'ImplementedInPrivateScript' in method.extended_attributes and | 308 not 'ImplementedInPrivateScript' in method.extended_attributes and |
| 302 not method.is_static): | 309 not method.is_static): |
| 303 cpp_arguments.append('*impl') | 310 cpp_arguments.append('*impl') |
| 304 cpp_arguments.extend(cpp_argument(argument) for argument in arguments) | 311 cpp_arguments.extend(cpp_argument(argument) for argument in method.arguments
) |
| 305 | 312 |
| 306 this_union_arguments = method.idl_type and method.idl_type.union_arguments | 313 this_union_arguments = method.idl_type and method.idl_type.union_arguments |
| 307 if this_union_arguments: | 314 if this_union_arguments: |
| 308 cpp_arguments.extend([member_argument['cpp_value'] | 315 cpp_arguments.extend([member_argument['cpp_value'] |
| 309 for member_argument in this_union_arguments]) | 316 for member_argument in this_union_arguments]) |
| 310 | 317 |
| 311 if 'ImplementedInPrivateScript' in method.extended_attributes: | 318 if 'ImplementedInPrivateScript' in method.extended_attributes: |
| 312 if method.idl_type.name != 'void': | 319 if method.idl_type.name != 'void': |
| 313 cpp_arguments.append('&result') | 320 cpp_arguments.append('&result') |
| 314 elif ('RaisesException' in method.extended_attributes or | 321 elif ('RaisesException' in method.extended_attributes or |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 | 445 |
| 439 | 446 |
| 440 def argument_default_cpp_value(argument): | 447 def argument_default_cpp_value(argument): |
| 441 if not argument.default_value: | 448 if not argument.default_value: |
| 442 return None | 449 return None |
| 443 return argument.idl_type.literal_cpp_value(argument.default_value) | 450 return argument.idl_type.literal_cpp_value(argument.default_value) |
| 444 | 451 |
| 445 IdlTypeBase.union_arguments = None | 452 IdlTypeBase.union_arguments = None |
| 446 IdlUnionType.union_arguments = property(union_arguments) | 453 IdlUnionType.union_arguments = property(union_arguments) |
| 447 IdlArgument.default_cpp_value = property(argument_default_cpp_value) | 454 IdlArgument.default_cpp_value = property(argument_default_cpp_value) |
| OLD | NEW |