Class GraalJsValueUtil
Deep-copies a GraalJS-produced Map/List into plain
LinkedHashMap/ArrayList instances - see issue #3236.
GraalJS's JSR-223 wrapper never materializes a returned JS object/array into a plain Java
collection: it hands back a lazy com.oracle.truffle.polyglot.PolyglotMap/
PolyglotArray view that calls back into the org.graalvm.polyglot.Context it came from
on every real access (e.g. entrySet()). Callers that dispose that Context's
engine right after the script returns - as every GraalJS evaluation does since issue #3185 -
leave any such value unusable the moment anything touches it, throwing
IllegalStateException: The Context is already closed.
Detection is purely by the value's own runtime class name, never by importing any
org.graalvm/com.oracle.truffle type: those classes are only ever an optional,
reflectively-loaded runtime dependency of GraalJS's embedders, never a compile-time dependency
here. This also means an ordinary, non-GraalJS Map/List (e.g. one a Java
delegate or a different script engine produced) is left completely untouched - only values
actually backed by GraalJS's Truffle/Polyglot implementation are ever copied.
-
Method Summary
-
Method Details
-
materialize
- Parameters:
value- the value to materialize, as returned by a GraalJS script/expression evaluation- Returns:
valueunchanged if it is not itself backed by GraalJS's Truffle/Polyglot implementation - an ordinary JavaMap/List(or any other object) is never inspected, let alone copied; otherwise a deep copy in whichvalueand every Polyglot-backedMap/Listreachable from it has been replaced by a plainLinkedHashMap/ArrayList- safe to use after theContextthat producedvaluehas been closed
-