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

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

Issue 680193003: IDL: Generate union type containers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 argument for argument in arguments 171 argument for argument in arguments
172 if not argument.is_optional]), 172 if not argument.is_optional]),
173 'only_exposed_to_private_script': is_only_exposed_to_private_script, 173 'only_exposed_to_private_script': is_only_exposed_to_private_script,
174 'per_context_enabled_function': v8_utilities.per_context_enabled_functio n_name(method), # [PerContextEnabled] 174 'per_context_enabled_function': v8_utilities.per_context_enabled_functio n_name(method), # [PerContextEnabled]
175 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local _cpp_value( 175 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local _cpp_value(
176 extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->is olate()', used_in_private_script=True), 176 extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->is olate()', used_in_private_script=True),
177 'property_attributes': property_attributes(method), 177 'property_attributes': property_attributes(method),
178 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m ethod), # [RuntimeEnabled] 178 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m ethod), # [RuntimeEnabled]
179 'should_be_exposed_to_script': not (is_implemented_in_private_script and is_only_exposed_to_private_script), 179 'should_be_exposed_to_script': not (is_implemented_in_private_script and is_only_exposed_to_private_script),
180 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig nature' in extended_attributes else 'defaultSignature', 180 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig nature' in extended_attributes else 'defaultSignature',
181 'union_arguments': idl_type.union_arguments, 181 'union_result_members': idl_type.union_result_members,
182 'use_output_parameter_for_result': idl_type.is_dictionary, 182 'use_output_parameter_for_result': idl_type.is_dictionary,
183 'use_local_result': use_local_result(method), 183 'use_local_result': use_local_result(method),
184 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value), 184 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value),
185 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True), 185 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True),
186 'visible': is_visible, 186 'visible': is_visible,
187 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings], 187 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings],
188 } 188 }
189 189
190 190
191 def argument_context(interface, method, argument, index): 191 def argument_context(interface, method, argument, index):
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 289
290 # Members of IDL partial interface definitions are implemented in C++ as 290 # Members of IDL partial interface definitions are implemented in C++ as
291 # static member functions, which for instance members (non-static members) 291 # static member functions, which for instance members (non-static members)
292 # take *impl as their first argument 292 # take *impl as their first argument
293 if ('PartialInterfaceImplementedAs' in method.extended_attributes and 293 if ('PartialInterfaceImplementedAs' in method.extended_attributes and
294 not 'ImplementedInPrivateScript' in method.extended_attributes and 294 not 'ImplementedInPrivateScript' in method.extended_attributes and
295 not method.is_static): 295 not method.is_static):
296 cpp_arguments.append('*impl') 296 cpp_arguments.append('*impl')
297 cpp_arguments.extend(cpp_argument(argument) for argument in arguments) 297 cpp_arguments.extend(cpp_argument(argument) for argument in arguments)
298 298
299 this_union_arguments = method.idl_type and method.idl_type.union_arguments
300 if this_union_arguments:
301 cpp_arguments.extend([member_argument['cpp_value']
302 for member_argument in this_union_arguments])
303
304 if 'ImplementedInPrivateScript' in method.extended_attributes: 299 if 'ImplementedInPrivateScript' in method.extended_attributes:
305 if method.idl_type.name != 'void': 300 if method.idl_type.name != 'void':
306 cpp_arguments.append('&result') 301 cpp_arguments.append('&result')
307 elif ('RaisesException' in method.extended_attributes or 302 elif ('RaisesException' in method.extended_attributes or
308 (method.is_constructor and 303 (method.is_constructor and
309 has_extended_attribute_value(interface, 'RaisesException', 'Constructor '))): 304 has_extended_attribute_value(interface, 'RaisesException', 'Constructor '))):
310 cpp_arguments.append('exceptionState') 305 cpp_arguments.append('exceptionState')
311 306
312 # If a method returns an IDL dictionary, the return value is passed 307 # If a method returns an IDL dictionary or union type, the return value is
313 # as an argument to impl classes. 308 # passed as an argument to impl classes.
314 if method.idl_type and method.idl_type.is_dictionary: 309 idl_type = method.idl_type
310 if idl_type and (idl_type.is_dictionary or idl_type.is_union_type):
315 cpp_arguments.append('result') 311 cpp_arguments.append('result')
316 312
317 if method.name == 'Constructor': 313 if method.name == 'Constructor':
318 base_name = 'create' 314 base_name = 'create'
319 elif method.name == 'NamedConstructor': 315 elif method.name == 'NamedConstructor':
320 base_name = 'createForJSConstructor' 316 base_name = 'createForJSConstructor'
321 elif 'ImplementedInPrivateScript' in method.extended_attributes: 317 elif 'ImplementedInPrivateScript' in method.extended_attributes:
322 base_name = '%sMethod' % method.name 318 base_name = '%sMethod' % method.name
323 else: 319 else:
324 base_name = v8_utilities.cpp_name(method) 320 base_name = v8_utilities.cpp_name(method)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 property_attributes_list = [] 391 property_attributes_list = []
396 if 'NotEnumerable' in extended_attributes: 392 if 'NotEnumerable' in extended_attributes:
397 property_attributes_list.append('v8::DontEnum') 393 property_attributes_list.append('v8::DontEnum')
398 if 'Unforgeable' in extended_attributes: 394 if 'Unforgeable' in extended_attributes:
399 property_attributes_list.append('v8::ReadOnly') 395 property_attributes_list.append('v8::ReadOnly')
400 if property_attributes_list: 396 if property_attributes_list:
401 property_attributes_list.insert(0, 'v8::DontDelete') 397 property_attributes_list.insert(0, 'v8::DontDelete')
402 return property_attributes_list 398 return property_attributes_list
403 399
404 400
405 def union_member_argument_context(idl_type, index): 401 def union_result_members_context(idl_type):
406 """Returns a context of union member for argument.""" 402 """Returns a context of return value for methods/getters of which type
Jens Widell 2014/10/28 11:31:38 I think "a context" here is expected to be a dict,
bashi 2014/10/29 01:34:32 Now we no longer need this method :)
407 this_cpp_value = 'result%d' % index 403 is an union type. If a method/getter returns an union type, the impl class
408 this_cpp_type = idl_type.cpp_type 404 takes 'result' argument of which type is the corresponding container class.
409 this_cpp_type_initializer = idl_type.cpp_type_initializer 405 """
410 cpp_return_value = this_cpp_value
411 406
412 if not idl_type.cpp_type_has_null_value: 407 def union_result_member_context(idl_type):
413 this_cpp_type = v8_types.cpp_template_type('Nullable', this_cpp_type) 408 cpp_value = 'result.getAs%s()' % idl_type.name
414 this_cpp_type_initializer = '' 409 if idl_type.is_explicit_nullable:
415 cpp_return_value = '%s.get()' % this_cpp_value 410 cpp_value = '%s.get()' % cpp_value
Jens Widell 2014/10/28 11:31:37 Could be cpp_value += '.get()' too, which is e
411 return {
412 'null_check_value': 'result.is%s()' % idl_type.name,
413 'v8_set_return_value': idl_type.v8_set_return_value(
414 cpp_value=cpp_value),
415 }
416 416
417 if idl_type.is_string_type: 417 return [union_result_member_context(member_idl_type)
418 null_check_value = '!%s.isNull()' % this_cpp_value 418 for member_idl_type in idl_type.member_types]
419 else:
420 null_check_value = this_cpp_value
421
422 return {
423 'cpp_type': this_cpp_type,
424 'cpp_type_initializer': this_cpp_type_initializer,
425 'cpp_value': this_cpp_value,
426 'null_check_value': null_check_value,
427 'v8_set_return_value': idl_type.v8_set_return_value(
428 cpp_value=cpp_return_value,
429 release=idl_type.release),
430 }
431
432
433 def union_arguments(idl_type):
434 return [union_member_argument_context(member_idl_type, index)
435 for index, member_idl_type
436 in enumerate(idl_type.member_types)]
437 419
438 420
439 def argument_default_cpp_value(argument): 421 def argument_default_cpp_value(argument):
440 if argument.idl_type.is_dictionary: 422 if argument.idl_type.is_dictionary:
441 return None 423 return None
442 if not argument.default_value: 424 if not argument.default_value:
443 return None 425 return None
444 return argument.idl_type.literal_cpp_value(argument.default_value) 426 return argument.idl_type.literal_cpp_value(argument.default_value)
445 427
446 IdlTypeBase.union_arguments = None 428 IdlTypeBase.union_result_members = None
447 IdlUnionType.union_arguments = property(union_arguments) 429 IdlUnionType.union_result_members = property(union_result_members_context)
448 IdlArgument.default_cpp_value = property(argument_default_cpp_value) 430 IdlArgument.default_cpp_value = property(argument_default_cpp_value)
449 431
450 432
451 def method_returns_promise(method): 433 def method_returns_promise(method):
452 return method.idl_type and method.idl_type.name == 'Promise' 434 return method.idl_type and method.idl_type.name == 'Promise'
453 435
454 IdlOperation.returns_promise = property(method_returns_promise) 436 IdlOperation.returns_promise = property(method_returns_promise)
455 437
456 438
457 def argument_conversion_needs_exception_state(method, argument): 439 def argument_conversion_needs_exception_state(method, argument):
458 idl_type = argument.idl_type 440 idl_type = argument.idl_type
459 return (idl_type.v8_conversion_needs_exception_state or 441 return (idl_type.v8_conversion_needs_exception_state or
460 argument.is_variadic or 442 argument.is_variadic or
461 (method.returns_promise and (idl_type.is_string_type or 443 (method.returns_promise and (idl_type.is_string_type or
462 idl_type.is_enum))) 444 idl_type.is_enum)))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698