XPCShell Reference

This is an archived page. It's not actively maintained.

The Command Line

The command-line syntax for xpcshell is:

xpcshell [-s] [-w] [-W] [-v version] [-f scriptfile] [scriptfile] [scriptarg...]
This option turns on the "compile-only" mode. (Setting this option disables the "Interactive" mode)
This option specifies a script file to execute. xpcshell terminates upon script completion. You can specify multiple JS files to execute by using multiple -f arguments, and the scripts will be executed in the order encountered.
Furthermore, XPCShell looks for xpcshell.js in the current directory. If that file is found, it is executed before any other JS files specified.
This option specifies which Gecko Runtime Environment directory (greDir) to use for XPCOM.
This option turns on the "interactive" mode
This option toggles the JavaScript strict option on and off. By default it is off.
-v version
This allows you to specify a specific version of JS to use, and should be set to an integral value specified by the JSVersion enumerated type. For instance, specifying -v 180 will set the interpreter to use JavaScript version 1.8.
-w (lower case)
This option turns on JavaScript warnings.
-W (upper case)
This turns off JavaScript warnings. The last option listed is the one that takes effect.
This option toggles the XML option on and off. By default it is off.
This is the file name of the script to execute.
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 instance, assume that you have a file called test.js with the following contents:
for (prop in arguments)
    print(prop + "=" + arguments[prop]);
Entering the following at the command line should produce the following output:
$ xpcshell test.js This is a test

Original Document Information

XPCShell Extensions

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:

clear() removes all properties from an object. For example, if you created anObject with a property named value and then called clear(anObject), the property value would no longer exist.
gc() will invoke garbage collection. It takes an optional argument that can be used to dump the heap to. If specified, it should equate to a valid filename.
load() 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.
print(obj1, obj2, )
print() is useful to print something to the screen. It dumps whatever is passed to the screen, putting spaces between arguments and appending a newline at the end. An example print(1, 2, 3) Will print 1 2 3<newline>.
dump() is almost like print. It only handles one parameter and it doesn't append a newline.
This function dumps the XPConnect object. See the documentation on debugDump() for the nsIXPConnect interface for more information.
version() returns the JavaScript engine version number. If you pass a number to it, it will set the version number (and return the old version number). See the above documentation on the -v command-line argument for more information.
quit() 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.
  • Author: David Bradley <dbradley@netscape.com>
  • Last Updated Date: 17 March 2003
  • Copyright Information: Portions of this content are © 1998–2008 by individual mozilla.org contributors; content available under a Creative Commons license.