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

Graal jrunscript does not work #546

Closed
davidpcaldwell opened this issue Jul 13, 2018 · 4 comments
Closed

Graal jrunscript does not work #546

davidpcaldwell opened this issue Jul 13, 2018 · 4 comments
Assignees
Labels

Comments

@davidpcaldwell
Copy link

Graal version: 1.0.0-rc3 (Mac OS X)

Graal command:
jrunscript jrunscript.js

Script (jrunscript.js)
print("Hello, jrunscript!");

Graal result:
script error in file : org.graalvm.polyglot.PolyglotException: ReferenceError: java is not defined
Exit status: 10

Expected result (JVM jrunscript)
Hello, jrunscript!

@iamstolis iamstolis self-assigned this Jul 18, 2018
@iamstolis
Copy link
Member

Thank you for your report. You are right, jrunscript is broken in GraalVM rc3. jrunscript uses ScriptEngine internally and executes some initialization script on the start-up. This initialization script uses some JavaScript extensions like java, JSAdapter provided by Nashorn engine by default. Unfortunately, the ScriptEngine wrapping Graal JavaScript has the support for these extensions turned off (by default). That's why the execution fails with the complains about unknown global variable called java.

We will fix this problem by enabling the mentioned extensions in our implementation of ScriptEngine. You can experiment with turning these extensions on explicitly using jrunscript -Dtruffle.js.NashornJavaInterop=true (in rc3 build) but note that this option is experimental and will disappear in future.

@thomaswue thomaswue added the bug label Jul 19, 2018
@iamstolis
Copy link
Member

This problem has been fixed by oracle/graaljs@50995a3 i.e. it will be part of rc5 build (hopefully). In case you switch to rc4 build before that note that a different workaround is needed there: you can use jrunscript -J-Dpolyglot.js.nashorn-compat=true. Plain jruncript should work in rc5 (once it is released).

@davidpcaldwell
Copy link
Author

Actually, @iamstolis, it worked out-of-the-box:

Graal command:
js --js.nashorn-compat=true --jvm jrunscript.js

Script (jrunscript.js)
print("Hello, jrunscript!");


Graal result (1.0.0-rc4):
Hello, jrunscript!

Expected result (JVM jjs)
Hello, jrunscript!

@lscoughlin
Copy link

so like...


🦄 ~ $ uname -a
Darwin mbp-2016.attlocal.net 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 18 20:50:10 PDT 2020; root:xnu-4903.278.43~1/RELEASE_X86_64 x86_64

🦄 ~ $ which jrunscript
/Library/Java/JavaVirtualMachines/graalvm-ee-java11-20.2.0/Contents/Home/bin/jrunscript

🦄 ~ $ jrunscript -e "print('hello world');"
script error in file <system-init> : org.graalvm.polyglot.PolyglotException: ReferenceError: java is not defined

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

No branches or pull requests

4 participants