220 * <p>
221 * In some cases the context provides a specific Java type that guides
222 * the conversion.
223 * For example if setting a Java {@code String} field from a JavaScript
224 * expression, then the JavaScript value is converted to a string.
225 *
226 * <h4>Mapping Java objects to JavaScript values</h4>
227 *
228 * The arguments of the {@code JSObject} methods {@code setMember} and
229 * {@code call} pass Java objects to the JavaScript environment.
230 * This is roughly the inverse of the JavaScript-to-Java mapping
231 * described above:
232 * Java {@code String}, {@code Number}, or {@code Boolean} objects
233 * are converted to the obvious JavaScript values. A {@code JSObject}
234 * object is converted to the original wrapped JavaScript object.
235 * Otherwise a {@code JavaRuntimeObject} is created. This is
236 * a JavaScript object that acts as a proxy for the Java object,
237 * in that accessing properties of the {@code JavaRuntimeObject}
238 * causes the Java field or method with the same name to be accessed.
239 * <p> Note that the Java objects bound using
240 * {@link netscape.javascript.JSObject#setMember JSObject.setMember}
241 * are implemented using weak references. This means that the Java object
242 * can be garbage collected, causing subsequent accesses to the JavaScript
243 * objects to have no effect.
244 *
245 * <h4>Calling back to Java from JavaScript</h4>
246 *
247 * <p>The {@link netscape.javascript.JSObject#setMember JSObject.setMember}
248 * method is useful to enable upcalls from JavaScript
249 * into Java code, as illustrated by the following example. The Java code
250 * establishes a new JavaScript object named {@code app}. This object has one
251 * public member, the method {@code exit}.
252 * <pre><code>
253 public class JavaApplication {
254 public void exit() {
255 Platform.exit();
256 }
257 }
258 ...
259 JavaApplication javaApp = new JavaApplication();
260 JSObject window = (JSObject) webEngine.executeScript("window");
|
220 * <p>
221 * In some cases the context provides a specific Java type that guides
222 * the conversion.
223 * For example if setting a Java {@code String} field from a JavaScript
224 * expression, then the JavaScript value is converted to a string.
225 *
226 * <h4>Mapping Java objects to JavaScript values</h4>
227 *
228 * The arguments of the {@code JSObject} methods {@code setMember} and
229 * {@code call} pass Java objects to the JavaScript environment.
230 * This is roughly the inverse of the JavaScript-to-Java mapping
231 * described above:
232 * Java {@code String}, {@code Number}, or {@code Boolean} objects
233 * are converted to the obvious JavaScript values. A {@code JSObject}
234 * object is converted to the original wrapped JavaScript object.
235 * Otherwise a {@code JavaRuntimeObject} is created. This is
236 * a JavaScript object that acts as a proxy for the Java object,
237 * in that accessing properties of the {@code JavaRuntimeObject}
238 * causes the Java field or method with the same name to be accessed.
239 * <p> Note that the Java objects bound using
240 * {@link netscape.javascript.JSObject#setMember JSObject.setMember},
241 * {@link netscape.javascript.JSObject#call JSObject.call} and
242 * {@link netscape.javascript.JSObject#setSlot JSObject.setSlot}
243 * are implemented using weak references. This means that the Java object
244 * can be garbage collected, causing subsequent accesses to the JavaScript
245 * objects to have no effect.
246 *
247 * <h4>Calling back to Java from JavaScript</h4>
248 *
249 * <p>The {@link netscape.javascript.JSObject#setMember JSObject.setMember}
250 * method is useful to enable upcalls from JavaScript
251 * into Java code, as illustrated by the following example. The Java code
252 * establishes a new JavaScript object named {@code app}. This object has one
253 * public member, the method {@code exit}.
254 * <pre><code>
255 public class JavaApplication {
256 public void exit() {
257 Platform.exit();
258 }
259 }
260 ...
261 JavaApplication javaApp = new JavaApplication();
262 JSObject window = (JSObject) webEngine.executeScript("window");
|