Interface JsValue
- All Known Implementing Classes:
JsBoolean,JsUndefined
This hierarchy enables exhaustive pattern matching and ensures type safety when handling JS wrapper types at engine boundaries.
Two methods provide access to the underlying value:
getJavaValue()- Returns the idiomatic Java type for external usegetJsValue()- Returns the raw internal value for JS operations
Hierarchy:
JsValue (sealed)
├── JsUndefined (singleton)
├── JsPrimitive (sealed) - boxed primitives
│ ├── JsNumber
│ ├── JsString
│ └── JsBoolean
├── JsDateValue (sealed)
│ └── JsDate
└── JsBinaryValue (sealed)
└── JsUint8Array
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionReturns the idiomatic Java representation of this object.default ObjectReturns the raw internal value for use in JS operations (comparison, arithmetic, etc.).default ObjectReturns the original Java object this wrapper was constructed from, for fall-through to Java method dispatch when a property lookup misses on this wrapper's prototype.
-
Method Details
-
getJavaValue
Object getJavaValue()Returns the idiomatic Java representation of this object. Used when values leave the JS engine and need to be consumed by Java code.Examples: JsNumber → Number, JsDate → Date, JsUint8Array → byte[]
-
getJsValue
Returns the raw internal value for use in JS operations (comparison, arithmetic, etc.). This enables a consistent "unwrap first, then switch on raw types" pattern.Examples: JsNumber → Number, JsDate → Long (millis), JsUint8Array → byte[]
Default implementation delegates to
getJavaValue()which is correct for most types. Override when internal representation differs from external (e.g., JsDate stores long millis). -
getOriginalJavaValue
Returns the original Java object this wrapper was constructed from, for fall-through to Java method dispatch when a property lookup misses on this wrapper's prototype. Returnsnullwhen no original is available (the wrapper was built from raw JS values, or the JsValue type doesn't carry an original-value concept).For example, a
JsDatebuilt from aZonedDateTimereturns the originalZonedDateTimesozdt.format(formatter)can route to the Java method whenformatisn't on the JS Date prototype.Default returns
null— opt in by overriding.
-