You are currently viewing a snapshot of taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to, please file a bug.

XPCShell Reference

The Command Line

XPCShell 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...]


This 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.


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. Essentially it calls JS_SetVersion, see the JS documentation for more details.

-w (lower case)

This option turns on JavaScript warnings

-W (upper case)

This turns off JavaScript warnings. The last option seen is the one that wins.


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".

Script: test.js
for (prop in arguments)
    print(prop + "=" + arguments[prop]);

xpcshell test.js This is a test
Will output:

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 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.


gc 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.


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 is useful to print something to the screen. It dumps whatever passed to the screen. It can take multiple arguments as well. An example print(1, 2 , 3); Will print 1 2 3. NOTE: It puts spaces between things separated by commas and appends a newline at the end.


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. This function takes one parameter for the depth.


Version returns the JavaScript engine version number. If you pass a number to it, it will set the version number.


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.
Flames/suggestions:David Bradley <>
Author: David Bradley <>
Last modified: 17 March 2003