| OLD | NEW |
| 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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 # Bytecode cache is not concurrency-safe unless pre-cached: | 420 # Bytecode cache is not concurrency-safe unless pre-cached: |
| 421 # if pre-cached this is read-only, but writing creates a race condition. | 421 # if pre-cached this is read-only, but writing creates a race condition. |
| 422 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir), | 422 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir), |
| 423 keep_trailing_newline=True, # newline-terminate generated files | 423 keep_trailing_newline=True, # newline-terminate generated files |
| 424 lstrip_blocks=True, # so can indent control flow tags | 424 lstrip_blocks=True, # so can indent control flow tags |
| 425 trim_blocks=True) | 425 trim_blocks=True) |
| 426 jinja_env.filters.update({ | 426 jinja_env.filters.update({ |
| 427 'blink_capitalize': capitalize, | 427 'blink_capitalize': capitalize, |
| 428 'exposed': exposed_if, | 428 'exposed': exposed_if, |
| 429 'for_origin_trial_feature': for_origin_trial_feature, | 429 'for_origin_trial_feature': for_origin_trial_feature, |
| 430 'secure_context': secure_context_if, |
| 430 'runtime_enabled': runtime_enabled_if, | 431 'runtime_enabled': runtime_enabled_if, |
| 431 'unique_by': unique_by, | 432 'unique_by': unique_by, |
| 432 }) | 433 }) |
| 433 jinja_env.filters.update(attribute_filters()) | 434 jinja_env.filters.update(attribute_filters()) |
| 434 jinja_env.filters.update(v8_interface.constant_filters()) | 435 jinja_env.filters.update(v8_interface.constant_filters()) |
| 435 jinja_env.filters.update(method_filters()) | 436 jinja_env.filters.update(method_filters()) |
| 436 return jinja_env | 437 return jinja_env |
| 437 | 438 |
| 438 | 439 |
| 439 def generate_indented_conditional(code, conditional): | 440 def generate_indented_conditional(code, conditional): |
| 440 # Indent if statement to level of original code | 441 # Indent if statement to level of original code |
| 441 indent = re.match(' *', code).group(0) | 442 indent = re.match(' *', code).group(0) |
| 442 return ('%sif (%s) {\n' % (indent, conditional) + | 443 return ('%sif (%s) {\n' % (indent, conditional) + |
| 443 ' %s\n' % '\n '.join(code.splitlines()) + | 444 ' %s\n' % '\n '.join(code.splitlines()) + |
| 444 '%s}\n' % indent) | 445 '%s}\n' % indent) |
| 445 | 446 |
| 446 | 447 |
| 447 # [Exposed] | 448 # [Exposed] |
| 448 def exposed_if(code, exposed_test): | 449 def exposed_if(code, exposed_test): |
| 449 if not exposed_test: | 450 if not exposed_test: |
| 450 return code | 451 return code |
| 451 return generate_indented_conditional(code, 'executionContext && (%s)' % expo
sed_test) | 452 return generate_indented_conditional(code, 'executionContext && (%s)' % expo
sed_test) |
| 452 | 453 |
| 453 | 454 |
| 455 # [SecureContext] |
| 456 def secure_context_if(code, secure_context_test): |
| 457 if not secure_context_test: |
| 458 return code |
| 459 return generate_indented_conditional(code, 'executionContext && (%s)' % secu
re_context_test) |
| 460 |
| 461 |
| 454 # [RuntimeEnabled] | 462 # [RuntimeEnabled] |
| 455 def runtime_enabled_if(code, runtime_enabled_function_name): | 463 def runtime_enabled_if(code, runtime_enabled_function_name): |
| 456 if not runtime_enabled_function_name: | 464 if not runtime_enabled_function_name: |
| 457 return code | 465 return code |
| 458 return generate_indented_conditional(code, '%s()' % runtime_enabled_function
_name) | 466 return generate_indented_conditional(code, '%s()' % runtime_enabled_function
_name) |
| 459 | 467 |
| 460 | 468 |
| 461 ################################################################################ | 469 ################################################################################ |
| 462 | 470 |
| 463 def main(argv): | 471 def main(argv): |
| (...skipping 15 matching lines...) Expand all Loading... |
| 479 | 487 |
| 480 # Create a dummy file as output for the build system, | 488 # Create a dummy file as output for the build system, |
| 481 # since filenames of individual cache files are unpredictable and opaque | 489 # since filenames of individual cache files are unpredictable and opaque |
| 482 # (they are hashes of the template path, which varies based on environment) | 490 # (they are hashes of the template path, which varies based on environment) |
| 483 with open(dummy_filename, 'w') as dummy_file: | 491 with open(dummy_filename, 'w') as dummy_file: |
| 484 pass # |open| creates or touches the file | 492 pass # |open| creates or touches the file |
| 485 | 493 |
| 486 | 494 |
| 487 if __name__ == '__main__': | 495 if __name__ == '__main__': |
| 488 sys.exit(main(sys.argv)) | 496 sys.exit(main(sys.argv)) |
| OLD | NEW |