Created
April 19, 2021 22:51
-
-
Save shelajev/9b35e504c63da77fddd86f5497e95be8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.graalvm.polyglot.*; | |
import org.graalvm.polyglot.Context.Builder; | |
import org.graalvm.polyglot.proxy.*; | |
import java.util.*; | |
public class Main { | |
public static void main(String[] args) { | |
try (Context context = Context.newBuilder() | |
.allowAllAccess(true) | |
.build()) { | |
Map<String, Object> javaMap = new HashMap<>(); | |
javaMap.put("name", "GraalVM"); | |
javaMap.put("version", 21.1); | |
context.getBindings("js").putMember("javaMap", javaMap); | |
Value jsObject = context.eval("js", | |
"{ " + | |
"print(javaMap.name);" + | |
"print(javaMap.version);" + | |
" new Map([['hello','world'],[1, 42]]);"+ | |
"}"); | |
var map = jsObject.as(Map.class); | |
System.out.println(map + "; " + map.get("hello")); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment