Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: Source/bindings/scripts/v8_methods.py

Issue 232563003: API functions returning Promises should not throw exceptions. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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, async):
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 in Source/bindings/core/v8/V8BindingMacros.h don't
66 # use a v8::TryCatch. 66 # use a v8::TryCatch.
bashi 2014/07/31 02:02:24 Could you update the comment to describe why we ne
yhirano 2014/07/31 03:38:03 Done.
67 (base_type == 'DOMString' and not argument.is_variadic)) 67 (base_type == 'DOMString' and not argument.is_variadic and not async))
68 68
69 69
70 def use_local_result(method): 70 def use_local_result(method):
71 extended_attributes = method.extended_attributes 71 extended_attributes = method.extended_attributes
72 idl_type = method.idl_type 72 idl_type = method.idl_type
73 return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or 73 return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or
74 'ImplementedInPrivateScript' in extended_attributes or 74 'ImplementedInPrivateScript' in extended_attributes or
75 'RaisesException' in extended_attributes or 75 'RaisesException' in extended_attributes or
76 idl_type.is_union_type or 76 idl_type.is_union_type or
77 idl_type.is_explicit_nullable) 77 idl_type.is_explicit_nullable)
78 78
79 79
80 def method_context(interface, method): 80 def method_context(interface, method):
81 arguments = method.arguments 81 arguments = method.arguments
82 extended_attributes = method.extended_attributes 82 extended_attributes = method.extended_attributes
83 idl_type = method.idl_type 83 idl_type = method.idl_type
84 is_static = method.is_static 84 is_static = method.is_static
85 name = method.name 85 name = method.name
86 async = idl_type.name == 'Promise'
86 87
87 idl_type.add_includes_for_type() 88 idl_type.add_includes_for_type()
88 this_cpp_value = cpp_value(interface, method, len(arguments)) 89 this_cpp_value = cpp_value(interface, method, len(arguments))
89 90
90 def function_template(): 91 def function_template():
91 if is_static: 92 if is_static:
92 return 'functionTemplate' 93 return 'functionTemplate'
93 if 'Unforgeable' in extended_attributes: 94 if 'Unforgeable' in extended_attributes:
94 return 'instanceTemplate' 95 return 'instanceTemplate'
95 return 'prototypeTemplate' 96 return 'prototypeTemplate'
(...skipping 19 matching lines...) Expand all
115 includes.add('bindings/core/v8/BindingSecurity.h') 116 includes.add('bindings/core/v8/BindingSecurity.h')
116 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute s 117 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute s
117 if is_custom_element_callbacks: 118 if is_custom_element_callbacks:
118 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') 119 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h')
119 120
120 is_check_security_for_frame = ( 121 is_check_security_for_frame = (
121 'CheckSecurity' in interface.extended_attributes and 122 'CheckSecurity' in interface.extended_attributes and
122 'DoNotCheckSecurity' not in extended_attributes) 123 'DoNotCheckSecurity' not in extended_attributes)
123 is_raises_exception = 'RaisesException' in extended_attributes 124 is_raises_exception = 'RaisesException' in extended_attributes
124 125
125 arguments_need_try_catch = any(argument_needs_try_catch(argument) 126 arguments_need_try_catch = any(argument_needs_try_catch(argument, async)
126 for argument in arguments) 127 for argument in arguments)
127 128
128 return { 129 return {
129 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging] 130 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging]
130 'arguments': [argument_context(interface, method, argument, index) 131 'arguments': [argument_context(interface, method, argument, index)
131 for index, argument in enumerate(arguments)], 132 for index, argument in enumerate(arguments)],
132 'argument_declarations_for_private_script': 133 'argument_declarations_for_private_script':
133 argument_declarations_for_private_script(interface, method), 134 argument_declarations_for_private_script(interface, method),
134 'arguments_need_try_catch': arguments_need_try_catch, 135 'arguments_need_try_catch': arguments_need_try_catch,
135 'conditional_string': v8_utilities.conditional_string(method), 136 'conditional_string': v8_utilities.conditional_string(method),
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 'is_optional': argument.is_optional, 237 'is_optional': argument.is_optional,
237 'is_variadic_wrapper_type': is_variadic_wrapper_type, 238 'is_variadic_wrapper_type': is_variadic_wrapper_type,
238 'is_wrapper_type': idl_type.is_wrapper_type, 239 'is_wrapper_type': idl_type.is_wrapper_type,
239 'name': argument.name, 240 'name': argument.name,
240 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( 241 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value(
241 argument.name, isolate='scriptState->isolate()', 242 argument.name, isolate='scriptState->isolate()',
242 creation_context='scriptState->context()->Global()'), 243 creation_context='scriptState->context()->Global()'),
243 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value), 244 '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), 245 '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), 246 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind ex),
247 'v8_value_to_local_cpp_value_async': v8_value_to_local_cpp_value(argumen t, index, async=True),
246 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc _type), 248 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc _type),
247 } 249 }
248 250
249 251
250 def argument_declarations_for_private_script(interface, method): 252 def argument_declarations_for_private_script(interface, method):
251 argument_declarations = ['LocalFrame* frame'] 253 argument_declarations = ['LocalFrame* frame']
252 argument_declarations.append('%s* holderImpl' % interface.name) 254 argument_declarations.append('%s* holderImpl' % interface.name)
253 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args( 255 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args(
254 used_as_argument=True), argument.name) for argument in method.arguments] ) 256 used_as_argument=True), argument.name) for argument in method.arguments] )
255 if method.idl_type.name != 'void': 257 if method.idl_type.name != 'void':
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 # result is of type Nullable<T> 340 # result is of type Nullable<T>
339 cpp_value = 'result.get()' 341 cpp_value = 'result.get()'
340 else: 342 else:
341 cpp_value = 'result' 343 cpp_value = 'result'
342 release = idl_type.release 344 release = idl_type.release
343 345
344 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else '' 346 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else ''
345 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 return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_w rappable=script_wrappable, release=release, for_main_world=for_main_world)
346 348
347 349
348 def v8_value_to_local_cpp_variadic_value(argument, index): 350 def v8_value_to_local_cpp_variadic_value(argument, index, async):
349 assert argument.is_variadic 351 assert argument.is_variadic
350 idl_type = argument.idl_type 352 idl_type = argument.idl_type
351 353
352 macro = 'TONATIVE_VOID_INTERNAL' 354 suffix = ''
355
356 macro = 'TONATIVE_VOID'
353 macro_args = [ 357 macro_args = [
354 argument.name, 358 argument.name,
355 'toNativeArguments<%s>(info, %s)' % (idl_type.cpp_type, index), 359 'toNativeArguments<%s>(info, %s)' % (idl_type.cpp_type, index),
356 ] 360 ]
357 361
358 return '%s(%s)' % (macro, ', '.join(macro_args)) 362 if async:
363 suffix += '_ASYNC'
364 macro_args.append('info')
365
366 suffix += '_INTERNAL'
367
368 return '%s%s(%s)' % (macro, suffix, ', '.join(macro_args))
359 369
360 370
361 def v8_value_to_local_cpp_value(argument, index): 371 def v8_value_to_local_cpp_value(argument, index, async=False):
362 extended_attributes = argument.extended_attributes 372 extended_attributes = argument.extended_attributes
363 idl_type = argument.idl_type 373 idl_type = argument.idl_type
364 name = argument.name 374 name = argument.name
365 if argument.is_variadic: 375 if argument.is_variadic:
366 return v8_value_to_local_cpp_variadic_value(argument, index) 376 return v8_value_to_local_cpp_variadic_value(argument, index, async)
367 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]' % index, 377 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]' % index,
368 name, index=index, declare_varia ble=False) 378 name, index=index, declare_varia ble=False, async=async)
369 379
370 380
371 ################################################################################ 381 ################################################################################
372 # Auxiliary functions 382 # Auxiliary functions
373 ################################################################################ 383 ################################################################################
374 384
375 # [NotEnumerable] 385 # [NotEnumerable]
376 def property_attributes(method): 386 def property_attributes(method):
377 extended_attributes = method.extended_attributes 387 extended_attributes = method.extended_attributes
378 property_attributes_list = [] 388 property_attributes_list = []
(...skipping 14 matching lines...) Expand all
393 403
394 404
395 def argument_default_cpp_value(argument): 405 def argument_default_cpp_value(argument):
396 if not argument.default_value: 406 if not argument.default_value:
397 return None 407 return None
398 return argument.idl_type.literal_cpp_value(argument.default_value) 408 return argument.idl_type.literal_cpp_value(argument.default_value)
399 409
400 IdlType.union_arguments = property(lambda self: None) 410 IdlType.union_arguments = property(lambda self: None)
401 IdlUnionType.union_arguments = property(union_arguments) 411 IdlUnionType.union_arguments = property(union_arguments)
402 IdlArgument.default_cpp_value = property(argument_default_cpp_value) 412 IdlArgument.default_cpp_value = property(argument_default_cpp_value)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698