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 16 matching lines...) Expand all Loading... |
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 28 |
29 """Generate template values for methods. | 29 """Generate template values for methods. |
30 | 30 |
31 Extends IdlArgument with property |default_cpp_value|. | 31 Extends IdlArgument with property |default_cpp_value|. |
32 Extends IdlTypeBase and IdlUnionType with property |union_arguments|. | 32 Extends IdlTypeBase and IdlUnionType with property |union_arguments|. |
33 | 33 |
34 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | 34 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
35 """ | 35 """ |
36 | 36 |
37 from idl_definitions import IdlArgument | 37 from idl_definitions import IdlArgument, IdlOperation |
38 from idl_types import IdlTypeBase, IdlUnionType, inherits_interface | 38 from idl_types import IdlTypeBase, IdlUnionType, inherits_interface |
39 from v8_globals import includes | 39 from v8_globals import includes |
40 import v8_types | 40 import v8_types |
41 import v8_utilities | 41 import v8_utilities |
42 from v8_utilities import has_extended_attribute_value | 42 from v8_utilities import has_extended_attribute_value |
43 | 43 |
44 | 44 |
45 # Methods with any of these require custom method registration code in the | 45 # Methods with any of these require custom method registration code in the |
46 # interface's configure*Template() function. | 46 # interface's configure*Template() function. |
47 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES = frozenset([ | 47 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES = frozenset([ |
48 'DoNotCheckSecurity', | 48 'DoNotCheckSecurity', |
49 'DoNotCheckSignature', | 49 'DoNotCheckSignature', |
50 'NotEnumerable', | 50 'NotEnumerable', |
51 'Unforgeable', | 51 'Unforgeable', |
52 ]) | 52 ]) |
53 | 53 |
54 | 54 |
55 def argument_needs_try_catch(method, argument): | 55 def argument_needs_try_catch(method, argument): |
56 return_promise = method.idl_type and method.idl_type.name == 'Promise' | |
57 idl_type = argument.idl_type | 56 idl_type = argument.idl_type |
58 base_type = idl_type.base_type | 57 base_type = idl_type.base_type |
59 | 58 |
60 return not( | 59 return not( |
61 # These cases are handled by separate code paths in the | 60 # These cases are handled by separate code paths in the |
62 # generate_argument() macro in Source/bindings/templates/methods.cpp. | 61 # generate_argument() macro in Source/bindings/templates/methods.cpp. |
63 idl_type.is_callback_interface or | 62 idl_type.is_callback_interface or |
64 base_type == 'SerializedScriptValue' or | 63 base_type == 'SerializedScriptValue' or |
65 (argument.is_variadic and idl_type.is_wrapper_type) or | 64 (argument.is_variadic and idl_type.is_wrapper_type) or |
66 # Variadic arguments use toImplArguments() with throws excentions via | 65 # Variadic arguments use toImplArguments() with throws excentions via |
67 # its ExceptionState& argument. | 66 # its ExceptionState& argument. |
68 argument.is_variadic or | 67 argument.is_variadic or |
69 # String and enumeration arguments converted using one of the | 68 # String and enumeration arguments converted using one of the |
70 # TOSTRING_* macros except for _PROMISE variants in | 69 # TOSTRING_* macros except for _PROMISE variants in |
71 # Source/bindings/core/v8/V8BindingMacros.h don't use a v8::TryCatch. | 70 # Source/bindings/core/v8/V8BindingMacros.h don't use a v8::TryCatch. |
72 ((base_type == 'DOMString' or idl_type.is_enum) and | 71 ((base_type == 'DOMString' or idl_type.is_enum) and |
73 not return_promise) or | 72 not method.returns_promise) or |
74 # Conversion that take an ExceptionState& argument throw all their | 73 # Conversion that take an ExceptionState& argument throw all their |
75 # exceptions via it, and doesn't need/use a TryCatch, except if the | 74 # exceptions via it, and doesn't need/use a TryCatch, except if the |
76 # argument has [Clamp], in which case it uses a separate code path in | 75 # argument has [Clamp], in which case it uses a separate code path in |
77 # Source/bindings/templates/methods.cpp, which *does* use a TryCatch. | 76 # Source/bindings/templates/methods.cpp, which *does* use a TryCatch. |
78 argument.v8_conversion_needs_exception_state or | 77 argument_conversion_needs_exception_state(method, argument) or |
79 # A trivial conversion cannot throw exceptions at all, so doesn't need a | 78 # A trivial conversion cannot throw exceptions at all, so doesn't need a |
80 # TryCatch to catch them. | 79 # TryCatch to catch them. |
81 idl_type.v8_conversion_is_trivial) | 80 idl_type.v8_conversion_is_trivial) |
82 | 81 |
83 | 82 |
84 def use_local_result(method): | 83 def use_local_result(method): |
85 extended_attributes = method.extended_attributes | 84 extended_attributes = method.extended_attributes |
86 idl_type = method.idl_type | 85 idl_type = method.idl_type |
87 return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or | 86 return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or |
88 'ImplementedInPrivateScript' in extended_attributes or | 87 'ImplementedInPrivateScript' in extended_attributes or |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 'function_template': function_template(), | 166 'function_template': function_template(), |
168 'has_custom_registration': is_static or | 167 'has_custom_registration': is_static or |
169 v8_utilities.has_extended_attribute( | 168 v8_utilities.has_extended_attribute( |
170 method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES), | 169 method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES), |
171 'has_exception_state': | 170 'has_exception_state': |
172 is_raises_exception or | 171 is_raises_exception or |
173 is_check_security_for_frame or | 172 is_check_security_for_frame or |
174 is_check_security_for_window or | 173 is_check_security_for_window or |
175 any(argument for argument in arguments | 174 any(argument for argument in arguments |
176 if (argument.idl_type.name == 'SerializedScriptValue' or | 175 if (argument.idl_type.name == 'SerializedScriptValue' or |
177 argument.v8_conversion_needs_exception_state)), | 176 argument_conversion_needs_exception_state(method, argument))
), |
178 'idl_type': idl_type.base_type, | 177 'idl_type': idl_type.base_type, |
179 'is_call_with_execution_context': has_extended_attribute_value(method, '
CallWith', 'ExecutionContext'), | 178 'is_call_with_execution_context': has_extended_attribute_value(method, '
CallWith', 'ExecutionContext'), |
180 'is_call_with_script_arguments': is_call_with_script_arguments, | 179 'is_call_with_script_arguments': is_call_with_script_arguments, |
181 'is_call_with_script_state': is_call_with_script_state, | 180 'is_call_with_script_state': is_call_with_script_state, |
182 'is_check_security_for_frame': is_check_security_for_frame, | 181 'is_check_security_for_frame': is_check_security_for_frame, |
183 'is_check_security_for_node': is_check_security_for_node, | 182 'is_check_security_for_node': is_check_security_for_node, |
184 'is_check_security_for_window': is_check_security_for_window, | 183 'is_check_security_for_window': is_check_security_for_window, |
185 'is_custom': 'Custom' in extended_attributes, | 184 'is_custom': 'Custom' in extended_attributes, |
186 'is_custom_element_callbacks': is_custom_element_callbacks, | 185 'is_custom_element_callbacks': is_custom_element_callbacks, |
187 'is_do_not_check_security': is_do_not_check_security, | 186 'is_do_not_check_security': is_do_not_check_security, |
(...skipping 30 matching lines...) Expand all Loading... |
218 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), | 217 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), |
219 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended
_attributes else [''], # [PerWorldBindings], | 218 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended
_attributes else [''], # [PerWorldBindings], |
220 } | 219 } |
221 | 220 |
222 | 221 |
223 def argument_context(interface, method, argument, index): | 222 def argument_context(interface, method, argument, index): |
224 extended_attributes = argument.extended_attributes | 223 extended_attributes = argument.extended_attributes |
225 idl_type = argument.idl_type | 224 idl_type = argument.idl_type |
226 this_cpp_value = cpp_value(interface, method, index) | 225 this_cpp_value = cpp_value(interface, method, index) |
227 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type | 226 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type |
228 return_promise = (method.idl_type.name == 'Promise' if method.idl_type | |
229 else False) | |
230 | 227 |
231 if ('ImplementedInPrivateScript' in extended_attributes and | 228 if ('ImplementedInPrivateScript' in extended_attributes and |
232 not idl_type.is_wrapper_type and | 229 not idl_type.is_wrapper_type and |
233 not idl_type.is_basic_type): | 230 not idl_type.is_basic_type): |
234 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') | 231 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') |
235 | 232 |
236 default_cpp_value = argument.default_cpp_value | 233 default_cpp_value = argument.default_cpp_value |
237 return { | 234 return { |
238 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut
es, | 235 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut
es, |
239 raw_type=True, | 236 raw_type=True, |
(...skipping 23 matching lines...) Expand all Loading... |
263 'is_nullable': idl_type.is_nullable, | 260 'is_nullable': idl_type.is_nullable, |
264 'is_optional': argument.is_optional, | 261 'is_optional': argument.is_optional, |
265 'is_variadic_wrapper_type': is_variadic_wrapper_type, | 262 'is_variadic_wrapper_type': is_variadic_wrapper_type, |
266 'is_wrapper_type': idl_type.is_wrapper_type, | 263 'is_wrapper_type': idl_type.is_wrapper_type, |
267 'name': argument.name, | 264 'name': argument.name, |
268 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( | 265 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( |
269 argument.name, isolate='scriptState->isolate()', | 266 argument.name, isolate='scriptState->isolate()', |
270 creation_context='scriptState->context()->Global()'), | 267 creation_context='scriptState->context()->Global()'), |
271 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), | 268 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), |
272 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), | 269 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), |
273 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind
ex, return_promise=return_promise), | 270 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind
ex, return_promise=method.returns_promise), |
274 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc
_type), | 271 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc
_type), |
275 } | 272 } |
276 | 273 |
277 | 274 |
278 def argument_declarations_for_private_script(interface, method): | 275 def argument_declarations_for_private_script(interface, method): |
279 argument_declarations = ['LocalFrame* frame'] | 276 argument_declarations = ['LocalFrame* frame'] |
280 argument_declarations.append('%s* holderImpl' % interface.name) | 277 argument_declarations.append('%s* holderImpl' % interface.name) |
281 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args( | 278 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args( |
282 used_as_rvalue_type=True), argument.name) for argument in method.argumen
ts]) | 279 used_as_rvalue_type=True), argument.name) for argument in method.argumen
ts]) |
283 if method.idl_type.name != 'void': | 280 if method.idl_type.name != 'void': |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 return '%s::create()' % argument.idl_type.base_type | 462 return '%s::create()' % argument.idl_type.base_type |
466 if not argument.default_value: | 463 if not argument.default_value: |
467 return None | 464 return None |
468 return argument.idl_type.literal_cpp_value(argument.default_value) | 465 return argument.idl_type.literal_cpp_value(argument.default_value) |
469 | 466 |
470 IdlTypeBase.union_arguments = None | 467 IdlTypeBase.union_arguments = None |
471 IdlUnionType.union_arguments = property(union_arguments) | 468 IdlUnionType.union_arguments = property(union_arguments) |
472 IdlArgument.default_cpp_value = property(argument_default_cpp_value) | 469 IdlArgument.default_cpp_value = property(argument_default_cpp_value) |
473 | 470 |
474 | 471 |
475 def v8_conversion_needs_exception_state(argument): | 472 def method_returns_promise(method): |
476 return (argument.idl_type.v8_conversion_needs_exception_state or | 473 return method.idl_type and method.idl_type.name == 'Promise' |
477 argument.is_variadic) | |
478 | 474 |
479 IdlArgument.v8_conversion_needs_exception_state = property(v8_conversion_needs_e
xception_state) | 475 IdlOperation.returns_promise = property(method_returns_promise) |
| 476 |
| 477 |
| 478 def argument_conversion_needs_exception_state(method, argument): |
| 479 idl_type = argument.idl_type |
| 480 return (idl_type.v8_conversion_needs_exception_state or |
| 481 argument.is_variadic or |
| 482 (method.returns_promise and (idl_type.is_string_type or |
| 483 idl_type.is_enum))) |
OLD | NEW |