public abstract classJSObjectextends java.lang.Object
Allows Java code to manipulate JavaScript objects.
When a JavaScript object is passed or returned to Java code, it is wrapped in an instance ofJSObject
. When aJSObject
instance is passed to the JavaScript engine, it is unwrapped back to its original JavaScript object. TheJSObject
class provides a way to invoke JavaScript methods and examine JavaScript properties.
Any data returned from the JavaScript engine to Java is converted to Java data types. Certain data passed to the JavaScript engine is converted to JavaScript data types. See the section on Data Type Conversions in theLiveConnect Specification for details on how values are converted.
Modifier | Constructor and Description |
---|---|
protected | JSObject() Constructs a new JSObject. |
Modifier and Type | Method and Description |
---|---|
abstract java.lang.Object | call(java.lang.String methodName, java.lang.Object... args) Calls a JavaScript method. |
abstract java.lang.Object | eval(java.lang.String s) Evaluates a JavaScript expression. |
abstract java.lang.Object | getMember(java.lang.String name) Retrieves a named member of a JavaScript object. |
abstract java.lang.Object | getSlot(int index) Retrieves an indexed member of a JavaScript object. |
abstract void | removeMember(java.lang.String name) Removes a named member of a JavaScript object. |
abstract void | setMember(java.lang.String name, java.lang.Object value) Sets a named member of a JavaScript object. |
abstract void | setSlot(int index, java.lang.Object value) Sets an indexed member of a JavaScript object. |
protected JSObject()
public abstract java.lang.Object call(java.lang.String methodName, java.lang.Object... args) throwsJSException
Calls a JavaScript method. Equivalent to "this.methodName(args[0], args[1], ...)" in JavaScript.
methodName
- The name of the JavaScript method to be invoked.args
- An array of Java object to be passed as arguments to the method.JSException
public abstract java.lang.Object eval(java.lang.String s) throwsJSException
Evaluates a JavaScript expression. The expression is a string of JavaScript source code which will be evaluated in the context given by "this".
s
- The JavaScript expression.JSException
public abstract java.lang.Object getMember(java.lang.String name) throwsJSException
Retrieves a named member of a JavaScript object. Equivalent to "this.name" in JavaScript.
name
- The name of the JavaScript property to be accessed.JSException
public abstract void setMember(java.lang.String name, java.lang.Object value) throwsJSException
Sets a named member of a JavaScript object. Equivalent to "this.name = value" in JavaScript.
name
- The name of the JavaScript property to be accessed.value
- The value of the propery.JSException
public abstract void removeMember(java.lang.String name) throwsJSException
Removes a named member of a JavaScript object. Equivalent to "delete this.name" in JavaScript.
name
- The name of the JavaScript property to be removed.JSException
public abstract java.lang.Object getSlot(int index) throwsJSException
Retrieves an indexed member of a JavaScript object. Equivalent to "this[index]" in JavaScript.
index
- The index of the array to be accessed.JSException
public abstract void setSlot(int index, java.lang.Object value) throwsJSException
Sets an indexed member of a JavaScript object. Equivalent to "this[index] = value" in JavaScript.
index
- The index of the array to be accessed.JSException
Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.