netscape.javascript
Class JSObject

java.lang.Object
  extended by netscape.javascript.JSObject

public abstract class JSObject
extends 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 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. See the section on Data Type Conversions in the new LiveConnect Specification for details on how values are converted.


Constructor Summary
protected JSObject()
          Constructs a new JSObject.
 
Method Summary
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.
static JSObject getWindow(java.applet.Applet applet)
           Returns a JSObject for the window containing the given applet.
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSObject

protected JSObject()
Constructs a new JSObject. Users should not call this method nor subclass JSObject.

Method Detail

call

public abstract java.lang.Object call(java.lang.String methodName,
                                      java.lang.Object[] args)
                               throws JSException

Calls a JavaScript method. Equivalent to "this.methodName(args[0], args[1], ...)" in JavaScript.

Parameters:
methodName - The name of the JavaScript method to be invoked.
args - An array of Java object to be passed as arguments to the method.
Returns:
Result of the method.
Throws:
JSException

eval

public abstract java.lang.Object eval(java.lang.String s)
                               throws JSException

Evaluates a JavaScript expression. The expression is a string of JavaScript source code which will be evaluated in the context given by "this".

Parameters:
s - The JavaScript expression.
Returns:
Result of the JavaScript evaluation.
Throws:
JSException

getMember

public abstract java.lang.Object getMember(java.lang.String name)
                                    throws JSException

Retrieves a named member of a JavaScript object. Equivalent to "this.name" in JavaScript.

Parameters:
name - The name of the JavaScript property to be accessed.
Returns:
The value of the propery.
Throws:
JSException

setMember

public abstract void setMember(java.lang.String name,
                               java.lang.Object value)
                        throws JSException

Sets a named member of a JavaScript object. Equivalent to "this.name = value" in JavaScript.

Parameters:
name - The name of the JavaScript property to be accessed.
value - The value of the propery.
Throws:
JSException

removeMember

public abstract void removeMember(java.lang.String name)
                           throws JSException

Removes a named member of a JavaScript object. Equivalent to "delete this.name" in JavaScript.

Parameters:
name - The name of the JavaScript property to be removed.
Throws:
JSException

getSlot

public abstract java.lang.Object getSlot(int index)
                                  throws JSException

Retrieves an indexed member of a JavaScript object. Equivalent to "this[index]" in JavaScript.

Parameters:
int - The index of the array to be accessed.
Returns:
The value of the indexed member.
Throws:
JSException

setSlot

public abstract void setSlot(int index,
                             java.lang.Object value)
                      throws JSException

Sets an indexed member of a JavaScript object. Equivalent to "this[index] = value" in JavaScript.

Parameters:
int - The index of the array to be accessed.
Throws:
JSException

getWindow

public static JSObject getWindow(java.applet.Applet applet)
                          throws JSException

Returns a JSObject for the window containing the given applet.

Parameters:
applet - The applet.
Returns:
JSObject for the window containing the given applet.
Throws:
JSException