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

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

Issue 611453002: IDL: Clean up argument conversion error handling (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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):
56 idl_type = argument.idl_type
57 base_type = idl_type.base_type
58
59 return not(
60 # These cases are handled by separate code paths in the
61 # generate_argument() macro in Source/bindings/templates/methods.cpp.
62 idl_type.is_callback_interface or
63 base_type == 'SerializedScriptValue' or
64 (argument.is_variadic and idl_type.is_wrapper_type) or
65 # Variadic arguments use toImplArguments() with throws excentions via
66 # its ExceptionState& argument.
67 argument.is_variadic or
68 # String and enumeration arguments converted using one of the
69 # TOSTRING_* macros except for _PROMISE variants in
70 # Source/bindings/core/v8/V8BindingMacros.h don't use a v8::TryCatch.
71 ((base_type == 'DOMString' or idl_type.is_enum) and
72 not method.returns_promise) or
73 # Conversion that take an ExceptionState& argument throw all their
74 # exceptions via it, and doesn't need/use a TryCatch, except if the
75 # argument has [Clamp], in which case it uses a separate code path in
76 # Source/bindings/templates/methods.cpp, which *does* use a TryCatch.
77 argument_conversion_needs_exception_state(method, argument) or
78 # A trivial conversion cannot throw exceptions at all, so doesn't need a
79 # TryCatch to catch them.
80 idl_type.v8_conversion_is_trivial)
81
82
83 def use_local_result(method): 55 def use_local_result(method):
84 extended_attributes = method.extended_attributes 56 extended_attributes = method.extended_attributes
85 idl_type = method.idl_type 57 idl_type = method.idl_type
86 return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or 58 return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or
87 'ImplementedInPrivateScript' in extended_attributes or 59 'ImplementedInPrivateScript' in extended_attributes or
88 'RaisesException' in extended_attributes or 60 'RaisesException' in extended_attributes or
89 idl_type.is_union_type or 61 idl_type.is_union_type or
90 idl_type.is_explicit_nullable) 62 idl_type.is_explicit_nullable)
91 63
92 64
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 is_check_security_for_frame = ( 107 is_check_security_for_frame = (
136 has_extended_attribute_value(interface, 'CheckSecurity', 'Frame') and 108 has_extended_attribute_value(interface, 'CheckSecurity', 'Frame') and
137 not is_do_not_check_security) 109 not is_do_not_check_security)
138 110
139 is_check_security_for_window = ( 111 is_check_security_for_window = (
140 has_extended_attribute_value(interface, 'CheckSecurity', 'Window') and 112 has_extended_attribute_value(interface, 'CheckSecurity', 'Window') and
141 not is_do_not_check_security) 113 not is_do_not_check_security)
142 114
143 is_raises_exception = 'RaisesException' in extended_attributes 115 is_raises_exception = 'RaisesException' in extended_attributes
144 116
145 arguments_need_try_catch = (
146 any(argument_needs_try_catch(method, argument)
147 for argument in arguments))
148
149 return { 117 return {
150 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging] 118 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging]
151 'arguments': [argument_context(interface, method, argument, index) 119 'arguments': [argument_context(interface, method, argument, index)
152 for index, argument in enumerate(arguments)], 120 for index, argument in enumerate(arguments)],
153 'argument_declarations_for_private_script': 121 'argument_declarations_for_private_script':
154 argument_declarations_for_private_script(interface, method), 122 argument_declarations_for_private_script(interface, method),
155 'arguments_need_try_catch': arguments_need_try_catch,
156 'conditional_string': v8_utilities.conditional_string(method), 123 'conditional_string': v8_utilities.conditional_string(method),
157 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type) 124 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type)
158 if idl_type.is_explicit_nullable else idl_type.cpp_type), 125 if idl_type.is_explicit_nullable else idl_type.cpp_type),
159 'cpp_value': this_cpp_value, 126 'cpp_value': this_cpp_value,
160 'cpp_type_initializer': idl_type.cpp_type_initializer, 127 'cpp_type_initializer': idl_type.cpp_type_initializer,
161 'custom_registration_extended_attributes': 128 'custom_registration_extended_attributes':
162 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES.intersection( 129 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES.intersection(
163 extended_attributes.iterkeys()), 130 extended_attributes.iterkeys()),
164 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] 131 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs]
165 'exposed_test': v8_utilities.exposed(method, interface), # [Exposed] 132 'exposed_test': v8_utilities.exposed(method, interface), # [Exposed]
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 441
475 IdlOperation.returns_promise = property(method_returns_promise) 442 IdlOperation.returns_promise = property(method_returns_promise)
476 443
477 444
478 def argument_conversion_needs_exception_state(method, argument): 445 def argument_conversion_needs_exception_state(method, argument):
479 idl_type = argument.idl_type 446 idl_type = argument.idl_type
480 return (idl_type.v8_conversion_needs_exception_state or 447 return (idl_type.v8_conversion_needs_exception_state or
481 argument.is_variadic or 448 argument.is_variadic or
482 (method.returns_promise and (idl_type.is_string_type or 449 (method.returns_promise and (idl_type.is_string_type or
483 idl_type.is_enum))) 450 idl_type.is_enum)))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698