You are not logged in.

#1 2012-04-17 17:31:34

anta40
Member
From: Jakarta, Indonesia
Registered: 2010-03-01
Posts: 79

Cannot run Javascript file using d8?

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

#2 2012-04-17 19:11:55

tavianator
Member
From: Waterloo, ON, Canada
Registered: 2007-08-21
Posts: 859
Website

Re: Cannot run Javascript file using d8?

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

#3 2012-04-18 23:06:52

rickeyski
Member
Registered: 2011-01-27
Posts: 25

Re: Cannot run Javascript file using d8?

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

Board footer

Powered by FluxBB