graal icon indicating copy to clipboard operation
graal copied to clipboard

Broken ScriptEngine for js after 22.2.0

Open elmart-devo opened this issue 2 years ago • 2 comments

Hi,

I'm executing js snippets in my graalvm through the ScriptEngine interface (this is an old app that used to use Nashorn and we haven't migrated to use Contexts directly). This was working perfectly with previous graalvm versions until 22.2.0. On 22.2.0 release, it is said that support for js is now a module that has to be installed with gu install js. I do so, but even after that, it seems the ScriptEngine for extension "js" is not found anymore. new ScriptEngineManager().getEngineByExtension("js") is now returning null.

Do I have to do anything extra, in addition to gu install js, or is this a bug?

elmart-devo avatar Sep 13 '22 14:09 elmart-devo

Thank you for the report. We are aware of this unfortunate regression, which was caused by the removal of js from the base distribution. We will fix this in the 22.3.0 release.

In the meantime, you can probably work around this issue by pulling js-scriptengine.jar from maven and explicitly adding it to the class/module path or as a maven dependency.

woess avatar Sep 15 '22 17:09 woess

Okay. Thx very much for your quick response.

elmart-devo avatar Sep 15 '22 17:09 elmart-devo

Hi, I just saw 22.3 release notes. It seems solution to this was not finally included there. I would just like to get confirmation on that, please.

elmart-devo avatar Nov 02 '22 12:11 elmart-devo

The solution should be included in 22.3. We probably just forgot to mention it in the release notes.

woess avatar Nov 10 '22 00:11 woess

Ok, checked and true. Thx! Closing this.

elmart-devo avatar Nov 10 '22 12:11 elmart-devo

Reopening this, as it seems even if I can install the js engine with gu install js, I cannot later find it using new ScriptEngineManager().getEngineByExtension("js"). That returns null, no matter js seems to have been correctly installed. Looking at the code I see a JS_ENABLED here and there that is always false. Do I need to launch the JVM with some flag or similar?

elmart-devo avatar Nov 15 '22 16:11 elmart-devo

Reopening this, as it seems even if I can install the js engine with gu install js, I cannot later find it using new ScriptEngineManager().getEngineByExtension("js").

I am sorry, I am not able to reproduce this issue. I have just downloaded graalvm-ce-java17-linux-amd64-22.3.0.tar.gz (from this page). Extracted it. Installed js and I am able to find GraalJSScriptEngine using your code snippet (and use the engine to evaluate some basic JavaScript code):

graalvm-ce-java17-22.3.0/bin$ ./gu install js
Downloading: Component catalog from www.graalvm.org
Processing Component: Graal.js
Downloading: Component js: Graal.js from github.com
Installing new component: Graal.js (org.graalvm.js, version 22.3.0)
graalvm-ce-java17-22.3.0/bin$ ./jshell
|  Welcome to JShell -- Version 17.0.5
|  For an introduction type: /help intro

jshell> new javax.script.ScriptEngineManager().getEngineByExtension("js")
$1 ==> com.oracle.truffle.js.scriptengine.GraalJSScriptEngine@bccb269

jshell> new javax.script.ScriptEngineManager().getEngineByExtension("js").eval("Math.PI")
$2 ==> 3.141592653589793

iamstolis avatar Nov 18 '22 10:11 iamstolis

You're right. My problem was now a strange issue in IntelliJ. For some reason, it was adding another JDK, different than the project one, to the class path, and using classes from that other JDK to evaluate expressions in the debugger. In particular, when I run new ScriptEngineManager(), it was picking manager from that other JDK, which did not have the js runtime installed. Once that has been solved, everything works as expected.

Closing this again. Thx very much.

elmart-devo avatar Nov 22 '22 07:11 elmart-devo