Package org.teavm.jso

Interface JSObject


public interface JSObject

The base type for all overlay types. Overlay types are Java types that represent JavaScript object, and therefore can be passed to and from JavaScript code.

An overlay type is an abstract class or an interface that extends/implements JSObject. An overlay type has following restrictions:

  • it must not contain any member fields, however static fields are allowed;
  • its non-abstract methods must not override methods of a parent type.

To simplify creation of overlay objects, you can use shortcut annotations instead of JSBody: JSMethod, JSProperty and JSIndexer.

Example:

 public abstract class Int32Array implements JSObject {
     @JSBody(params = {}, script = "return this.length;")
     public native int getLength();

     @JSIndexer
     public abstract int get(int index);

     @JSIndexer
     public abstract void set(int index, int value);

     @JSBody(params = "length", script = "return new Int32Array(length);")
     public static native ArrayBuffer create(int length);

     @JSBody(params = "buffer", script = "return new Int32Array(buffer);")
     public static native ArrayBuffer create(ArrayBuffer buffer);

     @JSBody(params = { "buffer", "offset", "length" },
             script = "return new Int32Array(buffer, offset, length);")
     public static native ArrayBuffer create(ArrayBuffer buffer, int offset, int length);
 }
 
Author:
Alexey Andreev
See Also:
JSBody
  • Method Summary

    Modifier and Type
    Method
    Description
    default <T extends JSObject>
    T
     
  • Method Details

    • cast

      default <T extends JSObject> T cast()