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> TCoerces this JavaScript value to the requested Java type.boolean[]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(Object value) Checks whether the given value is the JavaScriptundefinedvalue.static booleanisUndefined(JSValue value) Specialization ofisUndefined(Object)that avoids the type check forJSValue.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 usingas(Class). 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
Specialization ofisUndefined(Object)that avoids the type check forJSValue. -
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
Coerces this JavaScript value to the requested Java type. SeeJS.Coercefor the JavaScript to Java coercion rules.- Parameters:
cls- The Java type to coerce to.- Returns:
- The non-null coerced value of the requested type.
- Throws:
ClassCastException- If this value cannot be coerced to the requested type.
-
toString
-