A few folks told me that it would be useful to have a proper option
parser for JS going forward, so I made the patch in bug 668095.
I'd like to know which options people actually use, so I can just drop
the other ones. Right now, this is the help text in debug mode (which
automatically formats itself when you add new options -- yay!):
"""
Usage: ./js [options]
The SpiderMonkey shell provides a command line interface to the
JavaScript engine. Code and file options provided via the command
line are run left to right. Just-In-Time compilation modes may be
enabled via command line options.
Version: JavaScript-C 1.8.5+ 2011-04-16
Options:
-f --file=PATH File path to run
-e --execute=CODE Inline code to run
-i --repl Enter prompt after running code
-m --methodjit Enable the JaegerMonkey method JIT
-j --tracejit Enable the JaegerMonkey trace JIT
-p --profiling Enable runtime profiling select JIT mode
-n --type-infer Run the type inferencing engine
-d --debugjit Enable runtime debug mode for method JIT code
-a --always-mjit Do not try to run in the interpreter before
method
jitting. Note that this has no particular
effect on
the tracer; it still kicks in if enabled.
-b --print-timing Print sub-millisecond runtime for each file
that's
run
-A --oom-after=COUNT Trigger OOM after COUNT allocations
-O --print-alloc Print the number of allocations at exit
-Z --gc-zeal=N[,F[,C]] N indicates "zealousness":
0: no additional GCs
1: additional GCs at common danger points
2: GC every F allocations (default: 100)
If C is 1, compartmental GCs are performed;
otherwise, full
-U --utf8 C strings passed to the JSAPI are UTF-8 encoded
"""
Let me know if any useful ones are missing.
- Leary
From bug 668095
>Note that we no longer bind an arguments array on the global object.
Arguments was useful. Any plans to bring them back in some form?
Thanks,
Vassily
I'd love to discuss how best to add it back; although, I'd like to give
it a different identifier binding in the global scope, at least. Would
you mind describing your use case in more detail?
Thanks!
- Leary
I have used arguments to run xpcshell files as scripts, e.g., switching
ports as an option, or telling which script needs to bind port listeners.
My use cases are usual (int argc, char **argv), e.g. specify some
options
for script, like port number, files to process, etc.
JS shell supports #!/usr/bin/js , so I just "chmod a+x script.js" and
run it
from command line, same way as with bash or python or whatever. One
thing I am currently missing is the script name (like argv[0]), but
that's not
very important. Actually, I can live without arguments at all, (/proc/
cmdline),
but that's not portable.
I agree that different identifier makes sense, "arguments" are special
in JS,
and having them in global scope is probably not the best way to do
it.
But I have no ideas for better identifier, "arguments" are just that -
arguments
to script, so I just imagine that script itself is a function.
Thanks for asking,
Vassily
That's a great point, IMO. Added in the latest patch, bound as
scriptArgs on the shell global.
- Leary