OLD | NEW |
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 collections import defaultdict | 27 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 | 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, is_dictionary_from_idl |
29 | 29 |
30 interface_name_to_global_names = {} | 30 interface_name_to_global_names = {} |
31 global_name_to_constructors = defaultdict(list) | 31 global_name_to_constructors = defaultdict(list) |
32 | 32 |
33 | 33 |
34 HEADER_FORMAT = """// Stub header file for {{idl_basename}} | 34 HEADER_FORMAT = """// Stub header file for {{idl_basename}} |
35 // Required because the IDL compiler assumes that a corresponding header file | 35 // Required because the IDL compiler assumes that a corresponding header file |
36 // exists for each IDL file. | 36 // exists for each IDL file. |
37 """ | 37 """ |
38 | 38 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 full_path = os.path.realpath(idl_filename) | 71 full_path = os.path.realpath(idl_filename) |
72 idl_file_contents = get_file_contents(full_path) | 72 idl_file_contents = get_file_contents(full_path) |
73 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co
ntents) | 73 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co
ntents) |
74 | 74 |
75 # An interface property is produced for every non-callback interface | 75 # An interface property is produced for every non-callback interface |
76 # that does not have [NoInterfaceObject]. | 76 # that does not have [NoInterfaceObject]. |
77 # Callback interfaces with constants also have interface properties, | 77 # Callback interfaces with constants also have interface properties, |
78 # but there are none of these in Blink. | 78 # but there are none of these in Blink. |
79 # http://heycam.github.io/webidl/#es-interfaces | 79 # http://heycam.github.io/webidl/#es-interfaces |
80 if (is_callback_interface_from_idl(idl_file_contents) or | 80 if (is_callback_interface_from_idl(idl_file_contents) or |
| 81 is_dictionary_from_idl(idl_file_contents) or |
81 'NoInterfaceObject' in extended_attributes): | 82 'NoInterfaceObject' in extended_attributes): |
82 return | 83 return |
83 | 84 |
84 # The [Exposed] extended attribute MUST take an identifier list. Each | 85 # The [Exposed] extended attribute MUST take an identifier list. Each |
85 # identifier in the list MUST be a global name. An interface or interface | 86 # identifier in the list MUST be a global name. An interface or interface |
86 # member the extended attribute applies to will be exposed only on objects | 87 # member the extended attribute applies to will be exposed only on objects |
87 # associated with ECMAScript global environments whose global object | 88 # associated with ECMAScript global environments whose global object |
88 # implements an interface that has a matching global name. | 89 # implements an interface that has a matching global name. |
89 # FIXME: In spec names are comma-separated, but that makes parsing very | 90 # FIXME: In spec names are comma-separated, but that makes parsing very |
90 # difficult (https://www.w3.org/Bugs/Public/show_bug.cgi?id=24959). | 91 # difficult (https://www.w3.org/Bugs/Public/show_bug.cgi?id=24959). |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 constructors = interface_name_to_constructors(interface_name) | 176 constructors = interface_name_to_constructors(interface_name) |
176 write_global_constructors_partial_interface( | 177 write_global_constructors_partial_interface( |
177 interface_name, | 178 interface_name, |
178 idl_filename, | 179 idl_filename, |
179 constructors, | 180 constructors, |
180 options.write_file_only_if_changed) | 181 options.write_file_only_if_changed) |
181 | 182 |
182 | 183 |
183 if __name__ == '__main__': | 184 if __name__ == '__main__': |
184 sys.exit(main()) | 185 sys.exit(main()) |
OLD | NEW |