Rhino Examples

  • Raccourci de la révision : Rhino/Examples
  • Titre de la révision : Rhino Examples
  • ID de la révision : 375031
  • Créé :
  • Créateur : gnales
  • Version actuelle ? Oui
  • Commentaire

Contenu de la révision

Examples have been provided that show how to control the JavaScript engine and to implement scriptable host objects. All the examples are in the git tree at mozilla/js/rhino/examples.

Scripts Simple

Le script unique.js permet d'écrirer une seul ligne depuis un fichier.

Le script liveConnect.js montre un usage simple de LiveConnect (connectivité Java-vers-JavaScript).

Le script jsdoc.js est un analogue en JavaScript de la javadoc. Il permet un usage régulier des "regular expressions".

Le script checkParam.js est un outil utile pour vérifier les tags @param dans les commentaires documentation Java qui corresponde au paramètres dans la méthode  Java correspondante.

The enum.js script is a good example of using a JavaAdapter to implement a Java interface using a JavaScript object.

The NervousText.js script is a JavaScript implementation of the famous NervousText applet using JavaScript compiled to Java classes using jsc. It can be run in the HTML page NervousText.html.

Controlling the JavaScript Engine

The RunScript class

RunScript.java is a simple program that executes a script from the command line.

The Control class

Control.java is a program that executes a simple script and then manipulates the result.

JavaScript Shell

Shell.java is a program that executes JavaScript programs; it is a simplified version of the shell in the tools package. The programs may be specified as files on the command line or by typing interactively while the shell is running.

PrimitiveWrapFactory

PrimitiveWrapFactory.java is an example of a WrapFactory that can be used to control the wrapping behavior of the Rhino engine on calls to Java methods.

Multithreaded Script Execution

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

Implementing Host Objects

First check out the tutorial if you haven't already.

The Foo class - Extending ScriptableObject

Foo.java is a simple JavaScript host object that includes a property with an associated action and a variable argument method.

The Matrix class - Implementing Scriptable

Matrix.java provides a simple multidimensional array by implementing the Scriptable interface.

The File class - An advanced example

File.java extends ScriptableObject to provide a means of reading and writing files from JavaScript. A more involved example of host object definition.

Source de la révision

<p>Examples have been provided that show how to control the JavaScript engine and to implement scriptable host objects. All the examples are in the git tree at <code><a href="https://github.com/mozilla/rhino/tree/master/examples/">mozilla/js/rhino/examples</a></code>.</p>
<h2><a id="sample" name="sample">Scripts Simple</a></h2>
<p>Le script <code><a href="https://github.com/mozilla/rhino/tree/master/examples/unique.js">unique.js</a></code> permet d'écrirer une seul ligne depuis un fichier.</p>
<p>Le script <code><a href="https://github.com/mozilla/rhino/tree/master/examples/liveConnect.js">liveConnect.js</a></code> montre un usage simple de LiveConnect (connectivité Java-vers-JavaScript).</p>
<p>Le script <code><a href="https://github.com/mozilla/rhino/tree/master/examples/jsdoc.js">jsdoc.js</a></code> est un analogue en JavaScript de la<code> javadoc</code>. Il permet un usage régulier des "regular expressions".</p>
<p>Le script <code><a href="https://github.com/mozilla/rhino/tree/master/examples/checkParam.js">checkParam.js</a></code> est un outil utile pour vérifier les tags<code> @param</code> dans les commentaires documentation Java qui corresponde au paramètres dans la méthode&nbsp; Java correspondante.</p>
<p>The <code><a href="https://github.com/mozilla/rhino/tree/master/examples/enum.js">enum.js</a></code> script is a good example of using a JavaAdapter to implement a Java interface using a JavaScript object.</p>
<p>The <a href="https://github.com/mozilla/rhino/tree/master/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="https://github.com/mozilla/rhino/tree/master/examples/NervousText.html">NervousText.html</a>.</p>
<h2><a id="controlling" name="controlling">Controlling the JavaScript Engine</a></h2>
<h4>The RunScript class</h4>
<p><code><a href="https://github.com/mozilla/rhino/tree/master/examples/RunScript.java">RunScript.java</a></code> is a simple program that executes a script from the command line.</p>
<h4>The Control class</h4>
<p><code><a href="https://github.com/mozilla/rhino/tree/master/examples/Control.java">Control.java</a></code> is a program that executes a simple script and then manipulates the result.</p>
<h4>JavaScript Shell</h4>
<p><code><a href="https://github.com/mozilla/rhino/tree/master/examples/Shell.java">Shell.java</a></code> is a program that executes JavaScript programs; it is a simplified version of the shell in the <code>tools</code> package. The programs may be specified as files on the command line or by typing interactively while the shell is running.</p>
<h4>PrimitiveWrapFactory</h4>
<p><a href="https://github.com/mozilla/rhino/tree/master/examples/PrimitiveWrapFactory.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 Java methods.</p>
<h4>Multithreaded Script Execution</h4>
<p><code><a href="https://github.com/mozilla/rhino/tree/master/examples/DynamicScopes.java">DynamicScopes.java</a></code> 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.</p>
<h2>Implementing Host Objects</h2>
<p>First check out the <a href="/en/docs/Rhino/Embedding_tutorial">tutorial</a> if you haven't already.</p>
<h4>The Foo class - Extending ScriptableObject</h4>
<p><code><a href="https://github.com/mozilla/rhino/tree/master/examples/Foo.java">Foo.java</a></code> is a simple JavaScript host object that includes a property with an associated action and a variable argument method.</p>
<h4>The Matrix class - Implementing Scriptable</h4>
<p><code><a href="https://github.com/mozilla/rhino/tree/master/examples/Matrix.java">Matrix.java</a></code> provides a simple multidimensional array by implementing the Scriptable interface.</p>
<h4>The File class - An advanced example</h4>
<p><code><a href="https://github.com/mozilla/rhino/tree/master/examples/File.java">File.java</a></code> extends ScriptableObject to provide a means of reading and writing files from JavaScript. A more involved example of host object definition.</p>
Revenir à cette révision