Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Graal JS in an Eclipse Content in context with Eclipse EASE in Java 17 environment #837

Open
PalrajJayarajBosch opened this issue Aug 27, 2024 · 1 comment

Comments

@PalrajJayarajBosch
Copy link

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

@iamstolis
Copy link
Member

I am sorry, but the information that you have provided is not sufficient to track the problem down. For example, your error mentions WBPGraalJSScriptEngine but this class/string is not part of the short code snippet that you have provided. Please, provide more information. It would be ideal to described exact steps that lead to the problem that you are facing. Thank you in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants