author | serb |
Wed, 18 Apr 2018 14:07:41 -0700 | |
changeset 49998 | 9070717a16a1 |
parent 47290 | 2853531b2c8c |
child 50878 | fb7800b66c92 |
permissions | -rw-r--r-- |
36517 | 1 |
/* |
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
42380
180839e7d68a
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37833
diff
changeset
|
26 |
/** |
45538
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
27 |
* Provides the implementation of Nashorn script engine and |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
28 |
* the runtime environment for programs written in ECMAScript 5.1. |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
29 |
* <p> |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
30 |
* Nashorn is a runtime environment for programs written in ECMAScript 5.1. |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
31 |
* </p> |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
32 |
* |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
33 |
* <h1>Usage</h1> |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
34 |
* |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
35 |
* The recommended way to use Nashorn is through the |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
36 |
* <a href="http://jcp.org/en/jsr/detail?id=223" target="_top">JSR-223 |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
37 |
* "Scripting for the Java Platform"</a> APIs found in the |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
38 |
* {@link javax.script} package. Usually, you'll obtain a |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
39 |
* {@link javax.script.ScriptEngine} instance for Nashorn using: |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
40 |
* <pre> |
43017
88c78d6617f4
8164391: Provide a javadoc description for jdk.scripting.nashorn
sundar
parents:
42380
diff
changeset
|
41 |
import javax.script.*; |
88c78d6617f4
8164391: Provide a javadoc description for jdk.scripting.nashorn
sundar
parents:
42380
diff
changeset
|
42 |
... |
88c78d6617f4
8164391: Provide a javadoc description for jdk.scripting.nashorn
sundar
parents:
42380
diff
changeset
|
43 |
ScriptEngine nashornEngine = new ScriptEngineManager().getEngineByName("nashorn"); |
88c78d6617f4
8164391: Provide a javadoc description for jdk.scripting.nashorn
sundar
parents:
42380
diff
changeset
|
44 |
</pre> |
45538
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
45 |
* |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
46 |
* and then use it just as you would any other JSR-223 script engine. See |
47290 | 47 |
* {@link jdk.nashorn.api.scripting} package for details. |
45538
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
48 |
* <h1>Compatibility</h1> |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
49 |
* Nashorn is 100% compliant with the |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
50 |
* <a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm" |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
51 |
* target="_top">ECMA-262 Standard, Edition 5.1</a>. |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
52 |
* It requires a Java Virtual Machine that implements the |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
53 |
* <a href="http://jcp.org/en/jsr/detail?id=292" target="_top"> |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
54 |
* JSR-292 "Supporting Dynamically Typed Languages on the Java Platform"</a> |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
55 |
* specification (often referred to as "invokedynamic"), as well as |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
56 |
* the already mentioned JSR-223. |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
57 |
* |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
58 |
* <h1>Interoperability with the Java platform</h1> |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
59 |
* |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
60 |
* In addition to being a 100% ECMAScript 5.1 runtime, Nashorn provides features |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
61 |
* for interoperability of the ECMAScript programs with the Java platform. |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
62 |
* In general, any Java object put into the script engine's context will be |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
63 |
* visible from the script. In terms of the standard, such Java objects are not |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
64 |
* considered "native objects", but rather "host objects", as defined in |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
65 |
* section 4.3.8. This distinction allows certain semantical differences |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
66 |
* in handling them compared to native objects. For most purposes, Java objects |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
67 |
* behave just as native objects do: you can invoke their methods, get and set |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
68 |
* their properties. In most cases, though, you can't add arbitrary properties |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
69 |
* to them, nor can you remove existing properties. |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
70 |
* |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
71 |
* <h2>Java collection handling</h2> |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
72 |
* |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
73 |
* Native Java arrays and {@link java.util.List}s support indexed access to |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
74 |
* their elements through the property accessors, and {@link java.util.Map}s |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
75 |
* support both property and element access through both dot and square-bracket |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
76 |
* property accessors, with the difference being that dot operator gives |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
77 |
* precedence to object properties (its fields and properties defined as |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
78 |
* {@code getXxx} and {@code setXxx} methods) while the square bracket |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
79 |
* operator gives precedence to map elements. Native Java arrays expose |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
80 |
* the {@code length} property. |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
81 |
* |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
82 |
* <h2>ECMAScript primitive types</h2> |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
83 |
* |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
84 |
* ECMAScript primitive types for number, string, and boolean are represented |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
85 |
* with {@link java.lang.Number}, {@link java.lang.CharSequence}, and |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
86 |
* {@link java.lang.Boolean} objects. While the most often used number type |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
87 |
* is {@link java.lang.Double} and the most often used string type is |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
88 |
* {@link java.lang.String}, don't rely on it as various internal optimizations |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
89 |
* cause other subclasses of {@code Number} and internal implementations of |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
90 |
* {@code CharSequence} to be used. |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
91 |
* |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
92 |
* <h2>Type conversions</h2> |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
93 |
* |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
94 |
* When a method on a Java object is invoked, the arguments are converted to |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
95 |
* the formal parameter types of the Java method using all allowed ECMAScript |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
96 |
* conversions. This can be surprising, as in general, conversions from string |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
97 |
* to number will succeed according to Standard's section 9.3 "ToNumber" |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
98 |
* and so on; string to boolean, number to boolean, Object to number, |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
99 |
* Object to string all work. Note that if the Java method's declared parameter |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
100 |
* type is {@code java.lang.Object}, Nashorn objects are passed without any |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
101 |
* conversion whatsoever; specifically if the JavaScript value being passed |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
102 |
* is of primitive string type, you can only rely on it being a |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
103 |
* {@code java.lang.CharSequence}, and if the value is a number, you can only |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
104 |
* rely on it being a {@code java.lang.Number}. If the Java method declared |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
105 |
* parameter type is more specific (e.g. {@code java.lang.String} or |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
106 |
* {@code java.lang.Double}), then Nashorn will of course ensure |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
107 |
* the required type is passed. |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
108 |
* |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
109 |
* <h2>SAM types</h2> |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
110 |
* |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
111 |
* As a special extension when invoking Java methods, ECMAScript function |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
112 |
* objects can be passed in place of an argument whose Java type is so-called |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
113 |
* "single abstract method" or "SAM" type. While this name usually covers |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
114 |
* single-method interfaces, Nashorn is a bit more versatile, and it |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
115 |
* recognizes a type as a SAM type if all its abstract methods are |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
116 |
* overloads of the same name, and it is either an interface, or it is an |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
117 |
* abstract class with a no-arg constructor. The type itself must be public, |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
118 |
* while the constructor and the methods can be either public or protected. |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
119 |
* If there are multiple abstract overloads of the same name, the single |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
120 |
* function will serve as the shared implementation for all of them, |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
121 |
* <em>and additionally it will also override any non-abstract methods of |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
122 |
* the same name</em>. This is done to be consistent with the fact that |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
123 |
* ECMAScript does not have the concept of overloaded methods. |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
124 |
* |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
125 |
* <h2>The {@code Java} object</h2> |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
126 |
* |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
127 |
* Nashorn exposes a non-standard global object named {@code Java} that is |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
128 |
* the primary API entry point into Java platform-specific functionality. |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
129 |
* You can use it to create instances of Java classes, convert from Java arrays |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
130 |
* to native arrays and back, and so on. |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
131 |
* |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
132 |
* <h2>Other non-standard built-in objects</h2> |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
133 |
* |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
134 |
* In addition to {@code Java}, Nashorn also exposes some other |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
135 |
* non-standard built-in objects: |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
136 |
* {@code JSAdapter}, {@code JavaImporter}, {@code Packages} |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
137 |
* |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
138 |
* @provides javax.script.ScriptEngineFactory |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
139 |
* @moduleGraph |
3391b408f58a
8181639: Add tool and services information to module summary
mchung
parents:
44554
diff
changeset
|
140 |
* @since 9 |
42380
180839e7d68a
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37833
diff
changeset
|
141 |
*/ |
36517 | 142 |
module jdk.scripting.nashorn { |
143 |
requires java.logging; |
|
45670
2b0b8cd704d4
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
45538
diff
changeset
|
144 |
requires jdk.dynalink; |
2b0b8cd704d4
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
45538
diff
changeset
|
145 |
|
42380
180839e7d68a
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37833
diff
changeset
|
146 |
requires transitive java.scripting; |
36517 | 147 |
|
148 |
exports jdk.nashorn.api.scripting; |
|
149 |
exports jdk.nashorn.api.tree; |
|
150 |
||
151 |
exports jdk.nashorn.internal.runtime to |
|
152 |
jdk.scripting.nashorn.shell; |
|
153 |
exports jdk.nashorn.internal.objects to |
|
154 |
jdk.scripting.nashorn.shell; |
|
155 |
exports jdk.nashorn.tools to |
|
156 |
jdk.scripting.nashorn.shell; |
|
157 |
||
45670
2b0b8cd704d4
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
45538
diff
changeset
|
158 |
provides javax.script.ScriptEngineFactory with |
2b0b8cd704d4
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
45538
diff
changeset
|
159 |
jdk.nashorn.api.scripting.NashornScriptEngineFactory; |
37833
ae7b3314b209
8150731: Nashorn JSObject linker should be exposed as a service provider
sundar
parents:
36517
diff
changeset
|
160 |
|
45670
2b0b8cd704d4
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
45538
diff
changeset
|
161 |
provides jdk.dynalink.linker.GuardingDynamicLinkerExporter with |
2b0b8cd704d4
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
45538
diff
changeset
|
162 |
jdk.nashorn.api.linker.NashornLinkerExporter; |
36517 | 163 |
} |