The behavior of GraalVM JavaScript and Nashorn are quite different by default and you wil probably need to adjust a few things. See Graal's Migration Guide from Nashorn to GraalVM JavaScript for details.
When creating a GraalComplateRenderer using the default settings host access
is allowed for
ALL
and host class lookup, experimental options, and the option
js.experimental-foreign-object-prototype are enabled. If you have been using
NashornComplateRenderer before then you probably want to enable
js.nashorn-compat as well, for example
GraalComplateRenderer.of(source)
.withAdditionalContextCustomizations(ctx ->
ctx.option("js.nashorn-compat", "true"))
.build();Even after enabling full compatibility a few differences remain. Things that are known to have changed:
-
Java.fromin Graal will only translate JavaLists to JavaScript arrays while it used to work for any type of collection with Nashorn. -
If your view wants to read entries from a Java
MapthemapName.keysyntax doesn't work with Graal, you have to usemapName.get("key")instead. Alternatively you can work around this by wrapping theMapinstance with aorg.graalvm.polyglot.proxy.ProxyObject.
No, the GraalVM JavaScript engine relies on a model where JavaScript runtimes cannot be shared between different threads. For more details see https://medium.com/graalvm/multi-threaded-java-javascript-language-interoperability-in-graalvm-2f19c1f9c37b
When using GraalComplateRenderer in a multi-threaded environment (e.g. using
complate-spring-mvc) you may
encounter exceptions with a message like
Multi threaded access requested by thread Thread[...] but is not allowed for language(s) js.
You must wrap GraalComplateRenderer with ComplateThreadLocalRenderer when a
renderer could be used by multiple threads.