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

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

Issue 232563003: API functions returning Promises should not throw exceptions. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 8 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 'is_callback_interface': idl_type.is_callback_interface, 165 'is_callback_interface': idl_type.is_callback_interface,
166 'is_nullable': idl_type.is_nullable, 166 'is_nullable': idl_type.is_nullable,
167 'is_optional': argument.is_optional, 167 'is_optional': argument.is_optional,
168 'is_strict_type_checking': 'StrictTypeChecking' in extended_attributes, 168 'is_strict_type_checking': 'StrictTypeChecking' in extended_attributes,
169 'is_variadic_wrapper_type': is_variadic_wrapper_type, 169 'is_variadic_wrapper_type': is_variadic_wrapper_type,
170 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc _type), 170 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc _type),
171 'is_wrapper_type': idl_type.is_wrapper_type, 171 'is_wrapper_type': idl_type.is_wrapper_type,
172 'name': argument.name, 172 'name': argument.name,
173 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True), 173 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True),
174 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value), 174 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value),
175 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind ex), 175 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind ex, async=False),
Nils Barth (inactive) 2014/04/14 01:18:55 Could you remove the async=False, since it's a def
yhirano 2014/04/14 06:12:43 Done.
176 'v8_value_to_local_cpp_value_async': v8_value_to_local_cpp_value(argumen t, index, async=True),
176 } 177 }
177 178
178 179
179 ################################################################################ 180 ################################################################################
180 # Value handling 181 # Value handling
181 ################################################################################ 182 ################################################################################
182 183
183 def cpp_value(interface, method, number_of_arguments): 184 def cpp_value(interface, method, number_of_arguments):
184 def cpp_argument(argument): 185 def cpp_argument(argument):
185 idl_type = argument.idl_type 186 idl_type = argument.idl_type
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 has_extended_attribute_value(method, 'CallWith', 'NewScriptState') or 237 has_extended_attribute_value(method, 'CallWith', 'NewScriptState') or
237 'RaisesException' in extended_attributes or 238 'RaisesException' in extended_attributes or
238 idl_type.is_union_type): 239 idl_type.is_union_type):
239 cpp_value = 'result' # use local variable for value 240 cpp_value = 'result' # use local variable for value
240 release = idl_type.release 241 release = idl_type.release
241 242
242 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else '' 243 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else ''
243 return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_w rappable=script_wrappable, release=release, for_main_world=for_main_world) 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)
244 245
245 246
246 def v8_value_to_local_cpp_value(argument, index): 247 def v8_value_to_local_cpp_variadic_value(argument, index, async):
248 assert argument.is_variadic
249 idl_type = argument.idl_type
250 vector_type = v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc_type )
251
252 macro = 'TONATIVE_VOID' + ('_ASYNC' if async else '')
253 macro_args = [
254 '%s<%s>' % (vector_type, idl_type.cpp_type),
255 argument.name,
256 'toNativeArguments<%s>(info, %s)' % (idl_type.cpp_type, index),
257 ]
258 if async:
259 macro_args.append('info')
260 return '%s(%s)' % (macro, ', '.join(macro_args))
261
262
263 def v8_value_to_local_cpp_value(argument, index, async=False):
247 extended_attributes = argument.extended_attributes 264 extended_attributes = argument.extended_attributes
248 idl_type = argument.idl_type 265 idl_type = argument.idl_type
249 name = argument.name 266 name = argument.name
250 if argument.is_variadic: 267 if argument.is_variadic:
251 vector_type = v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc_ type) 268 return v8_value_to_local_cpp_variadic_value(argument, index, async)
252 return 'TONATIVE_VOID({vector_type}<{cpp_type}>, {name}, toNativeArgumen ts<{cpp_type}>(info, {index}))'.format(
253 vector_type=vector_type, cpp_type=idl_type.cpp_type, name=name,
254 index=index)
255 # [Default=NullString] 269 # [Default=NullString]
256 if (argument.is_optional and idl_type.name == 'String' and 270 if (argument.is_optional and idl_type.name == 'String' and
257 extended_attributes.get('Default') == 'NullString'): 271 extended_attributes.get('Default') == 'NullString'):
258 v8_value = 'argumentOrNull(info, %s)' % index 272 v8_value = 'argumentOrNull(info, %s)' % index
259 else: 273 else:
260 v8_value = 'info[%s]' % index 274 v8_value = 'info[%s]' % index
261 return idl_type.v8_value_to_local_cpp_value(extended_attributes, v8_value, 275 return idl_type.v8_value_to_local_cpp_value(extended_attributes, v8_value,
262 name, index=index) 276 name, index=index, async=async)
263 277
264 278
265 ################################################################################ 279 ################################################################################
266 # Auxiliary functions 280 # Auxiliary functions
267 ################################################################################ 281 ################################################################################
268 282
269 # [NotEnumerable] 283 # [NotEnumerable]
270 def property_attributes(method): 284 def property_attributes(method):
271 extended_attributes = method.extended_attributes 285 extended_attributes = method.extended_attributes
272 property_attributes_list = [] 286 property_attributes_list = []
273 if 'NotEnumerable' in extended_attributes: 287 if 'NotEnumerable' in extended_attributes:
274 property_attributes_list.append('v8::DontEnum') 288 property_attributes_list.append('v8::DontEnum')
275 if 'ReadOnly' in extended_attributes: 289 if 'ReadOnly' in extended_attributes:
276 property_attributes_list.append('v8::ReadOnly') 290 property_attributes_list.append('v8::ReadOnly')
277 if property_attributes_list: 291 if property_attributes_list:
278 property_attributes_list.insert(0, 'v8::DontDelete') 292 property_attributes_list.insert(0, 'v8::DontDelete')
279 return property_attributes_list 293 return property_attributes_list
280 294
281 295
282 def union_arguments(idl_type): 296 def union_arguments(idl_type):
283 """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for u nion types, for use in setting return value""" 297 """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for u nion types, for use in setting return value"""
284 return [arg 298 return [arg
285 for i in range(len(idl_type.member_types)) 299 for i in range(len(idl_type.member_types))
286 for arg in ['result%sEnabled' % i, 'result%s' % i]] 300 for arg in ['result%sEnabled' % i, 'result%s' % i]]
287 301
288 IdlType.union_arguments = property(lambda self: None) 302 IdlType.union_arguments = property(lambda self: None)
289 IdlUnionType.union_arguments = property(union_arguments) 303 IdlUnionType.union_arguments = property(union_arguments)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698