Chromium Code Reviews| 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)) | |
|
Jens Widell
2014/08/11 06:52:00
Very minor nit: indent this line by one space.
yhirano
2014/08/11 07:00:26
Done.
| |
| 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 = any(argument_needs_try_catch(argument, return_pro mise) |
| 126 for argument in arguments) | 128 for argument in arguments) |
| 127 | 129 |
| 128 return { | 130 return { |
| 129 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging] | 131 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging] |
| 130 'arguments': [argument_context(interface, method, argument, index) | 132 'arguments': [argument_context(interface, method, argument, index) |
| 131 for index, argument in enumerate(arguments)], | 133 for index, argument in enumerate(arguments)], |
| 132 'argument_declarations_for_private_script': | 134 'argument_declarations_for_private_script': |
| 133 argument_declarations_for_private_script(interface, method), | 135 argument_declarations_for_private_script(interface, method), |
| 134 'arguments_need_try_catch': arguments_need_try_catch, | 136 'arguments_need_try_catch': arguments_need_try_catch, |
| 135 'conditional_string': v8_utilities.conditional_string(method), | 137 'conditional_string': v8_utilities.conditional_string(method), |
| (...skipping 58 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), | 196 '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], | 197 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings], |
| 196 } | 198 } |
| 197 | 199 |
| 198 | 200 |
| 199 def argument_context(interface, method, argument, index): | 201 def argument_context(interface, method, argument, index): |
| 200 extended_attributes = argument.extended_attributes | 202 extended_attributes = argument.extended_attributes |
| 201 idl_type = argument.idl_type | 203 idl_type = argument.idl_type |
| 202 this_cpp_value = cpp_value(interface, method, index) | 204 this_cpp_value = cpp_value(interface, method, index) |
| 203 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type | 205 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type |
| 206 return_promise = (method.idl_type.name == 'Promise' if method.idl_type | |
| 207 else False) | |
| 204 | 208 |
| 205 if ('ImplementedInPrivateScript' in extended_attributes and | 209 if ('ImplementedInPrivateScript' in extended_attributes and |
| 206 not idl_type.is_wrapper_type and | 210 not idl_type.is_wrapper_type and |
| 207 not idl_type.is_basic_type): | 211 not idl_type.is_basic_type): |
| 208 raise Exception('Private scripts supports only primitive types and DOM w rappers.') | 212 raise Exception('Private scripts supports only primitive types and DOM w rappers.') |
| 209 | 213 |
| 210 return { | 214 return { |
| 211 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut es, | 215 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut es, |
| 212 raw_type=True, | 216 raw_type=True, |
| 213 used_as_variadic_argument=argument.is _variadic), | 217 used_as_variadic_argument=argument.is _variadic), |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 235 'is_nullable': idl_type.is_nullable, | 239 'is_nullable': idl_type.is_nullable, |
| 236 'is_optional': argument.is_optional, | 240 'is_optional': argument.is_optional, |
| 237 'is_variadic_wrapper_type': is_variadic_wrapper_type, | 241 'is_variadic_wrapper_type': is_variadic_wrapper_type, |
| 238 'is_wrapper_type': idl_type.is_wrapper_type, | 242 'is_wrapper_type': idl_type.is_wrapper_type, |
| 239 'name': argument.name, | 243 'name': argument.name, |
| 240 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( | 244 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( |
| 241 argument.name, isolate='scriptState->isolate()', | 245 argument.name, isolate='scriptState->isolate()', |
| 242 creation_context='scriptState->context()->Global()'), | 246 creation_context='scriptState->context()->Global()'), |
| 243 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value), | 247 '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), | 248 '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), | 249 '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), | 250 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc _type), |
| 247 } | 251 } |
| 248 | 252 |
| 249 | 253 |
| 250 def argument_declarations_for_private_script(interface, method): | 254 def argument_declarations_for_private_script(interface, method): |
| 251 argument_declarations = ['LocalFrame* frame'] | 255 argument_declarations = ['LocalFrame* frame'] |
| 252 argument_declarations.append('%s* holderImpl' % interface.name) | 256 argument_declarations.append('%s* holderImpl' % interface.name) |
| 253 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args( | 257 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]) | 258 used_as_rvalue_type=True), argument.name) for argument in method.argumen ts]) |
| 255 if method.idl_type.name != 'void': | 259 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> | 343 # result is of type Nullable<T> |
| 340 cpp_value = 'result.get()' | 344 cpp_value = 'result.get()' |
| 341 else: | 345 else: |
| 342 cpp_value = 'result' | 346 cpp_value = 'result' |
| 343 release = idl_type.release | 347 release = idl_type.release |
| 344 | 348 |
| 345 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else '' | 349 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) | 350 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 | 351 |
| 348 | 352 |
| 349 def v8_value_to_local_cpp_variadic_value(argument, index): | 353 def v8_value_to_local_cpp_variadic_value(argument, index, return_promise): |
| 350 assert argument.is_variadic | 354 assert argument.is_variadic |
| 351 idl_type = argument.idl_type | 355 idl_type = argument.idl_type |
| 352 | 356 |
| 353 macro = 'TONATIVE_VOID_INTERNAL' | 357 suffix = '' |
| 358 | |
| 359 macro = 'TONATIVE_VOID' | |
| 354 macro_args = [ | 360 macro_args = [ |
| 355 argument.name, | 361 argument.name, |
| 356 'toNativeArguments<%s>(info, %s)' % (idl_type.cpp_type, index), | 362 'toNativeArguments<%s>(info, %s)' % (idl_type.cpp_type, index), |
| 357 ] | 363 ] |
| 358 | 364 |
| 359 return '%s(%s)' % (macro, ', '.join(macro_args)) | 365 if return_promise: |
| 366 suffix += '_PROMISE' | |
| 367 macro_args.append('info') | |
| 368 | |
| 369 suffix += '_INTERNAL' | |
| 370 | |
| 371 return '%s%s(%s)' % (macro, suffix, ', '.join(macro_args)) | |
| 360 | 372 |
| 361 | 373 |
| 362 def v8_value_to_local_cpp_value(argument, index): | 374 def v8_value_to_local_cpp_value(argument, index, return_promise=False): |
| 363 extended_attributes = argument.extended_attributes | 375 extended_attributes = argument.extended_attributes |
| 364 idl_type = argument.idl_type | 376 idl_type = argument.idl_type |
| 365 name = argument.name | 377 name = argument.name |
| 366 if argument.is_variadic: | 378 if argument.is_variadic: |
| 367 return v8_value_to_local_cpp_variadic_value(argument, index) | 379 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, | 380 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]' % index, |
| 369 name, index=index, declare_varia ble=False) | 381 name, index=index, declare_varia ble=False, return_promise=return_promise) |
| 370 | 382 |
| 371 | 383 |
| 372 ################################################################################ | 384 ################################################################################ |
| 373 # Auxiliary functions | 385 # Auxiliary functions |
| 374 ################################################################################ | 386 ################################################################################ |
| 375 | 387 |
| 376 # [NotEnumerable] | 388 # [NotEnumerable] |
| 377 def property_attributes(method): | 389 def property_attributes(method): |
| 378 extended_attributes = method.extended_attributes | 390 extended_attributes = method.extended_attributes |
| 379 property_attributes_list = [] | 391 property_attributes_list = [] |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 394 | 406 |
| 395 | 407 |
| 396 def argument_default_cpp_value(argument): | 408 def argument_default_cpp_value(argument): |
| 397 if not argument.default_value: | 409 if not argument.default_value: |
| 398 return None | 410 return None |
| 399 return argument.idl_type.literal_cpp_value(argument.default_value) | 411 return argument.idl_type.literal_cpp_value(argument.default_value) |
| 400 | 412 |
| 401 IdlType.union_arguments = property(lambda self: None) | 413 IdlType.union_arguments = property(lambda self: None) |
| 402 IdlUnionType.union_arguments = property(union_arguments) | 414 IdlUnionType.union_arguments = property(union_arguments) |
| 403 IdlArgument.default_cpp_value = property(argument_default_cpp_value) | 415 IdlArgument.default_cpp_value = property(argument_default_cpp_value) |
| OLD | NEW |