The Command LineXPCShell is fairly simple to use. To start it up and have it present a prompt simple execute xpcshell. The options are fairly simple. The command line syntax is: usage: xpcshell [-s] [-w] [-W] [-v version] [-f scriptfile] [scriptfile] [scriptarg...]
-fThis option specifies a script file to execute. It's currently slightly broken. It was supposed to present the JS command prompt when the script has completed. It currently exits the program. You can specify multiple JS files to execute by using multiple –f arguments. The scripts will be executed in the order encountered. Also XPCShell looks for xpcshell.js in the current directory. If that file is found it is executed before any other JS files specified.
-v versionThis allows you to specify a specific version of JS to use. Essentially it calls JS_SetVersion, see the JS documentation for more details.
[scriptfile]This is the file name of the script to execute
[scriptarg…]These are arguments to be passed to the script. These arguments are only passed to “scriptfile” and not the scripts designated by –f options. These arguments appear on the global property "arguments".
for (prop in arguments)
print(prop + "=" + arguments[prop]);
xpcshell test.js This is a testWill output:
Once you execute XPCShell without a script you'll be at the JS>
command line. The following are some useful functions that can be invoked
from the command line:
clearClear removes properties from an object. So say you created anObject with a property named value and then called clear(anObject); the property value would no longer exist.
gcgc will invoke garbage collection. It takes an argument that can be used to dump the heap to. The argument is optional but if specified should equate to a valid file name.
loadLoad allows you to load and run a script from the command line. For example load("MyScript.js"); will execute the script MyScript.js in the current directory.
dumpDump is almost like print. It only handles one parameter and it doesn't append a newline.
dumpXPCThis function dumps the XPConnect object. See the documentation on debugDump for the nsIXPConnect interface for more information. This function takes one parameter for the depth.
quitQuit exits the shell. You can specify arguments that will get translated to an exit code. quit(5) will exit XPCShell with a result code of 5.
Flames/suggestions:David Bradley <email@example.com>
Author: David Bradley <firstname.lastname@example.org>
Last modified: 17 March 2003