Class JSObject
public abstract class JSObject extends 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 of JSObject
. When a JSObject
instance is passed to the JavaScript engine, it is unwrapped back to its original JavaScript object. The JSObject
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.
Constructor Summary
Modifier | Constructor | Description |
---|---|---|
protected |
Constructs a new JSObject. |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
abstract Object |
call |
Calls a JavaScript method. |
abstract Object |
eval |
Evaluates a JavaScript expression. |
abstract Object |
getMember |
Retrieves a named member of a JavaScript object. |
abstract Object |
getSlot |
Retrieves an indexed member of a JavaScript object. |
abstract void |
removeMember |
Removes a named member of a JavaScript object. |
abstract void |
setMember |
Sets a named member of a JavaScript object. |
abstract void |
setSlot |
Sets an indexed member of a JavaScript object. |
Constructor Details
JSObject
protected JSObject()
Method Details
call
public abstract Object call(String methodName, Object... args) throws JSException
- Parameters:
-
methodName
- The name of the JavaScript method to be invoked. -
args
- the Java objects passed as arguments to the method. - Returns:
- Result of the method.
- Throws:
-
JSException
- when an error is reported from the browser or JavaScript engine.
eval
public abstract Object eval(String s) throws JSException
- Parameters:
-
s
- The JavaScript expression. - Returns:
- Result of the JavaScript evaluation.
- Throws:
-
JSException
- when an error is reported from the browser or JavaScript engine.
getMember
public abstract Object getMember(String name) throws JSException
- Parameters:
-
name
- The name of the JavaScript property to be accessed. - Returns:
- The value of the propery.
- Throws:
-
JSException
- when an error is reported from the browser or JavaScript engine.
setMember
public abstract void setMember(String name, Object value) throws JSException
- Parameters:
-
name
- The name of the JavaScript property to be accessed. -
value
- The value of the propery. - Throws:
-
JSException
- when an error is reported from the browser or JavaScript engine.
removeMember
public abstract void removeMember(String name) throws JSException
- Parameters:
-
name
- The name of the JavaScript property to be removed. - Throws:
-
JSException
- when an error is reported from the browser or JavaScript engine.
getSlot
public abstract Object getSlot(int index) throws JSException
- Parameters:
-
index
- The index of the array to be accessed. - Returns:
- The value of the indexed member.
- Throws:
-
JSException
- when an error is reported from the browser or JavaScript engine.
setSlot
public abstract void setSlot(int index, Object value) throws JSException
- Parameters:
-
index
- The index of the array to be accessed. -
value
- The value to set - Throws:
-
JSException
- when an error is reported from the browser or JavaScript engine.
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/jdk.jsobject/netscape/javascript/JSObject.html