| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 # Methods with any of these require custom method registration code in the | 44 # Methods with any of these require custom method registration code in the |
| 45 # interface's configure*Template() function. | 45 # interface's configure*Template() function. |
| 46 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES = frozenset([ | 46 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES = frozenset([ |
| 47 'DoNotCheckSecurity', | 47 'DoNotCheckSecurity', |
| 48 'DoNotCheckSignature', | 48 'DoNotCheckSignature', |
| 49 'NotEnumerable', | 49 'NotEnumerable', |
| 50 'Unforgeable', | 50 'Unforgeable', |
| 51 ]) | 51 ]) |
| 52 | 52 |
| 53 | 53 |
| 54 def argument_needs_try_catch(argument): | 54 def argument_needs_try_catch(argument, return_promise): |
| 55 idl_type = argument.idl_type | 55 idl_type = argument.idl_type |
| 56 base_type = not idl_type.native_array_element_type and idl_type.base_type | 56 base_type = not idl_type.native_array_element_type and idl_type.base_type |
| 57 | 57 |
| 58 return not ( | 58 return not ( |
| 59 # These cases are handled by separate code paths in the | 59 # These cases are handled by separate code paths in the |
| 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/core/v8/V8BindingMacros.h don't | 65 # TOSTRING_* macros except for _PROMISE variants in |
| 66 # use a v8::TryCatch. | 66 # Source/bindings/core/v8/V8BindingMacros.h don't use a v8::TryCatch. |
| 67 (base_type == 'DOMString' and not argument.is_variadic)) | 67 (base_type == 'DOMString' and not argument.is_variadic and |
| 68 not return_promise)) |
| 68 | 69 |
| 69 | 70 |
| 70 def use_local_result(method): | 71 def use_local_result(method): |
| 71 extended_attributes = method.extended_attributes | 72 extended_attributes = method.extended_attributes |
| 72 idl_type = method.idl_type | 73 idl_type = method.idl_type |
| 73 return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or | 74 return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or |
| 74 'ImplementedInPrivateScript' in extended_attributes or | 75 'ImplementedInPrivateScript' in extended_attributes or |
| 75 'RaisesException' in extended_attributes or | 76 'RaisesException' in extended_attributes or |
| 76 idl_type.is_union_type or | 77 idl_type.is_union_type or |
| 77 idl_type.is_explicit_nullable) | 78 idl_type.is_explicit_nullable) |
| 78 | 79 |
| 79 | 80 |
| 80 def method_context(interface, method): | 81 def method_context(interface, method): |
| 81 arguments = method.arguments | 82 arguments = method.arguments |
| 82 extended_attributes = method.extended_attributes | 83 extended_attributes = method.extended_attributes |
| 83 idl_type = method.idl_type | 84 idl_type = method.idl_type |
| 84 is_static = method.is_static | 85 is_static = method.is_static |
| 85 name = method.name | 86 name = method.name |
| 87 return_promise = idl_type.name == 'Promise' |
| 86 | 88 |
| 87 idl_type.add_includes_for_type() | 89 idl_type.add_includes_for_type() |
| 88 this_cpp_value = cpp_value(interface, method, len(arguments)) | 90 this_cpp_value = cpp_value(interface, method, len(arguments)) |
| 89 | 91 |
| 90 def function_template(): | 92 def function_template(): |
| 91 if is_static: | 93 if is_static: |
| 92 return 'functionTemplate' | 94 return 'functionTemplate' |
| 93 if 'Unforgeable' in extended_attributes: | 95 if 'Unforgeable' in extended_attributes: |
| 94 return 'instanceTemplate' | 96 return 'instanceTemplate' |
| 95 return 'prototypeTemplate' | 97 return 'prototypeTemplate' |
| (...skipping 19 matching lines...) Expand all Loading... |
| 115 includes.add('bindings/core/v8/BindingSecurity.h') | 117 includes.add('bindings/core/v8/BindingSecurity.h') |
| 116 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute
s | 118 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute
s |
| 117 if is_custom_element_callbacks: | 119 if is_custom_element_callbacks: |
| 118 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') | 120 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') |
| 119 | 121 |
| 120 is_check_security_for_frame = ( | 122 is_check_security_for_frame = ( |
| 121 'CheckSecurity' in interface.extended_attributes and | 123 'CheckSecurity' in interface.extended_attributes and |
| 122 'DoNotCheckSecurity' not in extended_attributes) | 124 'DoNotCheckSecurity' not in extended_attributes) |
| 123 is_raises_exception = 'RaisesException' in extended_attributes | 125 is_raises_exception = 'RaisesException' in extended_attributes |
| 124 | 126 |
| 125 arguments_need_try_catch = any(argument_needs_try_catch(argument) | 127 arguments_need_try_catch = ( |
| 126 for argument in arguments) | 128 any(argument_needs_try_catch(argument, return_promise) |
| 129 for argument in arguments)) |
| 127 | 130 |
| 128 return { | 131 return { |
| 129 'activity_logging_world_list': v8_utilities.activity_logging_world_list(
method), # [ActivityLogging] | 132 'activity_logging_world_list': v8_utilities.activity_logging_world_list(
method), # [ActivityLogging] |
| 130 'arguments': [argument_context(interface, method, argument, index) | 133 'arguments': [argument_context(interface, method, argument, index) |
| 131 for index, argument in enumerate(arguments)], | 134 for index, argument in enumerate(arguments)], |
| 132 'argument_declarations_for_private_script': | 135 'argument_declarations_for_private_script': |
| 133 argument_declarations_for_private_script(interface, method), | 136 argument_declarations_for_private_script(interface, method), |
| 134 'arguments_need_try_catch': arguments_need_try_catch, | 137 'arguments_need_try_catch': arguments_need_try_catch, |
| 135 'conditional_string': v8_utilities.conditional_string(method), | 138 'conditional_string': v8_utilities.conditional_string(method), |
| 136 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type) | 139 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), | 197 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), |
| 195 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended
_attributes else [''], # [PerWorldBindings], | 198 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended
_attributes else [''], # [PerWorldBindings], |
| 196 } | 199 } |
| 197 | 200 |
| 198 | 201 |
| 199 def argument_context(interface, method, argument, index): | 202 def argument_context(interface, method, argument, index): |
| 200 extended_attributes = argument.extended_attributes | 203 extended_attributes = argument.extended_attributes |
| 201 idl_type = argument.idl_type | 204 idl_type = argument.idl_type |
| 202 this_cpp_value = cpp_value(interface, method, index) | 205 this_cpp_value = cpp_value(interface, method, index) |
| 203 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type | 206 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type |
| 207 return_promise = (method.idl_type.name == 'Promise' if method.idl_type |
| 208 else False) |
| 204 | 209 |
| 205 if ('ImplementedInPrivateScript' in extended_attributes and | 210 if ('ImplementedInPrivateScript' in extended_attributes and |
| 206 not idl_type.is_wrapper_type and | 211 not idl_type.is_wrapper_type and |
| 207 not idl_type.is_basic_type): | 212 not idl_type.is_basic_type): |
| 208 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') | 213 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') |
| 209 | 214 |
| 210 return { | 215 return { |
| 211 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut
es, | 216 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut
es, |
| 212 raw_type=True, | 217 raw_type=True, |
| 213 used_as_variadic_argument=argument.is
_variadic), | 218 used_as_variadic_argument=argument.is
_variadic), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 235 'is_nullable': idl_type.is_nullable, | 240 'is_nullable': idl_type.is_nullable, |
| 236 'is_optional': argument.is_optional, | 241 'is_optional': argument.is_optional, |
| 237 'is_variadic_wrapper_type': is_variadic_wrapper_type, | 242 'is_variadic_wrapper_type': is_variadic_wrapper_type, |
| 238 'is_wrapper_type': idl_type.is_wrapper_type, | 243 'is_wrapper_type': idl_type.is_wrapper_type, |
| 239 'name': argument.name, | 244 'name': argument.name, |
| 240 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( | 245 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( |
| 241 argument.name, isolate='scriptState->isolate()', | 246 argument.name, isolate='scriptState->isolate()', |
| 242 creation_context='scriptState->context()->Global()'), | 247 creation_context='scriptState->context()->Global()'), |
| 243 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), | 248 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), |
| 244 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), | 249 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), |
| 245 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind
ex), | 250 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind
ex, return_promise=return_promise), |
| 246 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc
_type), | 251 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc
_type), |
| 247 } | 252 } |
| 248 | 253 |
| 249 | 254 |
| 250 def argument_declarations_for_private_script(interface, method): | 255 def argument_declarations_for_private_script(interface, method): |
| 251 argument_declarations = ['LocalFrame* frame'] | 256 argument_declarations = ['LocalFrame* frame'] |
| 252 argument_declarations.append('%s* holderImpl' % interface.name) | 257 argument_declarations.append('%s* holderImpl' % interface.name) |
| 253 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args( | 258 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args( |
| 254 used_as_rvalue_type=True), argument.name) for argument in method.argumen
ts]) | 259 used_as_rvalue_type=True), argument.name) for argument in method.argumen
ts]) |
| 255 if method.idl_type.name != 'void': | 260 if method.idl_type.name != 'void': |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 # result is of type Nullable<T> | 344 # result is of type Nullable<T> |
| 340 cpp_value = 'result.get()' | 345 cpp_value = 'result.get()' |
| 341 else: | 346 else: |
| 342 cpp_value = 'result' | 347 cpp_value = 'result' |
| 343 release = idl_type.release | 348 release = idl_type.release |
| 344 | 349 |
| 345 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else
'' | 350 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else
'' |
| 346 return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_w
rappable=script_wrappable, release=release, for_main_world=for_main_world) | 351 return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_w
rappable=script_wrappable, release=release, for_main_world=for_main_world) |
| 347 | 352 |
| 348 | 353 |
| 349 def v8_value_to_local_cpp_variadic_value(argument, index): | 354 def v8_value_to_local_cpp_variadic_value(argument, index, return_promise): |
| 350 assert argument.is_variadic | 355 assert argument.is_variadic |
| 351 idl_type = argument.idl_type | 356 idl_type = argument.idl_type |
| 352 | 357 |
| 353 macro = 'TONATIVE_VOID_INTERNAL' | 358 suffix = '' |
| 359 |
| 360 macro = 'TONATIVE_VOID' |
| 354 macro_args = [ | 361 macro_args = [ |
| 355 argument.name, | 362 argument.name, |
| 356 'toNativeArguments<%s>(info, %s)' % (idl_type.cpp_type, index), | 363 'toNativeArguments<%s>(info, %s)' % (idl_type.cpp_type, index), |
| 357 ] | 364 ] |
| 358 | 365 |
| 359 return '%s(%s)' % (macro, ', '.join(macro_args)) | 366 if return_promise: |
| 367 suffix += '_PROMISE' |
| 368 macro_args.append('info') |
| 369 |
| 370 suffix += '_INTERNAL' |
| 371 |
| 372 return '%s%s(%s)' % (macro, suffix, ', '.join(macro_args)) |
| 360 | 373 |
| 361 | 374 |
| 362 def v8_value_to_local_cpp_value(argument, index): | 375 def v8_value_to_local_cpp_value(argument, index, return_promise=False): |
| 363 extended_attributes = argument.extended_attributes | 376 extended_attributes = argument.extended_attributes |
| 364 idl_type = argument.idl_type | 377 idl_type = argument.idl_type |
| 365 name = argument.name | 378 name = argument.name |
| 366 if argument.is_variadic: | 379 if argument.is_variadic: |
| 367 return v8_value_to_local_cpp_variadic_value(argument, index) | 380 return v8_value_to_local_cpp_variadic_value(argument, index, return_prom
ise) |
| 368 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]'
% index, | 381 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]'
% index, |
| 369 name, index=index, declare_varia
ble=False) | 382 name, index=index, declare_varia
ble=False, return_promise=return_promise) |
| 370 | 383 |
| 371 | 384 |
| 372 ################################################################################ | 385 ################################################################################ |
| 373 # Auxiliary functions | 386 # Auxiliary functions |
| 374 ################################################################################ | 387 ################################################################################ |
| 375 | 388 |
| 376 # [NotEnumerable] | 389 # [NotEnumerable] |
| 377 def property_attributes(method): | 390 def property_attributes(method): |
| 378 extended_attributes = method.extended_attributes | 391 extended_attributes = method.extended_attributes |
| 379 property_attributes_list = [] | 392 property_attributes_list = [] |
| (...skipping 14 matching lines...) Expand all Loading... |
| 394 | 407 |
| 395 | 408 |
| 396 def argument_default_cpp_value(argument): | 409 def argument_default_cpp_value(argument): |
| 397 if not argument.default_value: | 410 if not argument.default_value: |
| 398 return None | 411 return None |
| 399 return argument.idl_type.literal_cpp_value(argument.default_value) | 412 return argument.idl_type.literal_cpp_value(argument.default_value) |
| 400 | 413 |
| 401 IdlType.union_arguments = property(lambda self: None) | 414 IdlType.union_arguments = property(lambda self: None) |
| 402 IdlUnionType.union_arguments = property(union_arguments) | 415 IdlUnionType.union_arguments = property(union_arguments) |
| 403 IdlArgument.default_cpp_value = property(argument_default_cpp_value) | 416 IdlArgument.default_cpp_value = property(argument_default_cpp_value) |
| OLD | NEW |