Base: Update js(1) manpage
- Include all options - Update example REPL session to match current output - Mention REPL's help() - Add test mode section
This commit is contained in:
parent
afdba94f63
commit
440f017946
Notes:
sideshowbarker
2024-07-19 07:28:24 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/440f0179465 Pull-request: https://github.com/SerenityOS/serenity/pull/1870
1 changed files with 30 additions and 3 deletions
|
@ -17,11 +17,15 @@ single lines) of code from standard input, evaluates them in one shared
|
||||||
interpreter context, and prints back their results. This mode is useful for
|
interpreter context, and prints back their results. This mode is useful for
|
||||||
quickly experimenting with LibJS.
|
quickly experimenting with LibJS.
|
||||||
|
|
||||||
|
Run `help()` in REPL mode to see its available built-in functions.
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
|
||||||
* `-A`, `--dump-ast`: Dump the Abstract Syntax Tree after parsing the program.
|
* `-A`, `--dump-ast`: Dump the Abstract Syntax Tree after parsing the program.
|
||||||
* `-l`, `--print-last-result`: Print the result of the last statement executed.
|
* `-l`, `--print-last-result`: Print the result of the last statement executed.
|
||||||
* `-g`, `--gc-on-every-allocation`: Run garbage collection on every allocation.
|
* `-g`, `--gc-on-every-allocation`: Run garbage collection on every allocation.
|
||||||
|
* `-s`, `--syntax-highlight`: Enable live syntax highlighting in the REPL
|
||||||
|
* `-t`, `--test-mode`: Run the interpreter with added functionality for the test harness
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
@ -36,10 +40,33 @@ And here's an example of an interactive REPL session:
|
||||||
```js
|
```js
|
||||||
$ js
|
$ js
|
||||||
> function log_sum(a, b) {
|
> function log_sum(a, b) {
|
||||||
. console.log(a + b)
|
> console.log(a + b)
|
||||||
. }
|
> }
|
||||||
[object ScriptFunction]
|
undefined
|
||||||
> log_sum(35, 42)
|
> log_sum(35, 42)
|
||||||
77
|
77
|
||||||
undefined
|
undefined
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Test mode
|
||||||
|
|
||||||
|
In test mode, the `load()` function is added to the global object and can be used
|
||||||
|
to load further test utility functions defined in `LibJS/Tests/test-common.js`.
|
||||||
|
|
||||||
|
Typically a test will look like this:
|
||||||
|
|
||||||
|
```js
|
||||||
|
load("test-common.js");
|
||||||
|
|
||||||
|
try {
|
||||||
|
// test feature
|
||||||
|
console.log("PASS");
|
||||||
|
} catch (e) {
|
||||||
|
console.log("FAIL: " + e);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Available functions in `test-common.js`:
|
||||||
|
|
||||||
|
* `assert(expression)`: Throws an `AssertionError` if condition does not evaluate to a truthy value
|
||||||
|
* `assertNotReached()`: Throws an `AssertionError`, use to ensure certain code paths are never reached
|
||||||
|
|
Loading…
Add table
Reference in a new issue