jsc
is a command-line utility that allows you to run JavaScript programs outside of the context of a web browser. It is primarily used as part of the test harness for validating the JavaScript portions of WebKit, but can also be used as a scripting tool.
jsc
can be run in an interactive mode to test out JavaScript expressions, or it can be passed one or more files to run similar to invoking a Perl or Python script.
Usage: jsc [options] [files] [-- arguments] -d Dumps bytecode (debug builds only) -e Evaluate argument as script code -f Specifies a source file (deprecated) -h|--help Prints this help message -i Enables interactive mode (default if no files are specified) -s Installs signal handlers that exit on a crash (Unix platforms only) -p <file> Outputs profiling data to a file -x Output exit code before terminating --options Dumps all JSC VM options and exits --dumpOptions Dumps all JSC VM options before continuing --<jsc VM option>=<value> Sets the specified JSC VM option
checkSyntax('[FileName]')
[FileName]
.debug(term)
gc()
undefined
.load('[FileName]')
[FileName]
. If the run is successful, it will return the final value of the script.quit()
readline()
run('[FileName]')
[FileName]
. If the run is successful, it will return the elapsed milliseconds for the run.version()
undefined
.You can usejsc
as a calculator:
$ ./jsc> "hello"hello> 1 + 34> 2 * Math.sin(32)1.1028533624833812> 2 * Math.floor(1.2)2> 2 * Math.ceil(1.2)4> 15.3 / 18 * 27.1 * (Math.ceil(1.3) * Math.exp(2.3) * Math.log (1.223) * Math.sin(32.22))66.6192983328985> quit()
You can also test more complicated expressions:
> var add3 = function(arg) { return arg + 3; }undefined> add3(3)6> var foo = readline();abcdefgundefined> fooabcdefg> quit()
The return value ofundefined
from the variable assignment is from the JavaScript specification. While it might seem like an odd response to a successful operation, it is the expected behavior.