Search code examples
spidermonkey

jsshell executing external file


i am learning how to use jsshell... i downloaded the latest build for mac here

http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/jsshell-mac.zip

i unzipped, run the shell doing some basic commands like... adding and loops. it runs fine, however when i try to let it run an external file "in the same folder" as the shell i get an error.

js> js loop.js;
typein:6:3 SyntaxError: missing ; before statement:
typein:6:3 js loop.js;
typein:6:3 ...^

there is a file called loop.js in the file folder as the shell which this simple logic

for(var i=1; i<10; i++){
    print(i);
}

Can someone please tell me what i am doing wrong?

More updates...when i run it from the main folder, like this

./js loop.js

it works. by ./js i am executing the unix file. however when i am in the jsshell prompt. i can run js loop.js


Solution

  • Inside the jsshell command prompt, you should use load("loop.js"). If the code within the file is not inside a function like yours, they'll be executed immediately.