netscape.javascript

## Class JSObject

- java.lang.Object
- - netscape.javascript.JSObject

-     public final class JSObject
      extends java.lang.Object

  JSObject allows Java to manipulate objects that are defined in JavaScript. Values passed from Java to JavaScript are converted as follows:
  - JSObject is converted to the original JavaScript object
  - Any other Java object is converted to a JavaScript wrapper, which can be used to access methods and fields of the java object. Converting this wrapper to a string will call the toString method on the original object, converting to a number will call the doubleValue method if possible and fail otherwise. Converting to a boolean will try to call the booleanValue method in the same way.
  - Java arrays are wrapped with a JavaScript object that understands array.length and array[index]
  - A Java boolean is converted to a JavaScript boolean
  - Java byte, char, short, int, long, float, and double are converted to JavaScript numbers
  Values passed from JavaScript to Java are converted as follows:
  - objects which are wrappers around java objects are unwrapped
  - other objects are wrapped with a JSObject
  - strings, numbers and booleans are converted to String, Double, and Boolean objects respectively
  This means that all JavaScript values show up as some kind of java.lang.Object in Java. In order to make much use of them, you will have to cast them to the appropriate subclass of Object, e.g. `(String) window.getMember("name");` or `(JSObject) window.getMember("document");`.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `JSObject(int jsobj_addr)` it is illegal to construct a JSObject manually
    `JSObject(long jsobj_addr)`
    `JSObject(java.lang.String jsobj_addr)` it is illegal to construct a JSObject manually

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.Object` | `call(java.lang.String methodName, java.lang.Object[] args)` Calls a JavaScript method.
    `java.lang.Object` | `eval(java.lang.String s)` Evaluates a JavaScript expression.
    `protected void` | `finalize()` Finalization decrements the reference count on the corresponding JavaScript object.
    `java.lang.Object` | `getMember(java.lang.String name)` Retrieves a named member of a JavaScript object.
    `java.lang.Object` | `getSlot(int index)` Retrieves an indexed member of a JavaScript object.
    `static JSObject` | `getWindow(java.applet.Applet applet)` get a JSObject for the window containing the given applet
    `void` | `removeMember(java.lang.String name)` Removes a named member of a JavaScript object.
    `void` | `setMember(java.lang.String name, java.lang.Object value)` Sets a named member of a JavaScript object.
    `void` | `setSlot(int index, java.lang.Object value)` Sets an indexed member of a JavaScript object.
    `java.lang.String` | `toString()` Converts a JSObject to a String.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### JSObject

          public JSObject(int jsobj_addr)

      it is illegal to construct a JSObject manually
      Parameters:
        `jsobj_addr` - integer to become jsobject

    - #### JSObject

          public JSObject(java.lang.String jsobj_addr)

      it is illegal to construct a JSObject manually
      Parameters:
        `jsobj_addr` - string to become jsobject

    - #### JSObject

          public JSObject(long jsobj_addr)

  - ### Method Detail

    - #### getMember

          public java.lang.Object getMember(java.lang.String name)

      Retrieves a named member of a JavaScript object. Equivalent to "this.name" in JavaScript.
      Parameters:
        `name` - name of the memebr to be searched in
      Returns:
        object which is member of name

    - #### getSlot

          public java.lang.Object getSlot(int index)

      Retrieves an indexed member of a JavaScript object. Equivalent to "this[index]" in JavaScript.
      Parameters:
        `index` - as in array-like touch in javascript array
      Returns:
        object on index position

    - #### setMember

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

      Sets a named member of a JavaScript object. Equivalent to "this.name = value" in JavaScript.
      Parameters:
        `name` - name of the member
        `value` - value to best to the named member

    - #### setSlot

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

      Sets an indexed member of a JavaScript object. Equivalent to "this[index] = value" in JavaScript.
      Parameters:
        `index` - as in array-like touch in javascript array
        `value` - value to be set on the index palce

    - #### removeMember

          public void removeMember(java.lang.String name)

      Removes a named member of a JavaScript object.
      Parameters:
        `name` - name of member of given name

    - #### call

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

      Calls a JavaScript method. Equivalent to "this.methodName(args[0], args[1], ...)" in JavaScript.
      Parameters:
        `methodName` - - name of the method to be called
        `args` - parameters for method
      Returns:
        result of method call

    - #### eval

          public java.lang.Object eval(java.lang.String s)

      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` - expression to be evaluated
      Returns:
        result of evaluation

    - #### toString

          public java.lang.String toString()

      Converts a JSObject to a String.
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        string representation of this object

    - #### getWindow

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

      get a JSObject for the window containing the given applet
      Parameters:
        `applet` - applet which will be searched for window
      Returns:
        the JSObject representing window of applet

    - #### finalize

          protected void finalize()

      Finalization decrements the reference count on the corresponding JavaScript object.
      Overrides:
        `finalize` in class `java.lang.Object`

Submit a bug or feature