Pass command-line arguments to script in V8 Javascript shell
I'm trying to run JSLint via V8.
- I downloaded and built the V8 shell using these instructions.
- The interactive shell
d8
works, and passing a file to it executes that file.
Now I want to execute jslint.js
and pass the name of the file to parse to it. I have tried
d8 jslint.js myfile.js
d8 jslint.js < myfile.js
d8 jslint.js -- myfile.js
No doubt the trouble lines in the end of jslint.js which uses the Rhino readline()
function to get the command-line ar开发者_如何学Cguments. Has anyone modified this script to work in V8 or is there a generic way to have V8 pass arguments to it?
Update: Steve's answer reminded me that I did find a way to compile JSLint into an executable much as Steve did, but I was hoping for something that was a little more portable for the other developers.
The d8 shell allows you to pass arguments on the command line by preceding them by '--'. I.e., in your case:
d8 jslint.js -- myfile.js
Everthing after '--' will be read as verbatim strings, so all other flags must go before that. The command line arguments will be available to scripts as a global variable called "arguments" holding an array of strings.
(Instead of '--' you can use the synonymous '--js-arguments').
You could possibly have a look at my attempt to run JSLint using v8 at http://blog.stevenreid.co.uk/2011/06/27/jslint-command-line-tool-powered-by-v8/.
The command line application compiles JSLint directly into the binary. All JSlint options are supported. Multiple source files can be linted as well as input from stdin.
精彩评论