mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-05 08:35:26 +00:00
129 lines
6.1 KiB
HTML
129 lines
6.1 KiB
HTML
<!-- ***** BEGIN LICENSE BLOCK *****
|
|
- Version: MPL 1.1/GPL 2.0
|
|
-
|
|
- The contents of this file are subject to the Mozilla Public License Version
|
|
- 1.1 (the "License"); you may not use this file except in compliance with
|
|
- the License. You may obtain a copy of the License at
|
|
- http://www.mozilla.org/MPL/
|
|
-
|
|
- Software distributed under the License is distributed on an "AS IS" basis,
|
|
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
- for the specific language governing rights and limitations under the
|
|
- License.
|
|
-
|
|
- The Original Code is Rhino code, released May 6, 1999.
|
|
-
|
|
- The Initial Developer of the Original Code is
|
|
- Netscape Communications Corporation.
|
|
- Portions created by the Initial Developer are Copyright (C) 1997-1999
|
|
- the Initial Developer. All Rights Reserved.
|
|
-
|
|
- Contributor(s):
|
|
-
|
|
- Alternatively, the contents of this file may be used under the terms of
|
|
- the GNU General Public License Version 2 or later (the "GPL"), in which
|
|
- case the provisions of the GPL are applicable instead of those above. If
|
|
- you wish to allow use of your version of this file only under the terms of
|
|
- the GPL and not to allow others to use your version of this file under the
|
|
- MPL, indicate your decision by deleting the provisions above and replacing
|
|
- them with the notice and other provisions required by the GPL. If you do
|
|
- not delete the provisions above, a recipient may use your version of this
|
|
- file under either the MPL or the GPL.
|
|
-
|
|
- ***** END LICENSE BLOCK ***** -->
|
|
|
|
<!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.75 [en] (WinNT; U) [Netscape]">
|
|
<title>Rhino Examples</title>
|
|
</head>
|
|
<body bgcolor="#FFFFFF">
|
|
|
|
<center>
|
|
<h1>
|
|
Rhino Examples</h1></center>
|
|
Examples have been provided that show how to control the JavaScript engine
|
|
and to implement scriptable host objects. All the examples are in the cvs
|
|
tree at <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/">mozilla/js/rhino/examples</a></tt>.
|
|
<br>
|
|
<h2>
|
|
Sample Scripts</h2>
|
|
The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/unique.js">unique.js</a></tt>
|
|
script allows printing unique lines from a file.
|
|
<p>The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/liveConnect.js">liveConnect.js</a></tt>
|
|
script shows a sample usage of LiveConnect (Java-to-JavaScript connectivity).
|
|
<p>The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/jsdoc.js">jsdoc.js</a></tt>
|
|
script is a JavaScript analog to Java's <tt>javadoc</tt>. It makes heavy
|
|
use of regular expressions.
|
|
<p>The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/checkParam.js">checkParam.js</a></tt>
|
|
script is a useful tool to check that <tt>@param</tt> tags in Java documentation
|
|
comments match the parameters in the corresponding Java method.
|
|
<p>The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/enum.js">enum.js</a></tt>
|
|
script is a good example of using a JavaAdapter to implement a Java interface
|
|
using a JavaScript object.
|
|
<p>The <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/NervousText.js">NervousText.js</a>
|
|
script is a JavaScript implementation of the famous NervousText applet
|
|
using JavaScript compiled to Java classes using <a href="jsc.html">jsc</a>.
|
|
It can be run in the HTML page <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/NervousText.html">NervousText.html</a>.
|
|
<br>
|
|
<h2>
|
|
Controlling the JavaScript Engine</h2>
|
|
|
|
<h4>
|
|
The RunScript class</h4>
|
|
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/RunScript.java">RunScript.java</a></tt>
|
|
is a simple program that executes a script from the command line.
|
|
<h4>
|
|
The Control class</h4>
|
|
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/Control.java">Control.java</a></tt>
|
|
is a program that executes a simple script and then manipulates the result.
|
|
<h4>
|
|
JavaScript Shell</h4>
|
|
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/Shell.java">Shell.java</a></tt>
|
|
is a program that executes JavaScript programs; it is a simplified version
|
|
of the shell in the <tt>tools</tt> package. The programs may be specified
|
|
as files on the command line or by typing interactively while the shell
|
|
is running.
|
|
<h4>PrimitiveWrapFactory</h4>
|
|
<a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/PrimitiveWrap
|
|
Factory.java">PrimitiveWrapFactory.java</a> is an example of a WrapFactory that
|
|
can be used to control the wrapping behavior of the Rhino engine on calls to Jav
|
|
a methods.<br>
|
|
<h4>
|
|
<b>Multithreaded Script Execution</b></h4>
|
|
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/DynamicScopes.java">DynamicScopes.java</a></tt>
|
|
is a program that creates a single global scope object and then shares
|
|
it across multiple threads. Sharing the global scope allows both information
|
|
to be shared across threads, and amortizes the cost of Context.initStandardObjects
|
|
by only performing that expensive operation once.
|
|
<br>
|
|
<h2>
|
|
Implementing Host Objects</h2>
|
|
First check out the <a href="tutorial.html">tutorial</a>
|
|
if you haven't already.
|
|
<h4>
|
|
The Foo class - Extending ScriptableObject</h4>
|
|
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/Foo.java">Foo.java</a></tt>
|
|
is a simple JavaScript host object that includes a property with an associated
|
|
action and a variable argument method.
|
|
<br>
|
|
<h4>
|
|
The Matrix class - Implementing Scriptable</h4>
|
|
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/Matrix.java">Matrix.java</a></tt>
|
|
provides a simple multidimensional array by implementing the Scriptable
|
|
interface.
|
|
<br>
|
|
<h4>
|
|
The File class - An advanced example</h4>
|
|
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/File.java">File.java</a></tt>
|
|
extends ScriptableObject to provide a means of reading and writing files
|
|
from JavaScript. A more involved example of host object definition.
|
|
<p>
|
|
<hr WIDTH="100%">
|
|
<br><a href="index.html">back to top</a>
|
|
</body>
|
|
</html>
|