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

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

Issue 299203002: Support per-overload [RuntimeEnabled] extended attribute (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 7 months 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 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 code + 177 code +
178 '#endif // %s\n' % conditional_string) 178 '#endif // %s\n' % conditional_string)
179 179
180 180
181 # [RuntimeEnabled] 181 # [RuntimeEnabled]
182 def runtime_enabled_if(code, runtime_enabled_function_name): 182 def runtime_enabled_if(code, runtime_enabled_function_name):
183 if not runtime_enabled_function_name: 183 if not runtime_enabled_function_name:
184 return code 184 return code
185 # Indent if statement to level of original code 185 # Indent if statement to level of original code
186 indent = re.match(' *', code).group(0) 186 indent = re.match(' *', code).group(0)
187 return ('%sif (%s())\n' % (indent, runtime_enabled_function_name) + 187 lines = code.splitlines()
188 ' %s' % code) 188 if len(lines) > 1:
Nils Barth (inactive) 2014/05/27 06:33:20 It's fine to always use a { } block, so you can el
189 fmt = '%(indent)sif (%(fnname)s()) {\n %(code)s\n%(indent)s}\n'
Nils Barth (inactive) 2014/05/27 06:33:20 Could you use string concatenation and split the s
190 else:
191 fmt = '%(indent)sif (%(fnname)s())\n %(code)s\n'
192 return fmt % {
Nils Barth (inactive) 2014/05/27 06:33:20 Could you use str.format instead of % with a dict?
193 'indent': indent,
194 'fnname': runtime_enabled_function_name,
195 'code': '\n '.join(lines),
196 }
189 197
190 198
191 ################################################################################ 199 ################################################################################
192 200
193 def main(argv): 201 def main(argv):
194 # If file itself executed, cache templates 202 # If file itself executed, cache templates
195 try: 203 try:
196 cache_dir = argv[1] 204 cache_dir = argv[1]
197 dummy_filename = argv[2] 205 dummy_filename = argv[2]
198 except IndexError as err: 206 except IndexError as err:
(...skipping 10 matching lines...) Expand all
209 217
210 # Create a dummy file as output for the build system, 218 # Create a dummy file as output for the build system,
211 # since filenames of individual cache files are unpredictable and opaque 219 # since filenames of individual cache files are unpredictable and opaque
212 # (they are hashes of the template path, which varies based on environment) 220 # (they are hashes of the template path, which varies based on environment)
213 with open(dummy_filename, 'w') as dummy_file: 221 with open(dummy_filename, 'w') as dummy_file:
214 pass # |open| creates or touches the file 222 pass # |open| creates or touches the file
215 223
216 224
217 if __name__ == '__main__': 225 if __name__ == '__main__':
218 sys.exit(main(sys.argv)) 226 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/scripts/v8_interface.py » ('j') | Source/bindings/scripts/v8_interface.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698