Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

XPCShell Reference

The Command Line

The command-line syntax for xpcshell is:

xpcshell [-s] [-w] [-W] [-v version] [-f scriptfile] [scriptfile] [scriptarg...]
-C
This option turns on the "compile-only" mode. (Setting this option disables the "Interactive" mode)
-f
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.
-g
This option specifies which Gecko Runtime Environment directory (greDir) to use for XPCOM.
-i
This option turns on the "interactive" mode
-s
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.
-x
This option toggles the XML option on and off. By default it is off.
[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 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
0=This
1=is
2=a
3=test

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(object)
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(heapDumpFilename)
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(scriptFilename)
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(object)
dump() is almost like print. It only handles one parameter and it doesn't append a newline.
dumpXPC(depth)
This function dumps the XPConnect object. See the documentation on debugDump() for the nsIXPConnect interface for more information.
version(newVersion)
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(exitCode)
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.

Original Document Information

  • Author: David Bradley <[email protected]>
  • 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.

Document Tags and Contributors

 Contributors to this page: teoli, Fredinfinite23, Varmaa
 Last updated by: Fredinfinite23,