From db4da68618e8896cffa6b5164991308029160eb4 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Thu, 26 Mar 2020 10:03:17 +0300 Subject: [PATCH] Base: Add a man page for js(1) This also changes --ast-dump to --dump-ast, because I like it better and that is what the variable is actually called. --- Base/usr/share/man/man1/js.md | 45 +++++++++++++++++++++++++++++++++++ Userland/js.cpp | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 Base/usr/share/man/man1/js.md diff --git a/Base/usr/share/man/man1/js.md b/Base/usr/share/man/man1/js.md new file mode 100644 index 0000000000..1680e42f1d --- /dev/null +++ b/Base/usr/share/man/man1/js.md @@ -0,0 +1,45 @@ +## Name + +js - evaluate JavaScript + +## Synopsis + +```**sh +$ js [options...] [script.js] +``` + +## Description + +`js` evaluates JavaScript programs using the LibJS engine. If you pass it a path +to a script file, it will execute that script. Otherwise, it enters the +Read-Eval-Print-Loop (REPL) mode, where it interactively reads pieces (usually, +single lines) of code from standard input, evaluates them in one shared +interpreter context, and prints back their results. This mode is useful for +quickly experimenting with LibJS. + +## Options + +* `-A`, `--dump-ast`: Dump the Abstract Syntax Tree after parsing the program. +* `-l`, `--print-last-result`: Print the result of the last statement executed. +* `-g`, `--gc-on-every-allocation`: Run garbage collection on every allocation. + +## Examples + +Here's how you execute a script: + +```sh +$ js ~/js/type-play.js +``` + +And here's an example of an interactive REPL session: + +```js +$ js +> function log_sum(a, b) { +. console.log(a + b) +. } +[object ScriptFunction] +> log_sum(35, 42) +77 +undefined +``` diff --git a/Userland/js.cpp b/Userland/js.cpp index c3db8206b5..f13cb9204b 100644 --- a/Userland/js.cpp +++ b/Userland/js.cpp @@ -115,7 +115,7 @@ int main(int argc, char** argv) const char* script_path = nullptr; Core::ArgsParser args_parser; - args_parser.add_option(dump_ast, "Dump the AST", "ast-dump", 'A'); + args_parser.add_option(dump_ast, "Dump the AST", "dump-ast", 'A'); args_parser.add_option(print_last_result, "Print last result", "print-last-result", 'l'); args_parser.add_option(gc_on_every_allocation, "GC on every allocation", "gc-on-every-allocation", 'g'); args_parser.add_positional_argument(script_path, "Path to script file", "script", Core::ArgsParser::Required::No);