MDN may have intermittent access issues April 18 13:00 - April 19 01:00 UTC. See whistlepig.mozilla.org for all notifications.

mozilla

Revision 124595 of XPCShell Reference

  • Revision slug: XPCShell_Reference
  • Revision title: XPCShell Reference
  • Revision id: 124595
  • Created:
  • Creator: Varmaa
  • Is current revision? No
  • Comment /* The Command Line */ Added link to xpcshell page.

Revision Content

The Command Line

The command-line syntax for xpcshell is:

xpcshell [-s] [-w] [-W] [-v version] [-f scriptfile] [scriptfile] [scriptarg...]
<tt>-f</tt>
This option specifies a script file to execute. <tt>xpcshell</tt> terminates upon script completion. You can specify multiple JS files to execute by using multiple <tt>-f</tt> arguments, and the scripts will be executed in the order encountered.
Furthermore, XPCShell looks for <tt>xpcshell.js</tt> in the current directory. If that file is found, it is executed before any other JS files specified.
<tt>-s</tt>
This option toggles the JavaScript strict option on and off. By default it is off.
<tt>-v version</tt>
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 <tt>-v 180</tt> will set the interpreter to use JavaScript version 1.8.
<tt>-w (lower case)</tt>
This option turns on JavaScript warnings.
<tt>-W (upper case)</tt>
This turns off JavaScript warnings. The last option listed is the one that takes effect.
<tt>{{ mediawiki.external('scriptfile') }}</tt>
This is the file name of the script to execute.
<tt>{{ mediawiki.external('scriptarg…') }}</tt>
These are arguments to be passed to the script. These arguments are only passed to “scriptfile” and not the scripts designated by <tt>–f</tt> options. These arguments appear on the global property <tt>arguments</tt>.
For instance, assume that you have a file called <tt>test.js</tt> 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 <tt>JS></tt> command line. The following are some useful functions that can be invoked from the command line:

<tt>clear(object)</tt>
<tt>clear()</tt> removes all properties from an object. For example, if you created <tt>anObject</tt> with a property named <tt>value</tt> and then called <tt>clear(anObject)</tt>, the property <tt>value</tt> would no longer exist.
<tt>gc(heapDumpFilename)</tt>
<tt>gc()</tt> 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.
<tt>load(scriptFilename)</tt>
<tt>load()</tt> allows you to load and run a script from the command line. For example, <tt>load("MyScript.js")</tt> will execute the script <tt>MyScript.js</tt> in the current directory.
<tt>print(obj1, obj2, )</tt>
<tt>print()</tt> 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 <tt>print(1, 2, 3)</tt> Will print <tt>1 2 3<newline></tt>.
<tt>dump(object)</tt>
<tt>dump()</tt> is almost like <tt>print</tt>. It only handles one parameter and it doesn't append a newline.
<tt>dumpXPC(depth)</tt>
This function dumps the XPConnect object. See the documentation on <tt>debugDump()</tt> for the nsIXPConnect interface for more information.
<tt>version(newVersion)</tt>
<tt>version()</tt> 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 <tt>-v</tt> command-line argument for more information.
<tt>quit(exitCode)</tt>
<tt>quit()</tt> exits the shell. You can specify arguments that will get translated to an exit code. <tt>quit(5)</tt> 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/Xpcshell">xpcshell</a> is:
</p>
<pre>xpcshell [-s] [-w] [-W] [-v version] [-f scriptfile] [scriptfile] [scriptarg...]</pre>
<dl><dt><tt>-f</tt>
</dt><dd>This option specifies a script file to execute. <tt>xpcshell</tt> terminates upon script completion. You can specify multiple JS files to execute by using multiple <tt>-f</tt> arguments, and the scripts will be executed in the order encountered.
</dd></dl>
<dl><dd>Furthermore, XPCShell looks for <tt>xpcshell.js</tt> in the current directory. If that file is found, it is executed before any other JS files specified.
</dd></dl>
<dl><dt><tt>-s</tt>
</dt><dd>This option toggles the JavaScript strict option on and off. By default it is off.
</dd></dl>
<dl><dt><tt>-v version</tt>
</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/JSVersion">JSVersion</a> enumerated type. For instance, specifying <tt>-v 180</tt> will set the interpreter to use JavaScript version 1.8.
</dd></dl>
<dl><dt><tt>-w (lower case)</tt>
</dt><dd>This option turns on JavaScript warnings.
</dd></dl>
<dl><dt><tt>-W (upper case)</tt>
</dt><dd>This turns off JavaScript warnings. The last option listed is the one that takes effect.
</dd></dl>
<dl><dt><tt>{{ mediawiki.external('scriptfile') }}</tt>
</dt><dd>This is the file name of the script to execute.
</dd></dl>
<dl><dt><tt>{{ mediawiki.external('scriptarg…') }}</tt>
</dt><dd>These are arguments to be passed to the script. These arguments are only passed to “scriptfile” and not the scripts designated by <tt>–f</tt> options. These arguments appear on the global property <tt>arguments</tt>.
</dd></dl>
<dl><dd>For instance, assume that you have a file called <tt>test.js</tt> 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 <tt>JS&gt;</tt> command line. The following are some useful functions that can be invoked from the command line:
</p>
<dl><dt><tt>clear(<i>object</i>)</tt>
</dt><dd><tt>clear()</tt> removes all properties from an object. For example, if you created <tt>anObject</tt> with a property named <tt>value</tt> and then called <tt>clear(anObject)</tt>, the property <tt>value</tt> would no longer exist.
</dd></dl>
<dl><dt><tt>gc(<i>heapDumpFilename</i>)</tt>
</dt><dd><tt>gc()</tt> 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><tt>load(<i>scriptFilename</i>)</tt>
</dt><dd><tt>load()</tt> allows you to load and run a script from the command line. For example, <tt>load("MyScript.js")</tt> will execute the script <tt>MyScript.js</tt> in the current directory.
</dd></dl>
<dl><dt><tt>print(<i>obj1</i>, <i>obj2</i>, <i>…</i>)</tt>
</dt><dd><tt>print()</tt> 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 <tt>print(1, 2, 3)</tt> Will print <tt>1 2 3&lt;newline&gt;</tt>.
</dd></dl>
<dl><dt><tt>dump(<i>object</i>)</tt>
</dt><dd><tt>dump()</tt> is almost like <tt>print</tt>. It only handles one parameter and it doesn't append a newline.
</dd></dl>
<dl><dt><tt>dumpXPC(<i>depth</i>)</tt>
</dt><dd>This function dumps the XPConnect object. See the documentation on <tt>debugDump()</tt> for the <a href="en/NsIXPConnect">nsIXPConnect</a> interface for more information.
</dd></dl>
<dl><dt><tt>version(<i>newVersion</i>)</tt>
</dt><dd><tt>version()</tt> 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 <tt>-v</tt> command-line argument for more information.
</dd></dl>
<dl><dt><tt>quit(<i>exitCode</i>)</tt>
</dt><dd><tt>quit()</tt> exits the shell. You can specify arguments that will get translated to an exit code. <tt>quit(5)</tt> 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>
{{ languages( { "fr": "fr/Xpcshell" } ) }}
Revert to this revision