| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 idl_type.add_includes_for_type(extended_attributes) | 211 idl_type.add_includes_for_type(extended_attributes) |
| 212 this_cpp_value = cpp_value(interface, method, index) | 212 this_cpp_value = cpp_value(interface, method, index) |
| 213 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type | 213 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type |
| 214 | 214 |
| 215 # [TypeChecking=Interface] / [LegacyInterfaceTypeChecking] | 215 # [TypeChecking=Interface] / [LegacyInterfaceTypeChecking] |
| 216 has_type_checking_interface = ( | 216 has_type_checking_interface = ( |
| 217 not is_legacy_interface_type_checking(interface, method) and | 217 not is_legacy_interface_type_checking(interface, method) and |
| 218 idl_type.is_wrapper_type) | 218 idl_type.is_wrapper_type) |
| 219 | 219 |
| 220 if ('ImplementedInPrivateScript' in extended_attributes and | 220 if ('ImplementedInPrivateScript' in extended_attributes and |
| 221 not idl_type.is_wrapper_type and | 221 not idl_type.is_wrapper_type and |
| 222 not idl_type.is_basic_type): | 222 not idl_type.is_basic_type): |
| 223 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') | 223 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') |
| 224 | 224 |
| 225 set_default_value = argument.set_default_value | 225 set_default_value = argument.set_default_value |
| 226 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, | 226 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, |
| 227 raw_type=True, | 227 raw_type=True, |
| 228 used_as_variadic_argument=argument.is
_variadic) | 228 used_as_variadic_argument=argument.is
_variadic) |
| 229 return { | 229 return { |
| 230 'cpp_type': ( | 230 'cpp_type': ( |
| 231 v8_types.cpp_template_type('Nullable', this_cpp_type) | 231 v8_types.cpp_template_type('Nullable', this_cpp_type) |
| 232 if idl_type.is_explicit_nullable and not argument.is_variadic | 232 if idl_type.is_explicit_nullable and not argument.is_variadic |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 if method.is_constructor: | 300 if method.is_constructor: |
| 301 call_with_values = interface.extended_attributes.get('ConstructorCallWit
h') | 301 call_with_values = interface.extended_attributes.get('ConstructorCallWit
h') |
| 302 else: | 302 else: |
| 303 call_with_values = method.extended_attributes.get('CallWith') | 303 call_with_values = method.extended_attributes.get('CallWith') |
| 304 cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values)) | 304 cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values)) |
| 305 | 305 |
| 306 # Members of IDL partial interface definitions are implemented in C++ as | 306 # Members of IDL partial interface definitions are implemented in C++ as |
| 307 # static member functions, which for instance members (non-static members) | 307 # static member functions, which for instance members (non-static members) |
| 308 # take *impl as their first argument | 308 # take *impl as their first argument |
| 309 if ('PartialInterfaceImplementedAs' in method.extended_attributes and | 309 if ('PartialInterfaceImplementedAs' in method.extended_attributes and |
| 310 not 'ImplementedInPrivateScript' in method.extended_attributes and | 310 'ImplementedInPrivateScript' not in method.extended_attributes and |
| 311 not method.is_static): | 311 not method.is_static): |
| 312 cpp_arguments.append('*impl') | 312 cpp_arguments.append('*impl') |
| 313 cpp_arguments.extend(cpp_argument(argument) for argument in arguments) | 313 cpp_arguments.extend(cpp_argument(argument) for argument in arguments) |
| 314 | 314 |
| 315 if 'ImplementedInPrivateScript' in method.extended_attributes: | 315 if 'ImplementedInPrivateScript' in method.extended_attributes: |
| 316 if method.idl_type.name != 'void': | 316 if method.idl_type.name != 'void': |
| 317 cpp_arguments.append('&result') | 317 cpp_arguments.append('&result') |
| 318 elif ('RaisesException' in method.extended_attributes or | 318 elif ('RaisesException' in method.extended_attributes or |
| 319 (method.is_constructor and | 319 (method.is_constructor and |
| 320 has_extended_attribute_value(interface, 'RaisesException', 'Constructor
'))): | 320 has_extended_attribute_value(interface, 'RaisesException', 'Construct
or'))): |
| 321 cpp_arguments.append('exceptionState') | 321 cpp_arguments.append('exceptionState') |
| 322 | 322 |
| 323 # If a method returns an IDL dictionary or union type, the return value is | 323 # If a method returns an IDL dictionary or union type, the return value is |
| 324 # passed as an argument to impl classes. | 324 # passed as an argument to impl classes. |
| 325 idl_type = method.idl_type | 325 idl_type = method.idl_type |
| 326 if idl_type and idl_type.use_output_parameter_for_result: | 326 if idl_type and idl_type.use_output_parameter_for_result: |
| 327 cpp_arguments.append('result') | 327 cpp_arguments.append('result') |
| 328 | 328 |
| 329 if method.name == 'Constructor': | 329 if method.name == 'Constructor': |
| 330 base_name = 'create' | 330 base_name = 'create' |
| 331 elif method.name == 'NamedConstructor': | 331 elif method.name == 'NamedConstructor': |
| 332 base_name = 'createForJSConstructor' | 332 base_name = 'createForJSConstructor' |
| 333 elif 'ImplementedInPrivateScript' in method.extended_attributes: | 333 elif 'ImplementedInPrivateScript' in method.extended_attributes: |
| 334 base_name = '%sMethod' % method.name | 334 base_name = '%sMethod' % method.name |
| 335 else: | 335 else: |
| 336 base_name = v8_utilities.cpp_name(method) | 336 base_name = v8_utilities.cpp_name(method) |
| 337 | 337 |
| 338 cpp_method_name = v8_utilities.scoped_name(interface, method, base_name) | 338 cpp_method_name = v8_utilities.scoped_name(interface, method, base_name) |
| 339 return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments)) | 339 return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments)) |
| 340 | 340 |
| 341 | 341 |
| 342 def v8_set_return_value(interface_name, method, cpp_value, for_main_world=False)
: | 342 def v8_set_return_value(interface_name, method, cpp_value, for_main_world=False)
: |
| 343 idl_type = method.idl_type | 343 idl_type = method.idl_type |
| 344 extended_attributes = method.extended_attributes | 344 extended_attributes = method.extended_attributes |
| 345 if not idl_type or idl_type.name == 'void': | 345 if not idl_type or idl_type.name == 'void': |
| 346 # Constructors and void methods don't have a return type | 346 # Constructors and void methods don't have a return type |
| 347 return None | 347 return None |
| 348 | 348 |
| 349 if ('ImplementedInPrivateScript' in extended_attributes and | 349 if ('ImplementedInPrivateScript' in extended_attributes and |
| 350 not idl_type.is_wrapper_type and | 350 not idl_type.is_wrapper_type and |
| 351 not idl_type.is_basic_type): | 351 not idl_type.is_basic_type): |
| 352 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') | 352 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') |
| 353 | 353 |
| 354 release = False | 354 release = False |
| 355 # [CallWith=ScriptState], [RaisesException] | 355 # [CallWith=ScriptState], [RaisesException] |
| 356 if use_local_result(method): | 356 if use_local_result(method): |
| 357 if idl_type.is_explicit_nullable: | 357 if idl_type.is_explicit_nullable: |
| 358 # result is of type Nullable<T> | 358 # result is of type Nullable<T> |
| 359 cpp_value = 'result.get()' | 359 cpp_value = 'result.get()' |
| 360 else: | 360 else: |
| 361 cpp_value = 'result' | 361 cpp_value = 'result' |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]'
% index, | 398 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]'
% index, |
| 399 name, index=index, declare_varia
ble=False, | 399 name, index=index, declare_varia
ble=False, |
| 400 use_exception_state=method.retur
ns_promise, | 400 use_exception_state=method.retur
ns_promise, |
| 401 restricted_float=restricted_floa
t) | 401 restricted_float=restricted_floa
t) |
| 402 | 402 |
| 403 | 403 |
| 404 ################################################################################ | 404 ################################################################################ |
| 405 # Auxiliary functions | 405 # Auxiliary functions |
| 406 ################################################################################ | 406 ################################################################################ |
| 407 | 407 |
| 408 # [NotEnumerable] | 408 # [NotEnumerable], [Unforgeable] |
| 409 def property_attributes(interface, method): | 409 def property_attributes(interface, method): |
| 410 extended_attributes = method.extended_attributes | 410 extended_attributes = method.extended_attributes |
| 411 property_attributes_list = [] | 411 property_attributes_list = [] |
| 412 if 'NotEnumerable' in extended_attributes: | 412 if 'NotEnumerable' in extended_attributes: |
| 413 property_attributes_list.append('v8::DontEnum') | 413 property_attributes_list.append('v8::DontEnum') |
| 414 if is_unforgeable(interface, method): | 414 if is_unforgeable(interface, method): |
| 415 property_attributes_list.append('v8::ReadOnly') | 415 property_attributes_list.append('v8::ReadOnly') |
| 416 if property_attributes_list: | 416 property_attributes_list.append('v8::DontDelete') |
| 417 property_attributes_list.insert(0, 'v8::DontDelete') | |
| 418 return property_attributes_list | 417 return property_attributes_list |
| 419 | 418 |
| 420 | 419 |
| 421 def argument_set_default_value(argument): | 420 def argument_set_default_value(argument): |
| 422 idl_type = argument.idl_type | 421 idl_type = argument.idl_type |
| 423 default_value = argument.default_value | 422 default_value = argument.default_value |
| 424 if not default_value: | 423 if not default_value: |
| 425 return None | 424 return None |
| 426 if idl_type.is_dictionary: | 425 if idl_type.is_dictionary: |
| 427 if not argument.default_value.is_null: | 426 if not argument.default_value.is_null: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 return method.idl_type and method.idl_type.name == 'Promise' | 466 return method.idl_type and method.idl_type.name == 'Promise' |
| 468 | 467 |
| 469 IdlOperation.returns_promise = property(method_returns_promise) | 468 IdlOperation.returns_promise = property(method_returns_promise) |
| 470 | 469 |
| 471 | 470 |
| 472 def argument_conversion_needs_exception_state(method, argument): | 471 def argument_conversion_needs_exception_state(method, argument): |
| 473 idl_type = argument.idl_type | 472 idl_type = argument.idl_type |
| 474 return (idl_type.v8_conversion_needs_exception_state or | 473 return (idl_type.v8_conversion_needs_exception_state or |
| 475 argument.is_variadic or | 474 argument.is_variadic or |
| 476 (method.returns_promise and idl_type.is_string_type)) | 475 (method.returns_promise and idl_type.is_string_type)) |
| OLD | NEW |