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

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

Issue 158663002: IDL compiler: sync Python to r166688 (and clean up special operations+union code) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Typo Created 6 years, 10 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 | Annotate | Revision Log
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 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 return 0 517 return 0
518 return min(constructor['number_of_required_arguments'] 518 return min(constructor['number_of_required_arguments']
519 for constructor in constructors) 519 for constructor in constructors)
520 520
521 521
522 ################################################################################ 522 ################################################################################
523 # Special operations (methods) 523 # Special operations (methods)
524 # http://heycam.github.io/webidl/#idl-special-operations 524 # http://heycam.github.io/webidl/#idl-special-operations
525 ################################################################################ 525 ################################################################################
526 526
527 def property_getter(getter): 527 def property_getter(getter, cpp_arguments):
528 def is_null_expression(idl_type): 528 def is_null_expression(idl_type):
529 if v8_types.is_union_type(idl_type):
530 return ' && '.join('!result%sEnabled' % i
531 for i, _ in
532 enumerate(idl_type.union_member_types))
529 if idl_type == 'DOMString': 533 if idl_type == 'DOMString':
530 return 'element.isNull()' 534 return 'result.isNull()'
531 if is_interface_type(idl_type): 535 if is_interface_type(idl_type):
532 return '!element' 536 return '!result'
533 return '' 537 return ''
534 538
535 def union_arguments(idl_type):
536 """Return list of ['element0Enabled', 'element0', 'element1Enabled', ... ]"""
537 return [arg
538 for i in range(len(idl_type.union_member_types))
539 for arg in ['element%sEnabled' % i, 'element%s' % i]]
540
541 idl_type = getter.idl_type 539 idl_type = getter.idl_type
542 extended_attributes = getter.extended_attributes 540 extended_attributes = getter.extended_attributes
541 is_raises_exception = 'RaisesException' in extended_attributes
543 542
544 is_union_type = v8_types.is_union_type(idl_type) 543 if v8_types.is_union_type(idl_type):
545 if is_union_type:
546 release = [v8_types.is_interface_type(union_member_type) 544 release = [v8_types.is_interface_type(union_member_type)
547 for union_member_type in idl_type.union_member_types] 545 for union_member_type in idl_type.union_member_types]
548 else: 546 else:
549 release = v8_types.is_interface_type(idl_type) 547 release = v8_types.is_interface_type(idl_type)
550 548
549 # FIXME: make more generic, so can use v8_methods.cpp_value
550 cpp_method_name = 'imp->%s' % cpp_name(getter)
551
552 if is_raises_exception:
553 cpp_arguments.append('exceptionState')
554 this_union_arguments = v8_methods.union_arguments(idl_type)
555 if this_union_arguments:
556 cpp_arguments.extend(this_union_arguments)
557
558 cpp_value = '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
559
551 return { 560 return {
552 'cpp_type': v8_types.cpp_type(idl_type), 561 'cpp_type': v8_types.cpp_type(idl_type),
562 'cpp_value': cpp_value,
553 'is_custom': 563 'is_custom':
554 'Custom' in extended_attributes and 564 'Custom' in extended_attributes and
555 (not extended_attributes['Custom'] or 565 (not extended_attributes['Custom'] or
556 has_extended_attribute_value(getter, 'Custom', 'PropertyGetter')), 566 has_extended_attribute_value(getter, 'Custom', 'PropertyGetter')),
557 'is_custom_property_enumerator': has_extended_attribute_value( 567 'is_custom_property_enumerator': has_extended_attribute_value(
558 getter, 'Custom', 'PropertyEnumerator'), 568 getter, 'Custom', 'PropertyEnumerator'),
559 'is_custom_property_query': has_extended_attribute_value( 569 'is_custom_property_query': has_extended_attribute_value(
560 getter, 'Custom', 'PropertyQuery'), 570 getter, 'Custom', 'PropertyQuery'),
561 'is_enumerable': 'NotEnumerable' not in extended_attributes, 571 'is_enumerable': 'NotEnumerable' not in extended_attributes,
562 'is_null_expression': is_null_expression(idl_type), 572 'is_null_expression': is_null_expression(idl_type),
563 'is_raises_exception': 'RaisesException' in extended_attributes, 573 'is_raises_exception': is_raises_exception,
564 'name': cpp_name(getter), 574 'name': cpp_name(getter),
565 'union_arguments': union_arguments(idl_type) if is_union_type else None, 575 'union_arguments': v8_methods.union_arguments(idl_type),
566 'v8_set_return_value': v8_types.v8_set_return_value(idl_type, 'element', extended_attributes=extended_attributes, script_wrappable='collection', release =release), 576 'v8_set_return_value': v8_types.v8_set_return_value(idl_type, 'result', extended_attributes=extended_attributes, script_wrappable='imp', release=release ),
567 } 577 }
568 578
569 579
570 def property_setter(setter): 580 def property_setter(setter):
571 idl_type = setter.arguments[1].idl_type 581 idl_type = setter.arguments[1].idl_type
572 extended_attributes = setter.extended_attributes 582 extended_attributes = setter.extended_attributes
573 is_raises_exception = 'RaisesException' in extended_attributes 583 is_raises_exception = 'RaisesException' in extended_attributes
574 return { 584 return {
575 'has_strict_type_checking': 585 'has_strict_type_checking':
576 'StrictTypeChecking' in extended_attributes and 586 'StrictTypeChecking' in extended_attributes and
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 # getter TYPE [OPTIONAL_IDENTIFIER](unsigned long ARG1) 621 # getter TYPE [OPTIONAL_IDENTIFIER](unsigned long ARG1)
612 getter = next( 622 getter = next(
613 method 623 method
614 for method in interface.operations 624 for method in interface.operations
615 if ('getter' in method.specials and 625 if ('getter' in method.specials and
616 len(method.arguments) == 1 and 626 len(method.arguments) == 1 and
617 method.arguments[0].idl_type == 'unsigned long')) 627 method.arguments[0].idl_type == 'unsigned long'))
618 except StopIteration: 628 except StopIteration:
619 return None 629 return None
620 630
621 return property_getter(getter) 631 return property_getter(getter, ['index'])
622 632
623 633
624 def indexed_property_setter(interface): 634 def indexed_property_setter(interface):
625 try: 635 try:
626 # Find indexed property setter, if present; has form: 636 # Find indexed property setter, if present; has form:
627 # setter RETURN_TYPE [OPTIONAL_IDENTIFIER](unsigned long ARG1, ARG_TYPE ARG2) 637 # setter RETURN_TYPE [OPTIONAL_IDENTIFIER](unsigned long ARG1, ARG_TYPE ARG2)
628 setter = next( 638 setter = next(
629 method 639 method
630 for method in interface.operations 640 for method in interface.operations
631 if ('setter' in method.specials and 641 if ('setter' in method.specials and
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 # getter TYPE [OPTIONAL_IDENTIFIER](DOMString ARG1) 674 # getter TYPE [OPTIONAL_IDENTIFIER](DOMString ARG1)
665 getter = next( 675 getter = next(
666 method 676 method
667 for method in interface.operations 677 for method in interface.operations
668 if ('getter' in method.specials and 678 if ('getter' in method.specials and
669 len(method.arguments) == 1 and 679 len(method.arguments) == 1 and
670 method.arguments[0].idl_type == 'DOMString')) 680 method.arguments[0].idl_type == 'DOMString'))
671 except StopIteration: 681 except StopIteration:
672 return None 682 return None
673 683
674 return property_getter(getter) 684 getter.name = getter.name or 'anonymousNamedGetter'
685 return property_getter(getter, ['propertyName'])
675 686
676 687
677 def named_property_setter(interface): 688 def named_property_setter(interface):
678 try: 689 try:
679 # Find named property setter, if present; has form: 690 # Find named property setter, if present; has form:
680 # setter RETURN_TYPE [OPTIONAL_IDENTIFIER](DOMString ARG1, ARG_TYPE ARG2 ) 691 # setter RETURN_TYPE [OPTIONAL_IDENTIFIER](DOMString ARG1, ARG_TYPE ARG2 )
681 setter = next( 692 setter = next(
682 method 693 method
683 for method in interface.operations 694 for method in interface.operations
684 if ('setter' in method.specials and 695 if ('setter' in method.specials and
(...skipping 12 matching lines...) Expand all
697 deleter = next( 708 deleter = next(
698 method 709 method
699 for method in interface.operations 710 for method in interface.operations
700 if ('deleter' in method.specials and 711 if ('deleter' in method.specials and
701 len(method.arguments) == 1 and 712 len(method.arguments) == 1 and
702 method.arguments[0].idl_type == 'DOMString')) 713 method.arguments[0].idl_type == 'DOMString'))
703 except StopIteration: 714 except StopIteration:
704 return None 715 return None
705 716
706 return property_deleter(deleter) 717 return property_deleter(deleter)
OLDNEW
« no previous file with comments | « Source/bindings/scripts/code_generator_v8.pm ('k') | Source/bindings/scripts/unstable/v8_methods.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698