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

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

Issue 789473002: Introduce [Exposed(Arguments)] in IDL code generator. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years 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 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, get_interfac e_exposed_arguments, is_callback_interface_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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 'NoInterfaceObject' in extended_attributes): 81 'NoInterfaceObject' in extended_attributes):
82 return 82 return
83 83
84 # The [Exposed] extended attribute MUST take an identifier list. Each 84 # The [Exposed] extended attribute MUST take an identifier list. Each
85 # identifier in the list MUST be a global name. An interface or interface 85 # 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 86 # member the extended attribute applies to will be exposed only on objects
87 # associated with ECMAScript global environments whose global object 87 # associated with ECMAScript global environments whose global object
88 # implements an interface that has a matching global name. 88 # implements an interface that has a matching global name.
89 exposed_global_names = extended_attributes.get('Exposed', 'Window').strip('( )').split(',') 89 exposed_global_names = extended_attributes.get('Exposed', 'Window').strip('( )').split(',')
Jens Widell 2014/12/09 11:30:31 You could move this line down to line 101 (in the
yhirano 2014/12/09 11:59:13 Done.
90 new_constructors_list = generate_global_constructors_list(interface_name, ex tended_attributes) 90
91 for exposed_global_name in exposed_global_names: 91 exposed_arguments = get_interface_exposed_arguments(idl_file_contents)
92 global_name_to_constructors[exposed_global_name].extend(new_constructors _list) 92 if exposed_global_names == ['Window'] and exposed_arguments is not None:
93 for argument in exposed_arguments:
94 if 'RuntimeEnabled' in extended_attributes:
95 raise ValueError('RuntimeEnabled should not be used with Exposed (Arguments)')
96 attributes = extended_attributes.copy()
97 attributes['RuntimeEnabled'] = argument['runtime_enabled']
98 new_constructors_list = generate_global_constructors_list(interface_ name, attributes)
99 global_name_to_constructors[argument['exposed']].extend(new_construc tors_list)
100 else:
101 new_constructors_list = generate_global_constructors_list(interface_name , extended_attributes)
102 for name in exposed_global_names:
103 global_name_to_constructors[name].extend(new_constructors_list)
93 104
94 105
95 def generate_global_constructors_list(interface_name, extended_attributes): 106 def generate_global_constructors_list(interface_name, extended_attributes):
96 extended_attributes_list = [ 107 extended_attributes_list = [
97 name + '=' + extended_attributes[name] 108 name + '=' + extended_attributes[name]
98 for name in 'Conditional', 'PerContextEnabled', 'RuntimeEnabled' 109 for name in 'Conditional', 'PerContextEnabled', 'RuntimeEnabled'
99 if name in extended_attributes] 110 if name in extended_attributes]
100 if extended_attributes_list: 111 if extended_attributes_list:
101 extended_string = '[%s] ' % ', '.join(extended_attributes_list) 112 extended_string = '[%s] ' % ', '.join(extended_attributes_list)
102 else: 113 else:
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 constructors = interface_name_to_constructors(interface_name) 184 constructors = interface_name_to_constructors(interface_name)
174 write_global_constructors_partial_interface( 185 write_global_constructors_partial_interface(
175 interface_name, 186 interface_name,
176 idl_filename, 187 idl_filename,
177 constructors, 188 constructors,
178 options.write_file_only_if_changed) 189 options.write_file_only_if_changed)
179 190
180 191
181 if __name__ == '__main__': 192 if __name__ == '__main__':
182 sys.exit(main()) 193 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/scripts/idl_definitions.py » ('j') | Source/bindings/scripts/idl_definitions.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698