Class JSValue
java.lang.Object
org.graalvm.webimage.api.JSValue
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 Summary
Modifier and TypeMethodDescription<T> Tboolean[]asByte()byte[]asChar()char[]asDouble()double[]asFloat()float[]asInt()int[]asLong()long[]asShort()short[]asString()static <R> RcheckedCoerce(Object value, Class<R> cls) Attempts to coerce a given value to the specified Java type.booleanChecks whether this is the JavaScriptundefinedvalue.static booleanisUndefined(JSValue value) Checks whether the given value is the JavaScriptundefinedvalue.protected abstract StringtoString()abstract Stringtypeof()static JSUndefined
-
Method Details
-
checkedCoerce
Attempts to coerce a given value to the specified Java type.If the value is a
JSValue, it will be converted using itsas(...)method. Otherwise, the value is cast directly.- Type Parameters:
R- the return type- Parameters:
value- the value to coerce, which may be aJSValueor a native Java objectcls- 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
Checks whether the given value is the JavaScriptundefinedvalue.- See Also:
-
isUndefined
public boolean isUndefined()Checks whether this is the JavaScriptundefinedvalue. -
undefined
-
typeof
-
stringValue
-
asBoolean
-
asByte
-
asShort
-
asChar
-
asInt
-
asFloat
-
asLong
-
asDouble
-
asBigInteger
-
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
-
toString
-