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

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
« no previous file with comments | « no previous file | Source/bindings/scripts/idl_definitions.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 '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 exposed_arguments = get_interface_exposed_arguments(idl_file_contents)
85 # identifier in the list MUST be a global name. An interface or interface 85 if exposed_arguments:
86 # member the extended attribute applies to will be exposed only on objects 86 # Exposed(Arguments) case
87 # associated with ECMAScript global environments whose global object 87 for argument in exposed_arguments:
88 # implements an interface that has a matching global name. 88 if 'RuntimeEnabled' in extended_attributes:
89 exposed_global_names = extended_attributes.get('Exposed', 'Window').strip('( )').split(',') 89 raise ValueError('RuntimeEnabled should not be used with Exposed (Arguments)')
90 new_constructors_list = generate_global_constructors_list(interface_name, ex tended_attributes) 90 attributes = extended_attributes.copy()
91 for exposed_global_name in exposed_global_names: 91 attributes['RuntimeEnabled'] = argument['runtime_enabled']
92 global_name_to_constructors[exposed_global_name].extend(new_constructors _list) 92 new_constructors_list = generate_global_constructors_list(interface_ name, attributes)
93 global_name_to_constructors[argument['exposed']].extend(new_construc tors_list)
94 else:
95 # Exposed=env or Exposed=(env1,...) case
96 exposed_global_names = extended_attributes.get('Exposed', 'Window').stri p('()').split(',')
97 new_constructors_list = generate_global_constructors_list(interface_name , extended_attributes)
98 for name in exposed_global_names:
99 global_name_to_constructors[name].extend(new_constructors_list)
93 100
94 101
95 def generate_global_constructors_list(interface_name, extended_attributes): 102 def generate_global_constructors_list(interface_name, extended_attributes):
96 extended_attributes_list = [ 103 extended_attributes_list = [
97 name + '=' + extended_attributes[name] 104 name + '=' + extended_attributes[name]
98 for name in 'Conditional', 'PerContextEnabled', 'RuntimeEnabled' 105 for name in 'Conditional', 'PerContextEnabled', 'RuntimeEnabled'
99 if name in extended_attributes] 106 if name in extended_attributes]
100 if extended_attributes_list: 107 if extended_attributes_list:
101 extended_string = '[%s] ' % ', '.join(extended_attributes_list) 108 extended_string = '[%s] ' % ', '.join(extended_attributes_list)
102 else: 109 else:
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 constructors = interface_name_to_constructors(interface_name) 180 constructors = interface_name_to_constructors(interface_name)
174 write_global_constructors_partial_interface( 181 write_global_constructors_partial_interface(
175 interface_name, 182 interface_name,
176 idl_filename, 183 idl_filename,
177 constructors, 184 constructors,
178 options.write_file_only_if_changed) 185 options.write_file_only_if_changed)
179 186
180 187
181 if __name__ == '__main__': 188 if __name__ == '__main__':
182 sys.exit(main()) 189 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/scripts/idl_definitions.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698