XPCShell Reference

  • Revision slug: XPCShell_Reference
  • Revision title: XPCShell Reference
  • Revision id: 124598
  • Created:
  • Creator: Fredinfinite23
  • Is current revision? No
  • Comment 19 words added

Revision Content

The Command Line

The command-line syntax for xpcshell is:

xpcshell [-s] [-w] [-W] [-v version] [-f scriptfile] [scriptfile] [scriptarg...]
-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.
{{ mediawiki.external('scriptfile') }}
This is the file name of the script to execute.
{{ mediawiki.external('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 <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.

{{ languages( { "fr": "fr/Xpcshell" } ) }}

Revision Source

<h3 name="The_Command_Line">The Command Line</h3>
<p>The command-line syntax for <a href="/en/XPConnect/xpcshell" title="en/XPConnect/xpcshell">xpcshell</a> is:</p>
<pre>xpcshell [-s] [-w] [-W] [-v version] [-f scriptfile] [scriptfile] [scriptarg...]</pre>
<dl> <dt><code>-f</code></dt> <dd>This option specifies a script file to execute. <code>xpcshell</code> terminates upon script completion. You can specify multiple JS files to execute by using multiple <code>-f</code> arguments, and the scripts will be executed in the order encountered.</dd>
</dl>
<dl> <dd>Furthermore, XPCShell looks for <code>xpcshell.js</code> in the current directory. If that file is found, it is executed before any other JS files specified.</dd> <dt><code>-g</code></dt> <dd>This option specifies which Gecko Runtime Environment directory (greDir) to use for XPCOM.</dd> <dt><code>-i</code></dt> <dd>This option turns on the "interactive" mode</dd>
</dl>
<dl> <dt><code>-s</code></dt> <dd>This option toggles the JavaScript strict option on and off. By default it is off.</dd>
</dl>
<dl> <dt><code>-v version</code></dt> <dd>This allows you to specify a specific version of JS to use, and should be set to an integral value specified by the <a href="/En/SpiderMonkey/JSAPI_Reference/JSVersion" title="En/SpiderMonkey/JSAPI_Reference/JSVersion">JSVersion</a> enumerated type. For instance, specifying <code>-v 180</code> will set the interpreter to use JavaScript version 1.8.</dd>
</dl>
<dl> <dt><code>-w (lower case)</code></dt> <dd>This option turns on JavaScript warnings.</dd>
</dl>
<dl> <dt><code>-W (upper case)</code></dt> <dd>This turns off JavaScript warnings. The last option listed is the one that takes effect.</dd> <dt><code>-x</code></dt> <dd>This option toggles the XML option on and off. By default it is off.</dd>
</dl>
<dl> <dt><code>{{ mediawiki.external('scriptfile') }}</code></dt> <dd>This is the file name of the script to execute.</dd>
</dl>
<dl> <dt><code>{{ mediawiki.external('scriptarg…') }}</code></dt> <dd>These are arguments to be passed to the script. These arguments are only passed to “scriptfile” and not the scripts designated by <code>–f</code> options. These arguments appear on the global property <code>arguments</code>.</dd>
</dl>
<dl> <dd>For instance, assume that you have a file called <code>test.js</code> with the following contents:</dd>
</dl>
<pre>for (prop in arguments)
{
    print(prop + "=" + arguments[prop]);
}
</pre>
<dl> <dd>Entering the following at the command line should produce the following output:</dd>
</dl>
<pre>$ xpcshell test.js This is a test
0=This
1=is
2=a
3=test
</pre>
<h3 name="XPCShell_Extensions">XPCShell Extensions</h3>
<p>Once you execute XPCShell without a script you'll be at the <code>JS&gt;</code> command line. The following are some useful functions that can be invoked from the command line:</p>
<dl> <dt><code>clear(<em>object</em>)</code></dt> <dd><code>clear()</code> removes all properties from an object. For example, if you created <code>anObject</code> with a property named <code>value</code> and then called <code>clear(anObject)</code>, the property <code>value</code> would no longer exist.</dd>
</dl>
<dl> <dt><code>gc(<em>heapDumpFilename</em>)</code></dt> <dd><code>gc()</code> 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.</dd>
</dl>
<dl> <dt><code>load(<em>scriptFilename</em>)</code></dt> <dd><code>load()</code> allows you to load and run a script from the command line. For example, <code>load("MyScript.js")</code> will execute the script <code>MyScript.js</code> in the current directory.</dd>
</dl>
<dl> <dt><code>print(<em>obj1</em>, <em>obj2</em>, <em>…</em>)</code></dt> <dd><code>print()</code> 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 <code>print(1, 2, 3)</code> Will print <code>1 2 3&lt;newline&gt;</code>.</dd>
</dl>
<dl> <dt><code>dump(<em>object</em>)</code></dt> <dd><code>dump()</code> is almost like <code>print</code>. It only handles one parameter and it doesn't append a newline.</dd>
</dl>
<dl> <dt><code>dumpXPC(<em>depth</em>)</code></dt> <dd>This function dumps the XPConnect object. See the documentation on <code>debugDump()</code> for the <a href="/en/NsIXPConnect" title="en/NsIXPConnect">nsIXPConnect</a> interface for more information.</dd>
</dl>
<dl> <dt><code>version(<em>newVersion</em>)</code></dt> <dd><code>version()</code> 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 <code>-v</code> command-line argument for more information.</dd>
</dl>
<dl> <dt><code>quit(<em>exitCode</em>)</code></dt> <dd><code>quit()</code> exits the shell. You can specify arguments that will get translated to an exit code. <code>quit(5)</code> will exit XPCShell with a result code of 5.</dd>
</dl>
<div class="originaldocinfo">
<h2 name="Original_Document_Information">Original Document Information</h2>
<ul> <li>Author: David Bradley &lt;<a class=" link-mailto" href="mailto:dbradley@netscape.com" rel="freelink">dbradley@netscape.com</a>&gt;</li> <li>Last Updated Date: 17 March 2003</li> <li>Copyright Information: Portions of this content are © 1998–2008 by individual mozilla.org contributors; content available under a Creative Commons license.</li>
</ul>
</div>
<p>{{ languages( { "fr": "fr/Xpcshell" } ) }}</p>
Revert to this revision