Class JSValue

java.lang.Object
org.graalvm.webimage.api.JSValue
Direct Known Subclasses:
JSBigInt, JSBoolean, JSNumber, JSObject, JSString, JSSymbol, JSUndefined

public abstract class JSValue extends Object
Java representation of a JavaScript value.

The subclasses of this class represent JavaScript's six primitive data types and the object data type. The JavaScript Null data type does not have a special representation -- the JavaScript null value is directly mapped to the Java null value.

  • Method Details

    • checkedCoerce

      public static <R> R checkedCoerce(Object value, Class<R> cls)
      Attempts to coerce a given value to the specified Java type.

      If the value is a JSValue, it will be converted using its as(...) method. Otherwise, the value is cast directly.

      Type Parameters:
      R - the return type
      Parameters:
      value - the value to coerce, which may be a JSValue or a native Java object
      cls - the target Java class to coerce to
      Returns:
      the coerced value as an instance of cls
      Throws:
      ClassCastException - if the coercion fails or is unsupported
    • isUndefined

      public static boolean isUndefined(JSValue value)
      Checks whether the given value is the JavaScript undefined value.
      See Also:
    • isUndefined

      public boolean isUndefined()
      Checks whether this is the JavaScript undefined value.
    • undefined

      public static JSUndefined undefined()
    • typeof

      public abstract String typeof()
    • stringValue

      protected abstract String stringValue()
    • asBoolean

      public Boolean asBoolean()
    • asByte

      public Byte asByte()
    • asShort

      public Short asShort()
    • asChar

      public Character asChar()
    • asInt

      public Integer asInt()
    • asFloat

      public Float asFloat()
    • asLong

      public Long asLong()
    • asDouble

      public Double asDouble()
    • asBigInteger

      public BigInteger asBigInteger()
    • asString

      public String asString()
    • asBooleanArray

      public boolean[] asBooleanArray()
    • asByteArray

      public byte[] asByteArray()
    • asShortArray

      public short[] asShortArray()
    • asCharArray

      public char[] asCharArray()
    • asIntArray

      public int[] asIntArray()
    • asFloatArray

      public float[] asFloatArray()
    • asLongArray

      public long[] asLongArray()
    • asDoubleArray

      public double[] asDoubleArray()
    • as

      public <T> T as(Class<T> cls)
    • toString

      public String toString()
      Overrides:
      toString in class Object