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

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

Issue 229373006: Support optional, non-defaulted constructor arguments. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Formatting 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
« no previous file with comments | « no previous file | Source/bindings/scripts/v8_methods.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 446
447 447
448 ################################################################################ 448 ################################################################################
449 # Constructors 449 # Constructors
450 ################################################################################ 450 ################################################################################
451 451
452 # [Constructor] 452 # [Constructor]
453 def generate_constructor(interface, constructor): 453 def generate_constructor(interface, constructor):
454 return { 454 return {
455 'argument_list': constructor_argument_list(interface, constructor), 455 'argument_list': constructor_argument_list(interface, constructor),
456 'arguments': [constructor_argument(argument, index) 456 'arguments': [constructor_argument(interface, constructor, argument, ind ex)
457 for index, argument in enumerate(constructor.arguments)], 457 for index, argument in enumerate(constructor.arguments)],
458 'has_exception_state': 458 'has_exception_state':
459 # [RaisesException=Constructor] 459 # [RaisesException=Constructor]
460 interface.extended_attributes.get('RaisesException') == 'Constructor ' or 460 interface.extended_attributes.get('RaisesException') == 'Constructor ' or
461 any(argument for argument in constructor.arguments 461 any(argument for argument in constructor.arguments
462 if argument.idl_type.name == 'SerializedScriptValue' or 462 if argument.idl_type.name == 'SerializedScriptValue' or
463 argument.idl_type.is_integer_type), 463 argument.idl_type.is_integer_type),
464 'is_constructor': True, 464 'is_constructor': True,
465 'is_named_constructor': False,
465 'is_variadic': False, # Required for overload resolution 466 'is_variadic': False, # Required for overload resolution
466 'number_of_required_arguments': 467 'number_of_required_arguments':
467 number_of_required_arguments(constructor), 468 number_of_required_arguments(constructor),
468 } 469 }
469 470
470 471
471 def constructor_argument_list(interface, constructor): 472 def constructor_argument_list(interface, constructor):
472 arguments = [] 473 arguments = []
473 # [ConstructorCallWith=ExecutionContext] 474 # [ConstructorCallWith=ExecutionContext]
474 if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Execution Context'): 475 if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Execution Context'):
475 arguments.append('context') 476 arguments.append('context')
476 # [ConstructorCallWith=Document] 477 # [ConstructorCallWith=Document]
477 if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Document' ): 478 if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Document' ):
478 arguments.append('document') 479 arguments.append('document')
479 480
480 arguments.extend([argument.name for argument in constructor.arguments]) 481 arguments.extend([argument.name for argument in constructor.arguments])
481 482
482 # [RaisesException=Constructor] 483 # [RaisesException=Constructor]
483 if interface.extended_attributes.get('RaisesException') == 'Constructor': 484 if interface.extended_attributes.get('RaisesException') == 'Constructor':
484 arguments.append('exceptionState') 485 arguments.append('exceptionState')
485 486
486 return arguments 487 return arguments
487 488
488 489
489 def constructor_argument(argument, index): 490 def constructor_argument(interface, constructor, argument, index):
490 idl_type = argument.idl_type 491 idl_type = argument.idl_type
491 return { 492 return {
493 'cpp_value':
494 v8_methods.cpp_value(interface, constructor, index),
492 'has_default': 'Default' in argument.extended_attributes, 495 'has_default': 'Default' in argument.extended_attributes,
493 'idl_type_object': idl_type,
494 # Dictionary is special-cased, but arrays and sequences shouldn't be 496 # Dictionary is special-cased, but arrays and sequences shouldn't be
495 'idl_type': not idl_type.array_or_sequence_type and idl_type.base_type, 497 'idl_type': not idl_type.array_or_sequence_type and idl_type.base_type,
498 'idl_type_object': idl_type,
496 'index': index, 499 'index': index,
497 'is_optional': argument.is_optional, 500 'is_optional': argument.is_optional,
498 'is_strict_type_checking': False, # Required for overload resolution 501 'is_strict_type_checking': False, # Required for overload resolution
499 'name': argument.name, 502 'name': argument.name,
500 'v8_value_to_local_cpp_value': 503 'v8_value_to_local_cpp_value':
501 v8_methods.v8_value_to_local_cpp_value(argument, index), 504 v8_methods.v8_value_to_local_cpp_value(argument, index),
502 } 505 }
503 506
504 507
505 def generate_constructor_overloads(constructors): 508 def generate_constructor_overloads(constructors):
(...skipping 11 matching lines...) Expand all
517 def generate_named_constructor(interface): 520 def generate_named_constructor(interface):
518 extended_attributes = interface.extended_attributes 521 extended_attributes = interface.extended_attributes
519 if 'NamedConstructor' not in extended_attributes: 522 if 'NamedConstructor' not in extended_attributes:
520 return None 523 return None
521 # FIXME: parser should return named constructor separately; 524 # FIXME: parser should return named constructor separately;
522 # included in constructors (and only name stored in extended attribute) 525 # included in constructors (and only name stored in extended attribute)
523 # for Perl compatibility 526 # for Perl compatibility
524 idl_constructor = interface.constructors[0] 527 idl_constructor = interface.constructors[0]
525 constructor = generate_constructor(interface, idl_constructor) 528 constructor = generate_constructor(interface, idl_constructor)
526 constructor['argument_list'].insert(0, '*document') 529 constructor['argument_list'].insert(0, '*document')
527 constructor['name'] = extended_attributes['NamedConstructor'] 530 constructor.update({
531 'name': extended_attributes['NamedConstructor'],
532 'is_named_constructor': True,
533 })
528 return constructor 534 return constructor
529 535
530 536
531 def number_of_required_arguments(constructor): 537 def number_of_required_arguments(constructor):
532 return len([argument for argument in constructor.arguments 538 return len([argument for argument in constructor.arguments
533 if not argument.is_optional]) 539 if not argument.is_optional])
534 540
535 541
536 def interface_length(interface, constructors): 542 def interface_length(interface, constructors):
537 # Docs: http://heycam.github.io/webidl/#es-interface-call 543 # Docs: http://heycam.github.io/webidl/#es-interface-call
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 deleter = next( 731 deleter = next(
726 method 732 method
727 for method in interface.operations 733 for method in interface.operations
728 if ('deleter' in method.specials and 734 if ('deleter' in method.specials and
729 len(method.arguments) == 1 and 735 len(method.arguments) == 1 and
730 str(method.arguments[0].idl_type) == 'DOMString')) 736 str(method.arguments[0].idl_type) == 'DOMString'))
731 except StopIteration: 737 except StopIteration:
732 return None 738 return None
733 739
734 return property_deleter(deleter) 740 return property_deleter(deleter)
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/scripts/v8_methods.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698