| 1 | = JSC = |
| 2 | {{{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. |
| 3 | |
| 4 | {{{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. |
| 5 | |
| 6 | == Usage == |
| 7 | === Command Line Flags === |
| 8 | {{{ |
| 9 | Usage: jsc [options] [files] [-- arguments] |
| 10 | -d Dumps bytecode (debug builds only) |
| 11 | -e Evaluate argument as script code |
| 12 | -f Specifies a source file (deprecated) |
| 13 | -h|--help Prints this help message |
| 14 | -i Enables interactive mode (default if no files are specified) |
| 15 | -s Installs signal handlers that exit on a crash (Unix platforms only) |
| 16 | }}} |
| 17 | |
| 18 | === Built-In Functions === |
| 19 | * {{{quit()}}} Quit the interpreter |
| 20 | |
| 21 | |
| 22 | == Examples == |
| 23 | You can use {{{jsc}}} as a calculator: |
| 24 | {{{ |
| 25 | $ ./jsc |
| 26 | > "hello" |
| 27 | hello |
| 28 | > 1 + 3 |
| 29 | 4 |
| 30 | > 2 * Math.sin(32) |
| 31 | 1.1028533624833812 |
| 32 | > 2 * Math.floor(1.2) |
| 33 | 2 |
| 34 | > 2 * Math.ceil(1.2) |
| 35 | 4 |
| 36 | > 15.3 / 18 * 27.1 * (Math.ceil(1.3) * Math.exp(2.3) * Math.log (1.223) * Math.sin(32.22)) |
| 37 | 66.6192983328985 |
| 38 | > |
| 39 | }}} |
| 40 | |
| 41 | You can also test more complicated expressions: |
| 42 | {{{ |
| 43 | > var add3 = function(arg) { return arg + 3; } |
| 44 | undefined |
| 45 | > add3(3) |
| 46 | 6 |
| 47 | > |
| 48 | }}} |
| 49 | |