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

Side by Side Diff: bindings/scripts/generate_global_constructors.py

Issue 1660113002: Updated to Chrome 45 (2454) moved from SVN to git. Base URL: https://github.com/dart-lang/webcore.git@roll_45
Patch Set: Created 4 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
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright 2014 The Chromium Authors. All rights reserved. 3 # Copyright 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Generates interface properties on global objects. 7 """Generates interface properties on global objects.
8 8
9 Concretely these are implemented as "constructor attributes", meaning 9 Concretely these are implemented as "constructor attributes", meaning
10 "attributes whose name ends with Constructor" (special-cased by code generator), 10 "attributes whose name ends with Constructor" (special-cased by code generator),
11 hence "global constructors" for short. 11 hence "global constructors" for short.
12 12
13 For reference on global objects, see: 13 For reference on global objects, see:
14 http://heycam.github.io/webidl/#Global 14 http://heycam.github.io/webidl/#Global
15 http://heycam.github.io/webidl/#Exposed 15 http://heycam.github.io/webidl/#Exposed
16 16
17 Design document: http://www.chromium.org/developers/design-documents/idl-build 17 Design document: http://www.chromium.org/developers/design-documents/idl-build
18 """ 18 """
19 19
20 import itertools 20 import itertools
21 import optparse 21 import optparse
22 import os 22 import os
23 import cPickle as pickle 23 import cPickle as pickle
24 import re 24 import re
25 import sys 25 import sys
26 26
27 from v8_utilities import EXPOSED_EXECUTION_CONTEXT_METHOD
28
27 from collections import defaultdict 29 from collections import defaultdict
28 from utilities import get_file_contents, idl_filename_to_interface_name, read_fi le_to_list, write_file, get_interface_extended_attributes_from_idl, is_callback_ interface_from_idl 30 from utilities import should_generate_impl_file_from_idl, get_file_contents, idl _filename_to_interface_name, read_file_to_list, write_file, get_interface_extend ed_attributes_from_idl, get_interface_exposed_arguments, is_callback_interface_f rom_idl
29 31
30 interface_name_to_global_names = {} 32 interface_name_to_global_names = {}
31 global_name_to_constructors = defaultdict(list) 33 global_name_to_constructors = defaultdict(list)
32 34
33 35
34 HEADER_FORMAT = """// Stub header file for {{idl_basename}} 36 HEADER_FORMAT = """// Stub header file for {{idl_basename}}
35 // Required because the IDL compiler assumes that a corresponding header file 37 // Required because the IDL compiler assumes that a corresponding header file
36 // exists for each IDL file. 38 // exists for each IDL file.
37 """ 39 """
38 40
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 interface_name = idl_filename_to_interface_name(idl_filename) 72 interface_name = idl_filename_to_interface_name(idl_filename)
71 full_path = os.path.realpath(idl_filename) 73 full_path = os.path.realpath(idl_filename)
72 idl_file_contents = get_file_contents(full_path) 74 idl_file_contents = get_file_contents(full_path)
73 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co ntents) 75 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co ntents)
74 76
75 # An interface property is produced for every non-callback interface 77 # An interface property is produced for every non-callback interface
76 # that does not have [NoInterfaceObject]. 78 # that does not have [NoInterfaceObject].
77 # Callback interfaces with constants also have interface properties, 79 # Callback interfaces with constants also have interface properties,
78 # but there are none of these in Blink. 80 # but there are none of these in Blink.
79 # http://heycam.github.io/webidl/#es-interfaces 81 # http://heycam.github.io/webidl/#es-interfaces
80 if (is_callback_interface_from_idl(idl_file_contents) or 82 if ((not should_generate_impl_file_from_idl(idl_file_contents)) or
83 is_callback_interface_from_idl(idl_file_contents) or
81 'NoInterfaceObject' in extended_attributes): 84 'NoInterfaceObject' in extended_attributes):
82 return 85 return
83 86
84 # The [Exposed] extended attribute MUST take an identifier list. Each 87 exposed_arguments = get_interface_exposed_arguments(idl_file_contents)
85 # identifier in the list MUST be a global name. An interface or interface 88 if exposed_arguments:
86 # member the extended attribute applies to will be exposed only on objects 89 # Exposed(Arguments) case
87 # associated with ECMAScript global environments whose global object 90 for argument in exposed_arguments:
88 # implements an interface that has a matching global name. 91 if 'RuntimeEnabled' in extended_attributes:
89 exposed_global_names = extended_attributes.get('Exposed', 'Window').strip('( )').split(',') 92 raise ValueError('RuntimeEnabled should not be used with Exposed (Arguments)')
90 new_constructors_list = generate_global_constructors_list(interface_name, ex tended_attributes) 93 attributes = extended_attributes.copy()
91 for exposed_global_name in exposed_global_names: 94 attributes['RuntimeEnabled'] = argument['runtime_enabled']
92 global_name_to_constructors[exposed_global_name].extend(new_constructors _list) 95 new_constructors_list = generate_global_constructors_list(interface_ name, attributes)
96 global_name_to_constructors[argument['exposed']].extend(new_construc tors_list)
97 else:
98 # Exposed=env or Exposed=(env1,...) case
99 exposed_global_names = extended_attributes.get('Exposed', 'Window').stri p('()').split(',')
100 new_constructors_list = generate_global_constructors_list(interface_name , extended_attributes)
101 for name in exposed_global_names:
102 global_name_to_constructors[name].extend(new_constructors_list)
93 103
94 104
95 def generate_global_constructors_list(interface_name, extended_attributes): 105 def generate_global_constructors_list(interface_name, extended_attributes):
96 extended_attributes_list = [ 106 extended_attributes_list = [
97 name + '=' + extended_attributes[name] 107 name + '=' + extended_attributes[name]
98 for name in 'Conditional', 'PerContextEnabled', 'RuntimeEnabled' 108 for name in 'Conditional', 'RuntimeEnabled'
99 if name in extended_attributes] 109 if name in extended_attributes]
100 if extended_attributes_list: 110 if extended_attributes_list:
101 extended_string = '[%s] ' % ', '.join(extended_attributes_list) 111 extended_string = '[%s] ' % ', '.join(extended_attributes_list)
102 else: 112 else:
103 extended_string = '' 113 extended_string = ''
104 114
105 attribute_string = 'attribute {interface_name}Constructor {interface_name}'. format(interface_name=interface_name) 115 attribute_string = 'attribute {interface_name}Constructor {interface_name}'. format(interface_name=interface_name)
106 attributes_list = [extended_string + attribute_string] 116 attributes_list = [extended_string + attribute_string]
107 117
108 # In addition to the usual interface property, for every [NamedConstructor] 118 # In addition to the usual interface property, for every [NamedConstructor]
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 interface_name_idl_filename = [(args[i], args[i + 1]) 161 interface_name_idl_filename = [(args[i], args[i + 1])
152 for i in range(0, len(args), 2)] 162 for i in range(0, len(args), 2)]
153 163
154 with open(options.global_objects_file) as global_objects_file: 164 with open(options.global_objects_file) as global_objects_file:
155 interface_name_to_global_names.update(pickle.load(global_objects_file)) 165 interface_name_to_global_names.update(pickle.load(global_objects_file))
156 166
157 for idl_filename in idl_files: 167 for idl_filename in idl_files:
158 record_global_constructors(idl_filename) 168 record_global_constructors(idl_filename)
159 169
160 # Check for [Exposed] / [Global] mismatch. 170 # Check for [Exposed] / [Global] mismatch.
161 known_global_names = frozenset(itertools.chain.from_iterable(interface_name_ to_global_names.values())) 171 known_global_names = EXPOSED_EXECUTION_CONTEXT_METHOD.keys()
162 exposed_global_names = frozenset(global_name_to_constructors) 172 exposed_global_names = frozenset(global_name_to_constructors)
163 if not exposed_global_names.issubset(known_global_names): 173 if not exposed_global_names.issubset(known_global_names):
164 unknown_global_names = exposed_global_names.difference(known_global_name s) 174 unknown_global_names = exposed_global_names.difference(known_global_name s)
165 raise ValueError('The following global names were used in ' 175 raise ValueError('The following global names were used in '
166 '[Exposed=xxx] but do not match any [Global] / ' 176 '[Exposed=xxx] but do not match any [Global] / '
167 '[PrimaryGlobal] interface: %s' 177 '[PrimaryGlobal] interface: %s'
168 % list(unknown_global_names)) 178 % list(unknown_global_names))
169 179
170 # Write partial interfaces containing constructor attributes for each 180 # Write partial interfaces containing constructor attributes for each
171 # global interface. 181 # global interface.
172 for interface_name, idl_filename in interface_name_idl_filename: 182 for interface_name, idl_filename in interface_name_idl_filename:
173 constructors = interface_name_to_constructors(interface_name) 183 constructors = interface_name_to_constructors(interface_name)
174 write_global_constructors_partial_interface( 184 write_global_constructors_partial_interface(
175 interface_name, 185 interface_name,
176 idl_filename, 186 idl_filename,
177 constructors, 187 constructors,
178 options.write_file_only_if_changed) 188 options.write_file_only_if_changed)
179 189
180 190
181 if __name__ == '__main__': 191 if __name__ == '__main__':
182 sys.exit(main()) 192 sys.exit(main())
OLDNEW
« no previous file with comments | « bindings/scripts/generate_event_interfaces.py ('k') | bindings/scripts/generate_init_partial_interfaces.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698