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

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

Issue 340443004: IDL: reuse more code between CG for methods and constructors (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rename scriptContext -> executionContext Created 6 years, 6 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 | « Source/bindings/scripts/v8_attributes.py ('k') | 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 # coding=utf-8 2 # coding=utf-8
3 # 3 #
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 ################################################################################ 830 ################################################################################
831 # Constructors 831 # Constructors
832 ################################################################################ 832 ################################################################################
833 833
834 # [Constructor] 834 # [Constructor]
835 def generate_constructor(interface, constructor): 835 def generate_constructor(interface, constructor):
836 arguments_need_try_catch = any(v8_methods.argument_needs_try_catch(argument) 836 arguments_need_try_catch = any(v8_methods.argument_needs_try_catch(argument)
837 for argument in constructor.arguments) 837 for argument in constructor.arguments)
838 838
839 return { 839 return {
840 'argument_list': constructor_argument_list(interface, constructor),
841 'arguments': [v8_methods.generate_argument(interface, constructor, argum ent, index) 840 'arguments': [v8_methods.generate_argument(interface, constructor, argum ent, index)
842 for index, argument in enumerate(constructor.arguments)], 841 for index, argument in enumerate(constructor.arguments)],
843 'arguments_need_try_catch': arguments_need_try_catch, 842 'arguments_need_try_catch': arguments_need_try_catch,
844 'cpp_type': cpp_template_type( 843 'cpp_type': cpp_template_type(
845 cpp_ptr_type('RefPtr', 'RawPtr', gc_type(interface)), 844 cpp_ptr_type('RefPtr', 'RawPtr', gc_type(interface)),
846 cpp_name(interface)), 845 cpp_name(interface)),
846 'cpp_value': v8_methods.cpp_value(
847 interface, constructor, len(constructor.arguments)),
847 'has_exception_state': 848 'has_exception_state':
848 # [RaisesException=Constructor] 849 # [RaisesException=Constructor]
849 interface.extended_attributes.get('RaisesException') == 'Constructor ' or 850 interface.extended_attributes.get('RaisesException') == 'Constructor ' or
850 any(argument for argument in constructor.arguments 851 any(argument for argument in constructor.arguments
851 if argument.idl_type.name == 'SerializedScriptValue' or 852 if argument.idl_type.name == 'SerializedScriptValue' or
852 argument.idl_type.is_integer_type), 853 argument.idl_type.is_integer_type),
853 'is_constructor': True, 854 'is_constructor': True,
854 'is_named_constructor': False, 855 'is_named_constructor': False,
855 'number_of_required_arguments': 856 'number_of_required_arguments':
856 number_of_required_arguments(constructor), 857 number_of_required_arguments(constructor),
857 } 858 }
858 859
859 860
860 def constructor_argument_list(interface, constructor):
861 arguments = []
862 # [ConstructorCallWith=ExecutionContext]
863 if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Execution Context'):
864 arguments.append('context')
865 # [ConstructorCallWith=Document]
866 if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Document' ):
867 arguments.append('document')
868
869 arguments.extend([argument.name for argument in constructor.arguments])
870
871 # [RaisesException=Constructor]
872 if interface.extended_attributes.get('RaisesException') == 'Constructor':
873 arguments.append('exceptionState')
874
875 return arguments
876
877
878 # [NamedConstructor] 861 # [NamedConstructor]
879 def generate_named_constructor(interface): 862 def generate_named_constructor(interface):
880 extended_attributes = interface.extended_attributes 863 extended_attributes = interface.extended_attributes
881 if 'NamedConstructor' not in extended_attributes: 864 if 'NamedConstructor' not in extended_attributes:
882 return None 865 return None
883 # FIXME: parser should return named constructor separately; 866 # FIXME: parser should return named constructor separately;
884 # included in constructors (and only name stored in extended attribute) 867 # included in constructors (and only name stored in extended attribute)
885 # for Perl compatibility 868 # for Perl compatibility
886 idl_constructor = interface.constructors[0] 869 idl_constructor = interface.constructors[-1]
870 assert idl_constructor.name == 'NamedConstructor'
887 constructor = generate_constructor(interface, idl_constructor) 871 constructor = generate_constructor(interface, idl_constructor)
888 constructor['argument_list'].insert(0, '*document')
889 constructor.update({ 872 constructor.update({
890 'name': extended_attributes['NamedConstructor'], 873 'name': extended_attributes['NamedConstructor'],
891 'is_named_constructor': True, 874 'is_named_constructor': True,
892 }) 875 })
893 return constructor 876 return constructor
894 877
895 878
896 def number_of_required_arguments(constructor): 879 def number_of_required_arguments(constructor):
897 return len([argument for argument in constructor.arguments 880 return len([argument for argument in constructor.arguments
898 if not argument.is_optional]) 881 if not argument.is_optional])
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 deleter = next( 1073 deleter = next(
1091 method 1074 method
1092 for method in interface.operations 1075 for method in interface.operations
1093 if ('deleter' in method.specials and 1076 if ('deleter' in method.specials and
1094 len(method.arguments) == 1 and 1077 len(method.arguments) == 1 and
1095 str(method.arguments[0].idl_type) == 'DOMString')) 1078 str(method.arguments[0].idl_type) == 'DOMString'))
1096 except StopIteration: 1079 except StopIteration:
1097 return None 1080 return None
1098 1081
1099 return property_deleter(deleter) 1082 return property_deleter(deleter)
OLDNEW
« no previous file with comments | « Source/bindings/scripts/v8_attributes.py ('k') | Source/bindings/scripts/v8_methods.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698