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

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

Issue 424163002: Enable the WebIDL [Exposed] annotation on an interface's members. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: missed renames Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « Source/bindings/core/v8/V8WindowShell.cpp ('k') | Source/bindings/scripts/v8_attributes.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 # 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 loader=jinja2.FileSystemLoader(templates_dir), 232 loader=jinja2.FileSystemLoader(templates_dir),
233 # Bytecode cache is not concurrency-safe unless pre-cached: 233 # Bytecode cache is not concurrency-safe unless pre-cached:
234 # if pre-cached this is read-only, but writing creates a race condition. 234 # if pre-cached this is read-only, but writing creates a race condition.
235 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir), 235 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir),
236 keep_trailing_newline=True, # newline-terminate generated files 236 keep_trailing_newline=True, # newline-terminate generated files
237 lstrip_blocks=True, # so can indent control flow tags 237 lstrip_blocks=True, # so can indent control flow tags
238 trim_blocks=True) 238 trim_blocks=True)
239 jinja_env.filters.update({ 239 jinja_env.filters.update({
240 'blink_capitalize': capitalize, 240 'blink_capitalize': capitalize,
241 'conditional': conditional_if_endif, 241 'conditional': conditional_if_endif,
242 'exposed': exposed_if,
243 'per_context_enabled': per_context_enabled_if,
242 'runtime_enabled': runtime_enabled_if, 244 'runtime_enabled': runtime_enabled_if,
243 }) 245 })
244 return jinja_env 246 return jinja_env
245 247
246 248
249 def generate_indented_conditional(code, conditional):
250 # Indent if statement to level of original code
251 indent = re.match(' *', code).group(0)
252 return ('%sif (%s) {\n' % (indent, conditional) +
253 ' %s\n' % '\n '.join(code.splitlines()) +
254 '%s}\n' % indent)
255
256
247 # [Conditional] 257 # [Conditional]
248 def conditional_if_endif(code, conditional_string): 258 def conditional_if_endif(code, conditional_string):
249 # Jinja2 filter to generate if/endif directive blocks 259 # Jinja2 filter to generate if/endif directive blocks
250 if not conditional_string: 260 if not conditional_string:
251 return code 261 return code
252 return ('#if %s\n' % conditional_string + 262 return ('#if %s\n' % conditional_string +
253 code + 263 code +
254 '#endif // %s\n' % conditional_string) 264 '#endif // %s\n' % conditional_string)
255 265
256 266
267 # [Exposed]
268 def exposed_if(code, exposed_test):
269 if not exposed_test:
270 return code
271 return generate_indented_conditional(code, 'context && (%s)' % exposed_test)
272
273
274 # [PerContextEnabled]
275 def per_context_enabled_if(code, per_context_enabled_function):
276 if not per_context_enabled_function:
277 return code
278 return generate_indented_conditional(code, 'context && context->isDocument() && %s(toDocument(context))' % per_context_enabled_function)
279
280
257 # [RuntimeEnabled] 281 # [RuntimeEnabled]
258 def runtime_enabled_if(code, runtime_enabled_function_name): 282 def runtime_enabled_if(code, runtime_enabled_function_name):
259 if not runtime_enabled_function_name: 283 if not runtime_enabled_function_name:
260 return code 284 return code
261 # Indent if statement to level of original code 285 return generate_indented_conditional(code, '%s()' % runtime_enabled_function _name)
262 indent = re.match(' *', code).group(0)
263 return ('%sif (%s()) {\n' % (indent, runtime_enabled_function_name) +
264 ' %s\n' % '\n '.join(code.splitlines()) +
265 '%s}\n' % indent)
266 286
267 287
268 ################################################################################ 288 ################################################################################
269 289
270 def main(argv): 290 def main(argv):
271 # If file itself executed, cache templates 291 # If file itself executed, cache templates
272 try: 292 try:
273 cache_dir = argv[1] 293 cache_dir = argv[1]
274 dummy_filename = argv[2] 294 dummy_filename = argv[2]
275 except IndexError as err: 295 except IndexError as err:
(...skipping 10 matching lines...) Expand all
286 306
287 # Create a dummy file as output for the build system, 307 # Create a dummy file as output for the build system,
288 # since filenames of individual cache files are unpredictable and opaque 308 # since filenames of individual cache files are unpredictable and opaque
289 # (they are hashes of the template path, which varies based on environment) 309 # (they are hashes of the template path, which varies based on environment)
290 with open(dummy_filename, 'w') as dummy_file: 310 with open(dummy_filename, 'w') as dummy_file:
291 pass # |open| creates or touches the file 311 pass # |open| creates or touches the file
292 312
293 313
294 if __name__ == '__main__': 314 if __name__ == '__main__':
295 sys.exit(main(sys.argv)) 315 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/V8WindowShell.cpp ('k') | Source/bindings/scripts/v8_attributes.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698