2

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 arguments. 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.

Community
  • 1
  • 1
David Harkness
  • 35,992
  • 10
  • 112
  • 134

2 Answers2

3

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').

2

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.

Steve
  • 21
  • 1
  • I was unable to build FOX. The `make` command dies saying it cannot find `-lXext`, `-lGL`, and `-lGLU`. Any ideas? – David Harkness Aug 25 '11 at 17:44
  • Even though the build failed, you should hopefully have the 'reswrap' executable now. That's all that is needed. – Steve Aug 25 '11 at 18:46
  • Okay, now it's complaining that v8preparser.a is incompatible. This is probably because I am running 64-bit and had to specify `--arch=x64` when building v8. Is there a way to pass that to your scons script? The same argument is kicked out by scons. – David Harkness Aug 26 '11 at 00:27
  • Sorry no, the scons script supports 32-bit only atm. – Steve Aug 26 '11 at 05:12
  • Okay no worries. Thanks for the effort. – David Harkness Aug 26 '11 at 18:57