Interface JsValue

All Known Implementing Classes:
JsBoolean, JsUndefined

public sealed interface JsValue permits JsUndefined (not exhaustive)
Sealed interface hierarchy for JS value types that wrap Java values.

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 use
  • getJsValue() - 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 Type
    Method
    Description
    Returns the idiomatic Java representation of this object.
    default Object
    Returns the raw internal value for use in JS operations (comparison, arithmetic, etc.).
    default Object
    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.
  • 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

      default Object 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

      default Object 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. Returns null when 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 JsDate built from a ZonedDateTime returns the original ZonedDateTime so zdt.format(formatter) can route to the Java method when format isn't on the JS Date prototype.

      Default returns null — opt in by overriding.