Chromium Code Reviews| 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 har d-coding this mapping. | |
|
Nils Barth (inactive)
2014/05/02 02:49:48
Could you wrap the comment?
(No need to open a bug
Inactive
2014/05/02 03:08:37
Done.
| |
| 54 def global_name_to_interface_name(global_name): | |
| 55 if global_name.endswith('Worker'): | |
| 56 return global_name + 'GlobalScope' | |
| 57 return global_name | |
| 58 | |
| 59 | |
| 51 def record_global_constructors(idl_filename): | 60 def record_global_constructors(idl_filename): |
| 52 interface_name, _ = os.path.splitext(os.path.basename(idl_filename)) | 61 interface_name, _ = os.path.splitext(os.path.basename(idl_filename)) |
| 53 full_path = os.path.realpath(idl_filename) | 62 full_path = os.path.realpath(idl_filename) |
| 54 idl_file_contents = get_file_contents(full_path) | 63 idl_file_contents = get_file_contents(full_path) |
| 55 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co ntents) | 64 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co ntents) |
| 56 | 65 |
| 57 # An interface property is produced for every non-callback interface | 66 # An interface property is produced for every non-callback interface |
| 58 # that does not have [NoInterfaceObject]. | 67 # that does not have [NoInterfaceObject]. |
| 59 # Callback interfaces with constants also have interface properties, | 68 # Callback interfaces with constants also have interface properties, |
| 60 # but there are none of these in Blink. | 69 # but there are none of these in Blink. |
| 61 # http://heycam.github.io/webidl/#es-interfaces | 70 # http://heycam.github.io/webidl/#es-interfaces |
| 62 if (is_callback_interface_from_idl(idl_file_contents) or | 71 if (is_callback_interface_from_idl(idl_file_contents) or |
| 63 'NoInterfaceObject' in extended_attributes): | 72 'NoInterfaceObject' in extended_attributes): |
| 64 return | 73 return |
| 65 | 74 |
| 66 global_contexts = extended_attributes.get('GlobalContext', 'Window').split(' &') | 75 # FIXME: Web IDL says the global names are comma-separated. |
|
Nils Barth (inactive)
2014/05/02 02:49:48
Could you note which that is a problem, and link t
Inactive
2014/05/02 03:08:37
Done.
| |
| 76 global_names = extended_attributes.get('Exposed', 'Window').split('&') | |
| 67 new_constructors_list = generate_global_constructors_list(interface_name, ex tended_attributes) | 77 new_constructors_list = generate_global_constructors_list(interface_name, ex tended_attributes) |
| 68 for interface_name in global_contexts: | 78 for global_name in global_names: |
| 79 interface_name = global_name_to_interface_name(global_name) | |
| 69 global_objects[interface_name]['constructors'].extend(new_constructors_l ist) | 80 global_objects[interface_name]['constructors'].extend(new_constructors_l ist) |
| 70 | 81 |
| 71 | 82 |
| 72 def generate_global_constructors_list(interface_name, extended_attributes): | 83 def generate_global_constructors_list(interface_name, extended_attributes): |
| 73 extended_attributes_list = [ | 84 extended_attributes_list = [ |
| 74 name + '=' + extended_attributes[name] | 85 name + '=' + extended_attributes[name] |
| 75 for name in 'Conditional', 'PerContextEnabled', 'RuntimeEnabled' | 86 for name in 'Conditional', 'PerContextEnabled', 'RuntimeEnabled' |
| 76 if name in extended_attributes] | 87 if name in extended_attributes] |
| 77 if extended_attributes_list: | 88 if extended_attributes_list: |
| 78 extended_string = '[%s] ' % ', '.join(extended_attributes_list) | 89 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(): | 152 for interface_name, global_object in global_objects.iteritems(): |
| 142 write_global_constructors_partial_interface( | 153 write_global_constructors_partial_interface( |
| 143 interface_name, | 154 interface_name, |
| 144 global_object['idl_filename'], | 155 global_object['idl_filename'], |
| 145 global_object['constructors'], | 156 global_object['constructors'], |
| 146 options.write_file_only_if_changed) | 157 options.write_file_only_if_changed) |
| 147 | 158 |
| 148 | 159 |
| 149 if __name__ == '__main__': | 160 if __name__ == '__main__': |
| 150 sys.exit(main()) | 161 sys.exit(main()) |
| OLD | NEW |