You are not logged in.
I'm now learning JavaScript. Since I'm used to C/Python/Java (where you can build & run codes from command line) and sometimes a bit lazy to fire the browser up, therefore I use d8 and rhino.
Now let's say I have this code:
var len = arguments.length;
print("arg len: "+ len);
for (var x = 0; x < len; x++){
print("arg["+x+"]: "+arguments[x]);
}
If I run that using rhino:
java -jar /usr/share/java/js.jar test.js hello world "foo bar" "1 2 3 4"
The result is:
arg len: 4
arg[0]: hello
arg[1]: world
arg[2]: foo bar
arg[3]: 1 2 3 4
Which is correct, as expected. But if I run that code using d8:
d8 test.js hello world "foo bar" "1 2 3 4"
The result is:
d8 test.js hello world "foo bar" "1 2 3 4"
arg len: 0
hello:1: SyntaxError: Unexpected token ILLEGAL
ELF
^
SyntaxError: Unexpected token ILLEGAL
I'm confused.
Offline
It looks like d8 is trying to open a file called hello, which is probably an ELF executable. I guess that's not how d8 passes arguments to scripts.
Offline
d8 doesn't allow passing arguments to scripts, it simply runs everything given as scripts, eg file1 file2 file3. you can either use js, if you don't want the java dependencies of rhino, or use nodejs, which uses the v8 engine.
quick edit: d8 uses the --js_arguments flag to pass options to the script. without the flag it tries to read everything give as a js file
Last edited by rickeyski (2012-04-18 23:10:21)
Offline