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

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

Issue 771323004: Expose Fetch API related classes to Window and WorkerGlobalScope. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@exposed-runtime-enabled
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(',')
90 # Blink has Exposed(Arguments) form. In the form, each argument type
91 # represents the global context.
92 exposed_global_names = [name.split(' ')[0] for name in exposed_global_names]
93 90
94 new_constructors_list = generate_global_constructors_list(interface_name, ex tended_attributes) 91 exposed_arguments = get_interface_exposed_arguments(idl_file_contents)
95 for exposed_global_name in exposed_global_names: 92 if exposed_global_names == ['Window'] and exposed_arguments is not None:
96 global_name_to_constructors[exposed_global_name].extend(new_constructors _list) 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)
97 104
98 105
99 def generate_global_constructors_list(interface_name, extended_attributes): 106 def generate_global_constructors_list(interface_name, extended_attributes):
100 extended_attributes_list = [ 107 extended_attributes_list = [
101 name + '=' + extended_attributes[name] 108 name + '=' + extended_attributes[name]
102 for name in 'Conditional', 'PerContextEnabled', 'RuntimeEnabled' 109 for name in 'Conditional', 'PerContextEnabled', 'RuntimeEnabled'
103 if name in extended_attributes] 110 if name in extended_attributes]
104 if extended_attributes_list: 111 if extended_attributes_list:
105 extended_string = '[%s] ' % ', '.join(extended_attributes_list) 112 extended_string = '[%s] ' % ', '.join(extended_attributes_list)
106 else: 113 else:
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 constructors = interface_name_to_constructors(interface_name) 184 constructors = interface_name_to_constructors(interface_name)
178 write_global_constructors_partial_interface( 185 write_global_constructors_partial_interface(
179 interface_name, 186 interface_name,
180 idl_filename, 187 idl_filename,
181 constructors, 188 constructors,
182 options.write_file_only_if_changed) 189 options.write_file_only_if_changed)
183 190
184 191
185 if __name__ == '__main__': 192 if __name__ == '__main__':
186 sys.exit(main()) 193 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698