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://www.chromium.org/blink/webidl/blink-idl-extended-attributes#TOC-GlobalCon
text-i- | 14 http://heycam.github.io/webidl/#Global |
| 15 http://heycam.github.io/webidl/#Exposed |
15 | 16 |
16 Design document: http://www.chromium.org/developers/design-documents/idl-build | 17 Design document: http://www.chromium.org/developers/design-documents/idl-build |
17 """ | 18 """ |
18 | 19 |
19 import optparse | 20 import optparse |
20 import os | 21 import os |
21 import re | 22 import re |
22 import sys | 23 import sys |
23 | 24 |
24 from utilities import get_file_contents, write_file, get_interface_extended_attr
ibutes_from_idl, is_callback_interface_from_idl | 25 from utilities import get_file_contents, write_file, get_interface_extended_attr
ibutes_from_idl, is_callback_interface_from_idl |
(...skipping 16 matching lines...) Expand all Loading... |
41 | 42 |
42 if options.idl_files_list is None: | 43 if options.idl_files_list is None: |
43 parser.error('Must specify a file listing IDL files using --idl-files-li
st.') | 44 parser.error('Must specify a file listing IDL files using --idl-files-li
st.') |
44 if options.write_file_only_if_changed is None: | 45 if options.write_file_only_if_changed is None: |
45 parser.error('Must specify whether output files are only written if chan
ged using --write-file-only-if-changed.') | 46 parser.error('Must specify whether output files are only written if chan
ged using --write-file-only-if-changed.') |
46 options.write_file_only_if_changed = bool(options.write_file_only_if_changed
) | 47 options.write_file_only_if_changed = bool(options.write_file_only_if_changed
) |
47 | 48 |
48 return options, args | 49 return options, args |
49 | 50 |
50 | 51 |
| 52 # Global name: http://heycam.github.io/webidl/#dfn-global-name |
| 53 # FIXME: We should add support for [Global=xx] extended attribute instead of |
| 54 # hard-coding this mapping. |
| 55 def global_name_to_interface_name(global_name): |
| 56 if global_name.endswith('Worker'): |
| 57 return global_name + 'GlobalScope' |
| 58 return global_name |
| 59 |
| 60 |
51 def record_global_constructors(idl_filename): | 61 def record_global_constructors(idl_filename): |
52 interface_name, _ = os.path.splitext(os.path.basename(idl_filename)) | 62 interface_name, _ = os.path.splitext(os.path.basename(idl_filename)) |
53 full_path = os.path.realpath(idl_filename) | 63 full_path = os.path.realpath(idl_filename) |
54 idl_file_contents = get_file_contents(full_path) | 64 idl_file_contents = get_file_contents(full_path) |
55 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co
ntents) | 65 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co
ntents) |
56 | 66 |
57 # An interface property is produced for every non-callback interface | 67 # An interface property is produced for every non-callback interface |
58 # that does not have [NoInterfaceObject]. | 68 # that does not have [NoInterfaceObject]. |
59 # Callback interfaces with constants also have interface properties, | 69 # Callback interfaces with constants also have interface properties, |
60 # but there are none of these in Blink. | 70 # but there are none of these in Blink. |
61 # http://heycam.github.io/webidl/#es-interfaces | 71 # http://heycam.github.io/webidl/#es-interfaces |
62 if (is_callback_interface_from_idl(idl_file_contents) or | 72 if (is_callback_interface_from_idl(idl_file_contents) or |
63 'NoInterfaceObject' in extended_attributes): | 73 'NoInterfaceObject' in extended_attributes): |
64 return | 74 return |
65 | 75 |
66 global_contexts = extended_attributes.get('GlobalContext', 'Window').split('
&') | 76 # FIXME: In spec names are comma-separated, but that makes parsing very |
| 77 # difficult (https://www.w3.org/Bugs/Public/show_bug.cgi?id=24959). |
| 78 global_names = extended_attributes.get('Exposed', 'Window').split('&') |
67 new_constructors_list = generate_global_constructors_list(interface_name, ex
tended_attributes) | 79 new_constructors_list = generate_global_constructors_list(interface_name, ex
tended_attributes) |
68 for interface_name in global_contexts: | 80 for global_name in global_names: |
| 81 interface_name = global_name_to_interface_name(global_name) |
69 global_objects[interface_name]['constructors'].extend(new_constructors_l
ist) | 82 global_objects[interface_name]['constructors'].extend(new_constructors_l
ist) |
70 | 83 |
71 | 84 |
72 def generate_global_constructors_list(interface_name, extended_attributes): | 85 def generate_global_constructors_list(interface_name, extended_attributes): |
73 extended_attributes_list = [ | 86 extended_attributes_list = [ |
74 name + '=' + extended_attributes[name] | 87 name + '=' + extended_attributes[name] |
75 for name in 'Conditional', 'PerContextEnabled', 'RuntimeEnabled' | 88 for name in 'Conditional', 'PerContextEnabled', 'RuntimeEnabled' |
76 if name in extended_attributes] | 89 if name in extended_attributes] |
77 if extended_attributes_list: | 90 if extended_attributes_list: |
78 extended_string = '[%s] ' % ', '.join(extended_attributes_list) | 91 extended_string = '[%s] ' % ', '.join(extended_attributes_list) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 for interface_name, global_object in global_objects.iteritems(): | 154 for interface_name, global_object in global_objects.iteritems(): |
142 write_global_constructors_partial_interface( | 155 write_global_constructors_partial_interface( |
143 interface_name, | 156 interface_name, |
144 global_object['idl_filename'], | 157 global_object['idl_filename'], |
145 global_object['constructors'], | 158 global_object['constructors'], |
146 options.write_file_only_if_changed) | 159 options.write_file_only_if_changed) |
147 | 160 |
148 | 161 |
149 if __name__ == '__main__': | 162 if __name__ == '__main__': |
150 sys.exit(main()) | 163 sys.exit(main()) |
OLD | NEW |