2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Embeds standalone JavaScript snippets in C++ code.
8 Each argument to the script must be a file containing an associated JavaScript
9 function (e.g., evaluate_script.js should contain an evaluateScript function).
10 This is called the exported function of the script. The entire script will be
11 put into a C-style string in the form of an anonymous function which invokes
12 the exported function when called.
23 parser
= optparse
.OptionParser()
25 '', '--directory', type='string', default
='.',
26 help='Path to directory where the cc/h js file should be created')
27 options
, args
= parser
.parse_args()
29 global_string_map
= {}
31 base_name
= os
.path
.basename(js_file
)[:-3].title().replace('_', '')
32 func_name
= base_name
[0].lower() + base_name
[1:]
33 script_name
= 'k%sScript' % base_name
34 with
open(js_file
, 'r') as f
:
36 script
= 'function() { %s; return %s.apply(null, arguments) }' % (
38 global_string_map
[script_name
] = script
40 cpp_source
.WriteSource('js', 'chrome/test/chromedriver/chrome',
41 options
.directory
, global_string_map
)
44 if __name__
== '__main__':