-
Notifications
You must be signed in to change notification settings - Fork 206
Description
In out Eclipse Product, we are moving away from using Nashorn Engine to GraalJS Engine. But, due to some constraints, I'm currently unable to make it work.
We have a project named 'org.graalvm.js' and has added all the required jars into the libraries folder and added it to the classpath. Extracted all the ServiceRegistry file to META-INF folder.
I have refered to the help documentation at: https://www.graalvm.org/latest/reference-manual/js/ScriptEngine/
And created my own plugin named 'com.pal.script' and in MyGraalJSScriptEngine class (in same plugin), I have tried to use the load a class from Host. I tried the same class itself. But, it says
Caused by: org.graalvm.polyglot.PolyglotException: TypeError: Access to host class com.bosch.wbp.scripting.commandline.WBPGraalJSScriptEngine is not allowed or does not exist. at <js>.:program(<eval>:1) at org.graalvm.polyglot.Context.eval(Context.java:402) at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:490) ... 36 more
The code is:
public MyGraalJSScriptEngine() { super("Graal VM"); System.setProperty("polyglot.engine.WarnInterpreterOnly", "false"); final ScriptEngineManager engineManager = new ScriptEngineManager(); this.fEngine = (GraalJSScriptEngine) engineManager.getEngineByName("GraalJS"); Bindings bindings = this.fEngine.getBindings(ScriptContext.ENGINE_SCOPE); bindings.put("polyglot.js.allowHostAccess", true); bindings.put("polyglot.js.allowHostClassLookup", (Predicate<String>) s -> { return true; }); this.fEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("javaObj", new Object()); String script = "(javaObj instanceof Java.type('com.pal.MyGraalJSScriptEngine'));"; try { this.fEngine.eval("(javaObj instanceof Java.type('java.lang.Object'));"); this.fEngine.eval(script); // This is not working } catch (ScriptException e) { e.printStackTrace(); } }
Any help would be appreciated.
Thanks,
Palraj