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, 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 except for _ASYNC 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 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 return_promise = 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 Loading... |
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, return_pro
mise) |
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 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), | 195 '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], | 196 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended
_attributes else [''], # [PerWorldBindings], |
196 } | 197 } |
197 | 198 |
198 | 199 |
199 def argument_context(interface, method, argument, index): | 200 def argument_context(interface, method, argument, index): |
200 extended_attributes = argument.extended_attributes | 201 extended_attributes = argument.extended_attributes |
201 idl_type = argument.idl_type | 202 idl_type = argument.idl_type |
202 this_cpp_value = cpp_value(interface, method, index) | 203 this_cpp_value = cpp_value(interface, method, index) |
203 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type | 204 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type |
| 205 return_promise = (method.idl_type.name == 'Promise' if method.idl_type |
| 206 else False) |
204 | 207 |
205 if ('ImplementedInPrivateScript' in extended_attributes and | 208 if ('ImplementedInPrivateScript' in extended_attributes and |
206 not idl_type.is_wrapper_type and | 209 not idl_type.is_wrapper_type and |
207 not idl_type.is_basic_type): | 210 not idl_type.is_basic_type): |
208 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') | 211 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') |
209 | 212 |
210 return { | 213 return { |
211 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut
es, | 214 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut
es, |
212 raw_type=True, | 215 raw_type=True, |
213 used_as_variadic_argument=argument.is
_variadic), | 216 used_as_variadic_argument=argument.is
_variadic), |
(...skipping 21 matching lines...) Expand all Loading... |
235 'is_nullable': idl_type.is_nullable, | 238 'is_nullable': idl_type.is_nullable, |
236 'is_optional': argument.is_optional, | 239 'is_optional': argument.is_optional, |
237 'is_variadic_wrapper_type': is_variadic_wrapper_type, | 240 'is_variadic_wrapper_type': is_variadic_wrapper_type, |
238 'is_wrapper_type': idl_type.is_wrapper_type, | 241 'is_wrapper_type': idl_type.is_wrapper_type, |
239 'name': argument.name, | 242 'name': argument.name, |
240 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( | 243 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( |
241 argument.name, isolate='scriptState->isolate()', | 244 argument.name, isolate='scriptState->isolate()', |
242 creation_context='scriptState->context()->Global()'), | 245 creation_context='scriptState->context()->Global()'), |
243 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), | 246 '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), | 247 '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), | 248 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind
ex, async=return_promise), |
246 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc
_type), | 249 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc
_type), |
247 } | 250 } |
248 | 251 |
249 | 252 |
250 def argument_declarations_for_private_script(interface, method): | 253 def argument_declarations_for_private_script(interface, method): |
251 argument_declarations = ['LocalFrame* frame'] | 254 argument_declarations = ['LocalFrame* frame'] |
252 argument_declarations.append('%s* holderImpl' % interface.name) | 255 argument_declarations.append('%s* holderImpl' % interface.name) |
253 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args( | 256 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]) | 257 used_as_rvalue_type=True), argument.name) for argument in method.argumen
ts]) |
255 if method.idl_type.name != 'void': | 258 if method.idl_type.name != 'void': |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 # result is of type Nullable<T> | 341 # result is of type Nullable<T> |
339 cpp_value = 'result.get()' | 342 cpp_value = 'result.get()' |
340 else: | 343 else: |
341 cpp_value = 'result' | 344 cpp_value = 'result' |
342 release = idl_type.release | 345 release = idl_type.release |
343 | 346 |
344 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else
'' | 347 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) | 348 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 | 349 |
347 | 350 |
348 def v8_value_to_local_cpp_variadic_value(argument, index): | 351 def v8_value_to_local_cpp_variadic_value(argument, index, async): |
349 assert argument.is_variadic | 352 assert argument.is_variadic |
350 idl_type = argument.idl_type | 353 idl_type = argument.idl_type |
351 | 354 |
352 macro = 'TONATIVE_VOID_INTERNAL' | 355 suffix = '' |
| 356 |
| 357 macro = 'TONATIVE_VOID' |
353 macro_args = [ | 358 macro_args = [ |
354 argument.name, | 359 argument.name, |
355 'toNativeArguments<%s>(info, %s)' % (idl_type.cpp_type, index), | 360 'toNativeArguments<%s>(info, %s)' % (idl_type.cpp_type, index), |
356 ] | 361 ] |
357 | 362 |
358 return '%s(%s)' % (macro, ', '.join(macro_args)) | 363 if async: |
| 364 suffix += '_ASYNC' |
| 365 macro_args.append('info') |
| 366 |
| 367 suffix += '_INTERNAL' |
| 368 |
| 369 return '%s%s(%s)' % (macro, suffix, ', '.join(macro_args)) |
359 | 370 |
360 | 371 |
361 def v8_value_to_local_cpp_value(argument, index): | 372 def v8_value_to_local_cpp_value(argument, index, async=False): |
362 extended_attributes = argument.extended_attributes | 373 extended_attributes = argument.extended_attributes |
363 idl_type = argument.idl_type | 374 idl_type = argument.idl_type |
364 name = argument.name | 375 name = argument.name |
365 if argument.is_variadic: | 376 if argument.is_variadic: |
366 return v8_value_to_local_cpp_variadic_value(argument, index) | 377 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, | 378 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]'
% index, |
368 name, index=index, declare_varia
ble=False) | 379 name, index=index, declare_varia
ble=False, async=async) |
369 | 380 |
370 | 381 |
371 ################################################################################ | 382 ################################################################################ |
372 # Auxiliary functions | 383 # Auxiliary functions |
373 ################################################################################ | 384 ################################################################################ |
374 | 385 |
375 # [NotEnumerable] | 386 # [NotEnumerable] |
376 def property_attributes(method): | 387 def property_attributes(method): |
377 extended_attributes = method.extended_attributes | 388 extended_attributes = method.extended_attributes |
378 property_attributes_list = [] | 389 property_attributes_list = [] |
(...skipping 14 matching lines...) Expand all Loading... |
393 | 404 |
394 | 405 |
395 def argument_default_cpp_value(argument): | 406 def argument_default_cpp_value(argument): |
396 if not argument.default_value: | 407 if not argument.default_value: |
397 return None | 408 return None |
398 return argument.idl_type.literal_cpp_value(argument.default_value) | 409 return argument.idl_type.literal_cpp_value(argument.default_value) |
399 | 410 |
400 IdlType.union_arguments = property(lambda self: None) | 411 IdlType.union_arguments = property(lambda self: None) |
401 IdlUnionType.union_arguments = property(union_arguments) | 412 IdlUnionType.union_arguments = property(union_arguments) |
402 IdlArgument.default_cpp_value = property(argument_default_cpp_value) | 413 IdlArgument.default_cpp_value = property(argument_default_cpp_value) |
OLD | NEW |