gecko-dev/js/rhino/docs/jsc.html
nboyd%atg.com 711c087f8e Massive reconfiguration of the cvs directory structure:
mozilla/js/rhino/org is now distributed between
mozilla/js/rhino/src and mozilla/js/rhino/toolsrc.
The build.xml has been split in three.
Docs now live in the project directory.

These changes mean that the cvs directories mirror the distribution and thus a distribution
will build the same way as a cvs build.
2001-04-24 20:31:31 +00:00

83 lines
3.6 KiB
HTML

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Norris Boyd">
<meta name="GENERATOR" content="Mozilla/4.7 [en] (WinNT; U) [Netscape]">
<title>JavaScript Compiler</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h1>
JavaScript Compiler</h1></center>
The JavaScript compiler translates JavaScript source into Java class files.
The resulting Java class files can then be loaded and executed at another
time, providing a convenient method for transfering JavaScript, and for
avoiding translation cost.
<p>Note that the top-level functions available to the shell (such as <tt>print</tt>)
are <i>not</i> available to compiled scripts when they are run outside
the shell.
<br>&nbsp;
<h2>
Invoking the Compiler</h2>
<tt>java org.mozilla.javascript.tools.jsc.Main</tt> [<i>options</i>] <i>file1</i><tt>.js</tt>
[<i>file2</i><tt>.js</tt>...]
<p>where <i>options</i> are:
<p><tt>-extends <i>java-class-name</i></tt>
<blockquote>Specifies that a java class extending the Java class <i>java-class-name</i>
should be generated from the incoming JavaScript source file. Each global
function in the source file is made a method of the generated class, overriding
any methods in the base class by the same name.</blockquote>
<tt>-implements <i>java-intf-name</i></tt>
<blockquote>Specifies that a java class implementing the Java interface
<i><tt>java-intf-name</tt></i>
should be generated from the incoming JavaScript source file. Each global
function in the source file is made a method of the generated class, implementing
any methods in the interface by the same name.</blockquote>
<tt>-debug</tt>
<br><tt>-g</tt>
<ul>Specifies that debug information should be generated. May not be combined
with optimization at an <i>optLevel</i> greater than zero.</ul>
<tt>-nosource</tt>
<ul>Does not save the source in the class file. Functions and scripts compiled
this way cannot be decompiled. This option can be used to avoid distributing
source or simply to save space in the resulting class file.</ul>
<tt>-o </tt><i>outputFile</i>
<ul>Writes the class file to the given file (which should end in <tt>.class</tt>).
The string <i>outputFile</i> must be a writable filename.</ul>
<tt>-opt </tt><i>optLevel</i>
<br><tt>-O</tt> <i>optLevel</i>
<ul>Optimizes at level <i>optLevel</i>, which must be an integer between
-1 and 9. See <a href="opt.html">Optimization</a> for more details. If
<i>optLevel</i>
is greater than zero, <tt>-debug</tt> may not be specified.</ul>
<tt>-package</tt> <i>packageName</i>
<ul>Specifies the package to generate the class into. The string <i>packageName</i>
must be composed of valid identifier characters optionally separated by
periods.</ul>
<tt>-version </tt><i>versionNumber</i>
<ul>Specifies the language version to compile with. The string <i>versionNumber</i>
must be one of <tt>100</tt>, <tt>110</tt>, <tt>120</tt>, <tt>130</tt>,
or <tt>140</tt>. See <a href="overview.html#versions">JavaScript Language
Versions</a> for more information on language versions.</ul>
<h2>
Examples</h2>
<tt>$ cat test.js</tt>
<br><tt>java.lang.System.out.println("hi, mom!");</tt>
<br><tt>$ java org.mozilla.javascript.tools.jsc.Main test.js</tt>
<br><tt>$ ls *.class</tt>
<br><tt>test.class</tt>
<br><tt>$ java test</tt>
<br><tt>hi, mom!</tt>
<p><tt>$ java org.mozilla.javascript.tools.jsc.Main -extends java.applet.Applet
\</tt>
<br><tt>&nbsp;&nbsp;&nbsp; -implements java.lang.Runnable NervousText.js</tt>
<br>&nbsp;
<p>
<hr WIDTH="100%">
<br><a href="index.html">back to top</a>
</body>
</html>