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

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: call block.ReThrow() when throwing exceptions 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 return not (
45 # These cases are handled by separate code paths in the
46 # generate_argument() macro in Source/bindings/templates/methods.cpp.
47 argument['is_callback_interface'] or
48 argument['idl_type'] == 'SerializedScriptValue' or
49 argument['is_variadic_wrapper_type'] or
50 # String and enumeration arguments converted using one of the
51 # TOSTRING_* macros in Source/bindings/v8/V8BindingMacros.h don't
52 # use a v8::TryCatch.
53 argument['v8_value_to_local_cpp_value'].startswith('TOSTRING_'))
54
55
43 def generate_method(interface, method): 56 def generate_method(interface, method):
44 arguments = method.arguments 57 arguments = method.arguments
45 extended_attributes = method.extended_attributes 58 extended_attributes = method.extended_attributes
46 idl_type = method.idl_type 59 idl_type = method.idl_type
47 is_static = method.is_static 60 is_static = method.is_static
48 name = method.name 61 name = method.name
49 62
50 idl_type.add_includes_for_type() 63 idl_type.add_includes_for_type()
51 this_cpp_value = cpp_value(interface, method, len(arguments)) 64 this_cpp_value = cpp_value(interface, method, len(arguments))
52 65
(...skipping 19 matching lines...) Expand all
72 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') 85 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h')
73 86
74 has_event_listener_argument = any( 87 has_event_listener_argument = any(
75 argument for argument in arguments 88 argument for argument in arguments
76 if argument.idl_type.name == 'EventListener') 89 if argument.idl_type.name == 'EventListener')
77 is_check_security_for_frame = ( 90 is_check_security_for_frame = (
78 'CheckSecurity' in interface.extended_attributes and 91 'CheckSecurity' in interface.extended_attributes and
79 'DoNotCheckSecurity' not in extended_attributes) 92 'DoNotCheckSecurity' not in extended_attributes)
80 is_raises_exception = 'RaisesException' in extended_attributes 93 is_raises_exception = 'RaisesException' in extended_attributes
81 94
95 generated_arguments = [generate_argument(interface, method, argument, index)
96 for index, argument in enumerate(arguments)]
97
82 return { 98 return {
83 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging] 99 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging]
84 'arguments': [generate_argument(interface, method, argument, index) 100 'arguments': generated_arguments,
85 for index, argument in enumerate(arguments)], 101 'arguments_need_try_catch': any(argument_needs_try_catch(argument)
102 for argument in generated_arguments),
86 'conditional_string': v8_utilities.conditional_string(method), 103 'conditional_string': v8_utilities.conditional_string(method),
87 'cpp_type': idl_type.cpp_type, 104 'cpp_type': idl_type.cpp_type,
88 'cpp_value': this_cpp_value, 105 'cpp_value': this_cpp_value,
89 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] 106 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs]
90 'do_not_check_signature': not(is_static or 107 'do_not_check_signature': not(is_static or
91 v8_utilities.has_extended_attribute(method, 108 v8_utilities.has_extended_attribute(method,
92 ['DoNotCheckSecurity', 'DoNotCheckSignature', 'NotEnumerable', 109 ['DoNotCheckSecurity', 'DoNotCheckSignature', 'NotEnumerable',
93 'ReadOnly', 'RuntimeEnabled', 'Unforgeable'])), 110 'ReadOnly', 'RuntimeEnabled', 'Unforgeable'])),
94 'function_template': function_template(), 111 'function_template': function_template(),
95 'idl_type': idl_type.base_type, 112 'idl_type': idl_type.base_type,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 154 }
138 155
139 156
140 def generate_argument(interface, method, argument, index): 157 def generate_argument(interface, method, argument, index):
141 extended_attributes = argument.extended_attributes 158 extended_attributes = argument.extended_attributes
142 idl_type = argument.idl_type 159 idl_type = argument.idl_type
143 this_cpp_value = cpp_value(interface, method, index) 160 this_cpp_value = cpp_value(interface, method, index)
144 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type 161 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type
145 162
146 return { 163 return {
147 'cpp_type': idl_type.cpp_type_args(used_in_cpp_sequence=is_variadic_wrap per_type), 164 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut es,
165 used_as_argument=True,
166 used_as_variadic_argument=argument.is _variadic),
148 'cpp_value': this_cpp_value, 167 'cpp_value': this_cpp_value,
149 'enum_validation_expression': idl_type.enum_validation_expression, 168 'enum_validation_expression': idl_type.enum_validation_expression,
150 'has_default': 'Default' in extended_attributes, 169 'has_default': 'Default' in extended_attributes,
151 'has_event_listener_argument': any( 170 'has_event_listener_argument': any(
152 argument_so_far for argument_so_far in method.arguments[:index] 171 argument_so_far for argument_so_far in method.arguments[:index]
153 if argument_so_far.idl_type.name == 'EventListener'), 172 if argument_so_far.idl_type.name == 'EventListener'),
154 'has_legacy_overload_string': # [LegacyOverloadString] 173 'has_legacy_overload_string': # [LegacyOverloadString]
155 'LegacyOverloadString' in extended_attributes, 174 'LegacyOverloadString' in extended_attributes,
156 'has_type_checking_interface': 175 'has_type_checking_interface':
157 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface' ) or 176 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface' ) or
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 263
245 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else '' 264 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else ''
246 return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_w rappable=script_wrappable, release=release, for_main_world=for_main_world) 265 return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_w rappable=script_wrappable, release=release, for_main_world=for_main_world)
247 266
248 267
249 def v8_value_to_local_cpp_value(argument, index): 268 def v8_value_to_local_cpp_value(argument, index):
250 extended_attributes = argument.extended_attributes 269 extended_attributes = argument.extended_attributes
251 idl_type = argument.idl_type 270 idl_type = argument.idl_type
252 name = argument.name 271 name = argument.name
253 if argument.is_variadic: 272 if argument.is_variadic:
254 vector_type = v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc_ type) 273 return 'TONATIVE_VOID_INTERNAL({name}, toNativeArguments<{cpp_type}>(inf o, {index}))'.format(
255 return 'TONATIVE_VOID({vector_type}<{cpp_type}>, {name}, toNativeArgumen ts<{cpp_type}>(info, {index}))'.format( 274 cpp_type=idl_type.cpp_type, name=name, index=index)
256 vector_type=vector_type, cpp_type=idl_type.cpp_type, name=name,
257 index=index)
258 # [Default=NullString] 275 # [Default=NullString]
259 if (argument.is_optional and idl_type.name == 'String' and 276 if (argument.is_optional and idl_type.name == 'String' and
260 extended_attributes.get('Default') == 'NullString'): 277 extended_attributes.get('Default') == 'NullString'):
261 v8_value = 'argumentOrNull(info, %s)' % index 278 v8_value = 'argumentOrNull(info, %s)' % index
262 else: 279 else:
263 v8_value = 'info[%s]' % index 280 v8_value = 'info[%s]' % index
264 return idl_type.v8_value_to_local_cpp_value(extended_attributes, v8_value, 281 return idl_type.v8_value_to_local_cpp_value(extended_attributes, v8_value,
265 name, index=index) 282 name, index=index, declare_varia ble=False)
266 283
267 284
268 ################################################################################ 285 ################################################################################
269 # Auxiliary functions 286 # Auxiliary functions
270 ################################################################################ 287 ################################################################################
271 288
272 # [NotEnumerable] 289 # [NotEnumerable]
273 def property_attributes(method): 290 def property_attributes(method):
274 extended_attributes = method.extended_attributes 291 extended_attributes = method.extended_attributes
275 property_attributes_list = [] 292 property_attributes_list = []
276 if 'NotEnumerable' in extended_attributes: 293 if 'NotEnumerable' in extended_attributes:
277 property_attributes_list.append('v8::DontEnum') 294 property_attributes_list.append('v8::DontEnum')
278 if 'ReadOnly' in extended_attributes: 295 if 'ReadOnly' in extended_attributes:
279 property_attributes_list.append('v8::ReadOnly') 296 property_attributes_list.append('v8::ReadOnly')
280 if property_attributes_list: 297 if property_attributes_list:
281 property_attributes_list.insert(0, 'v8::DontDelete') 298 property_attributes_list.insert(0, 'v8::DontDelete')
282 return property_attributes_list 299 return property_attributes_list
283 300
284 301
285 def union_arguments(idl_type): 302 def union_arguments(idl_type):
286 """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for u nion types, for use in setting return value""" 303 """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for u nion types, for use in setting return value"""
287 return [arg 304 return [arg
288 for i in range(len(idl_type.member_types)) 305 for i in range(len(idl_type.member_types))
289 for arg in ['result%sEnabled' % i, 'result%s' % i]] 306 for arg in ['result%sEnabled' % i, 'result%s' % i]]
290 307
291 IdlType.union_arguments = property(lambda self: None) 308 IdlType.union_arguments = property(lambda self: None)
292 IdlUnionType.union_arguments = property(union_arguments) 309 IdlUnionType.union_arguments = property(union_arguments)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698