-
Hi everyone, With this post I would like to ask a question. I've created a small Java (8) app which executes Javascripts using GraalVM, as a replacement for the Nashorn engine. What I would like to know if (and how) it's possible to extend the Javascript Syntax, by creating some extensions? I need some basic stuff like this ...
I just need a few additional basic classes (based on the ExtendScript language) like File, Folder, XML, ... etc ... If i'm not mistaking, using Nashorn it should be possible to create such extentions. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hi @tmmlsBE thanks for your question. We do have a few additional built-ins like To provide implementations from Java to JavaScript, you can use our interoperability support. Have a look at https://github.com/oracle/graaljs/blob/master/docs/user/JavaInteroperability.md - in short, you can either use something like Using Node.js modules as you state is a possibility as well. You could use a package bundler like Browserify or Webpack to achieve that. Note that this only works if the eventloop (and other Node.js internals) are not used, and there are no dependencies on Node.js-internal packages ("fs", etc.) OR those dependencies can be substituted by the bundler. You can also load some Node.js modules directly via our
Note that we try to be mostly compatible with Nashorn, but ultimately, we are an independent engine. For instance, you will see best results if you use Best, |
Beta Was this translation helpful? Give feedback.
Hi @tmmlsBE
thanks for your question.
We do have a few additional built-ins like
read(file)
but most likely, this will not cover all your use-cases. See https://github.com/oracle/graaljs/blob/master/docs/user/JavaScriptCompatibility.md#additional-global-functions-in-the-js-shellTo provide implementations from Java to JavaScript, you can use our interoperability support. Have a look at https://github.com/oracle/graaljs/blob/master/docs/user/JavaInteroperability.md - in short, you can either use something like
var JavaClass = Java.type("com.domain.classname");
to load Java classes into JavaScript and then use them very similar to normal JavaScript code. Or, you expose functionality wrapped…