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

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

Issue 265293004: Create fewer local v8::TryCatch objects in generated bindings code (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebased Created 6 years, 7 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 22 matching lines...) Expand all
33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler 33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
34 """ 34 """
35 35
36 from idl_types import IdlType, IdlUnionType, inherits_interface 36 from idl_types import IdlType, IdlUnionType, inherits_interface
37 from v8_globals import includes 37 from v8_globals import includes
38 import v8_types 38 import v8_types
39 import v8_utilities 39 import v8_utilities
40 from v8_utilities import has_extended_attribute_value 40 from v8_utilities import has_extended_attribute_value
41 41
42 42
43 def argument_needs_try_catch(argument):
44 idl_type = argument.idl_type
45 base_type = not idl_type.array_or_sequence_type and idl_type.base_type
46
47 return not (
48 # These cases are handled by separate code paths in the
49 # generate_argument() macro in Source/bindings/templates/methods.cpp.
50 idl_type.is_callback_interface or
51 base_type == 'SerializedScriptValue' or
52 (argument.is_variadic and idl_type.is_wrapper_type) or
53 # String and enumeration arguments converted using one of the
54 # TOSTRING_* macros in Source/bindings/v8/V8BindingMacros.h don't
55 # use a v8::TryCatch.
56 (base_type == 'DOMString' and not argument.is_variadic))
haraken 2014/05/21 14:56:45 I'm a bit concerned that this list becomes out-dat
Jens Widell 2014/05/21 15:07:02 I'm a bit concerned about maintainability here as
57
58
43 def generate_method(interface, method): 59 def generate_method(interface, method):
44 arguments = method.arguments 60 arguments = method.arguments
45 extended_attributes = method.extended_attributes 61 extended_attributes = method.extended_attributes
46 idl_type = method.idl_type 62 idl_type = method.idl_type
47 is_static = method.is_static 63 is_static = method.is_static
48 name = method.name 64 name = method.name
49 65
50 idl_type.add_includes_for_type() 66 idl_type.add_includes_for_type()
51 this_cpp_value = cpp_value(interface, method, len(arguments)) 67 this_cpp_value = cpp_value(interface, method, len(arguments))
52 68
(...skipping 19 matching lines...) Expand all
72 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') 88 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h')
73 89
74 has_event_listener_argument = any( 90 has_event_listener_argument = any(
75 argument for argument in arguments 91 argument for argument in arguments
76 if argument.idl_type.name == 'EventListener') 92 if argument.idl_type.name == 'EventListener')
77 is_check_security_for_frame = ( 93 is_check_security_for_frame = (
78 'CheckSecurity' in interface.extended_attributes and 94 'CheckSecurity' in interface.extended_attributes and
79 'DoNotCheckSecurity' not in extended_attributes) 95 'DoNotCheckSecurity' not in extended_attributes)
80 is_raises_exception = 'RaisesException' in extended_attributes 96 is_raises_exception = 'RaisesException' in extended_attributes
81 97
98 arguments_need_try_catch = any(argument_needs_try_catch(argument)
99 for argument in arguments)
100
82 return { 101 return {
83 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging] 102 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging]
84 'arguments': [generate_argument(interface, method, argument, index) 103 'arguments': [generate_argument(interface, method, argument, index, argu ments_need_try_catch)
85 for index, argument in enumerate(arguments)], 104 for index, argument in enumerate(arguments)],
105 'arguments_need_try_catch': arguments_need_try_catch,
86 'conditional_string': v8_utilities.conditional_string(method), 106 'conditional_string': v8_utilities.conditional_string(method),
87 'cpp_type': idl_type.cpp_type, 107 'cpp_type': idl_type.cpp_type,
88 'cpp_value': this_cpp_value, 108 'cpp_value': this_cpp_value,
89 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] 109 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs]
90 'do_not_check_signature': not(is_static or 110 'do_not_check_signature': not(is_static or
91 v8_utilities.has_extended_attribute(method, 111 v8_utilities.has_extended_attribute(method,
92 ['DoNotCheckSecurity', 'DoNotCheckSignature', 'NotEnumerable', 112 ['DoNotCheckSecurity', 'DoNotCheckSignature', 'NotEnumerable',
93 'ReadOnly', 'RuntimeEnabled', 'Unforgeable'])), 113 'ReadOnly', 'RuntimeEnabled', 'Unforgeable'])),
94 'function_template': function_template(), 114 'function_template': function_template(),
95 'idl_type': idl_type.base_type, 115 'idl_type': idl_type.base_type,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 'property_attributes': property_attributes(method), 150 'property_attributes': property_attributes(method),
131 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m ethod), # [RuntimeEnabled] 151 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m ethod), # [RuntimeEnabled]
132 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig nature' in extended_attributes else 'defaultSignature', 152 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig nature' in extended_attributes else 'defaultSignature',
133 'union_arguments': idl_type.union_arguments, 153 'union_arguments': idl_type.union_arguments,
134 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True), 154 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True),
135 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value), 155 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value),
136 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings] 156 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings]
137 } 157 }
138 158
139 159
140 def generate_argument(interface, method, argument, index): 160 def generate_argument(interface, method, argument, index, method_has_try_catch):
141 extended_attributes = argument.extended_attributes 161 extended_attributes = argument.extended_attributes
142 idl_type = argument.idl_type 162 idl_type = argument.idl_type
143 this_cpp_value = cpp_value(interface, method, index) 163 this_cpp_value = cpp_value(interface, method, index)
144 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type 164 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type
145 165
146 return { 166 return {
147 'cpp_type': idl_type.cpp_type_args(used_in_cpp_sequence=is_variadic_wrap per_type), 167 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut es,
168 used_as_argument=True,
169 used_as_variadic_argument=argument.is _variadic),
148 'cpp_value': this_cpp_value, 170 'cpp_value': this_cpp_value,
149 'enum_validation_expression': idl_type.enum_validation_expression, 171 'enum_validation_expression': idl_type.enum_validation_expression,
150 'has_default': 'Default' in extended_attributes, 172 'has_default': 'Default' in extended_attributes,
151 'has_event_listener_argument': any( 173 'has_event_listener_argument': any(
152 argument_so_far for argument_so_far in method.arguments[:index] 174 argument_so_far for argument_so_far in method.arguments[:index]
153 if argument_so_far.idl_type.name == 'EventListener'), 175 if argument_so_far.idl_type.name == 'EventListener'),
154 'has_type_checking_interface': 176 'has_type_checking_interface':
155 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface' ) or 177 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface' ) or
156 has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and 178 has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and
157 idl_type.is_wrapper_type, 179 idl_type.is_wrapper_type,
158 'has_type_checking_unrestricted': 180 'has_type_checking_unrestricted':
159 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestrict ed') or 181 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestrict ed') or
160 has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted' )) and 182 has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted' )) and
161 idl_type.name in ('Float', 'Double'), 183 idl_type.name in ('Float', 'Double'),
162 # Dictionary is special-cased, but arrays and sequences shouldn't be 184 # Dictionary is special-cased, but arrays and sequences shouldn't be
163 'idl_type': not idl_type.array_or_sequence_type and idl_type.base_type, 185 'idl_type': not idl_type.array_or_sequence_type and idl_type.base_type,
164 'idl_type_object': idl_type, 186 'idl_type_object': idl_type,
165 'index': index, 187 'index': index,
166 'is_clamp': 'Clamp' in extended_attributes, 188 'is_clamp': 'Clamp' in extended_attributes,
167 'is_callback_interface': idl_type.is_callback_interface, 189 'is_callback_interface': idl_type.is_callback_interface,
168 'is_nullable': idl_type.is_nullable, 190 'is_nullable': idl_type.is_nullable,
169 'is_optional': argument.is_optional, 191 'is_optional': argument.is_optional,
170 'is_variadic_wrapper_type': is_variadic_wrapper_type, 192 'is_variadic_wrapper_type': is_variadic_wrapper_type,
171 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc _type), 193 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc _type),
172 'is_wrapper_type': idl_type.is_wrapper_type, 194 'is_wrapper_type': idl_type.is_wrapper_type,
173 'name': argument.name, 195 'name': argument.name,
174 '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),
175 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value), 197 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value),
176 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind ex), 198 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind ex, method_has_try_catch),
177 } 199 }
178 200
179 201
180 ################################################################################ 202 ################################################################################
181 # Value handling 203 # Value handling
182 ################################################################################ 204 ################################################################################
183 205
184 def cpp_value(interface, method, number_of_arguments): 206 def cpp_value(interface, method, number_of_arguments):
185 def cpp_argument(argument): 207 def cpp_argument(argument):
186 idl_type = argument.idl_type 208 idl_type = argument.idl_type
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 if (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or 259 if (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or
238 'RaisesException' in extended_attributes or 260 'RaisesException' in extended_attributes or
239 idl_type.is_union_type): 261 idl_type.is_union_type):
240 cpp_value = 'result' # use local variable for value 262 cpp_value = 'result' # use local variable for value
241 release = idl_type.release 263 release = idl_type.release
242 264
243 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else '' 265 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else ''
244 return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_w rappable=script_wrappable, release=release, for_main_world=for_main_world) 266 return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_w rappable=script_wrappable, release=release, for_main_world=for_main_world)
245 267
246 268
247 def v8_value_to_local_cpp_value(argument, index): 269 def v8_value_to_local_cpp_value(argument, index, method_has_try_catch):
248 extended_attributes = argument.extended_attributes 270 extended_attributes = argument.extended_attributes
249 idl_type = argument.idl_type 271 idl_type = argument.idl_type
250 name = argument.name 272 name = argument.name
251 if argument.is_variadic: 273 if argument.is_variadic:
252 vector_type = v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc_ type) 274 return 'TONATIVE_VOID_INTERNAL({name}, toNativeArguments<{cpp_type}>(inf o, {index}))'.format(
253 return 'TONATIVE_VOID({vector_type}<{cpp_type}>, {name}, toNativeArgumen ts<{cpp_type}>(info, {index}))'.format( 275 cpp_type=idl_type.cpp_type, name=name, index=index)
254 vector_type=vector_type, cpp_type=idl_type.cpp_type, name=name,
255 index=index)
256 # [Default=NullString] 276 # [Default=NullString]
257 if (argument.is_optional and idl_type.name == 'String' and 277 if (argument.is_optional and idl_type.name == 'String' and
258 extended_attributes.get('Default') == 'NullString'): 278 extended_attributes.get('Default') == 'NullString'):
259 v8_value = 'argumentOrNull(info, %s)' % index 279 v8_value = 'argumentOrNull(info, %s)' % index
260 else: 280 else:
261 v8_value = 'info[%s]' % index 281 v8_value = 'info[%s]' % index
262 return idl_type.v8_value_to_local_cpp_value(extended_attributes, v8_value, 282 return idl_type.v8_value_to_local_cpp_value(extended_attributes, v8_value,
263 name, index=index) 283 name, index=index, declare_varia ble=False,
284 method_has_try_catch=method_has_ try_catch)
264 285
265 286
266 ################################################################################ 287 ################################################################################
267 # Auxiliary functions 288 # Auxiliary functions
268 ################################################################################ 289 ################################################################################
269 290
270 # [NotEnumerable] 291 # [NotEnumerable]
271 def property_attributes(method): 292 def property_attributes(method):
272 extended_attributes = method.extended_attributes 293 extended_attributes = method.extended_attributes
273 property_attributes_list = [] 294 property_attributes_list = []
274 if 'NotEnumerable' in extended_attributes: 295 if 'NotEnumerable' in extended_attributes:
275 property_attributes_list.append('v8::DontEnum') 296 property_attributes_list.append('v8::DontEnum')
276 if 'ReadOnly' in extended_attributes: 297 if 'ReadOnly' in extended_attributes:
277 property_attributes_list.append('v8::ReadOnly') 298 property_attributes_list.append('v8::ReadOnly')
278 if property_attributes_list: 299 if property_attributes_list:
279 property_attributes_list.insert(0, 'v8::DontDelete') 300 property_attributes_list.insert(0, 'v8::DontDelete')
280 return property_attributes_list 301 return property_attributes_list
281 302
282 303
283 def union_arguments(idl_type): 304 def union_arguments(idl_type):
284 """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for u nion types, for use in setting return value""" 305 """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for u nion types, for use in setting return value"""
285 return [arg 306 return [arg
286 for i in range(len(idl_type.member_types)) 307 for i in range(len(idl_type.member_types))
287 for arg in ['result%sEnabled' % i, 'result%s' % i]] 308 for arg in ['result%sEnabled' % i, 'result%s' % i]]
288 309
289 IdlType.union_arguments = property(lambda self: None) 310 IdlType.union_arguments = property(lambda self: None)
290 IdlUnionType.union_arguments = property(union_arguments) 311 IdlUnionType.union_arguments = property(union_arguments)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698