A JavaScript implementation that runs on GraalVM. See tags "javascript" and "graalvm". Use this tag for questions regarding running JavaScript code using GraalJS.
Questions tagged [graaljs]
67 questions
6
votes
1 answer
Is it possible to store and load precompiled js to org.graalvm.polyglot.Context
It there any way to convert javascript source into some pre-compiled stated that can be stored and loaded somehow to org.graalvm.polyglot.Context instead of eval-ing it as a raw String? Something like undocumented --persistent-code-cache in nashorn.…

shabunc
- 23,119
- 19
- 77
- 102
5
votes
0 answers
Stencil.js: component level server side rendering
The stencil docs propose a way for server side rendering that works on a page level. It creates one whole of a hydrate app, which holds all the components created in a single index.js file which consumes whole of a HTML source page as input.
Is…

user3250183
- 506
- 6
- 19
4
votes
2 answers
GraalJS: how to get rid of these warnings?
We're using GraalVM.js as a ScriptEngine in our application. The goal is to have a Java JRE that can run user-defined javascript scripts to extend functionality.
MVCE:
ScriptEngine engine = GraalJSScriptEngine.create(null,…

colouredmirrorball
- 199
- 11
3
votes
1 answer
Graal.js importing module causes org.graalvm.polyglot.PolyglotException: SyntaxError: Expected an operand but found import
I am trying to use experimental ES module support from Grall.js.
I use following scripts: ES module "lib"
export const sqrt = Math.sqrt;
export function square(x) {
return x * x;
}
export function diag(x, y) {
return sqrt(square(x) +…

tporeba
- 867
- 10
- 23
3
votes
4 answers
Access Java object from JavaScript in GraalVM Polyglot context
Running on GraalVM CE.
openjdk version "11.0.5" 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-jvmci-19.3-b05-LTS)
OpenJDK 64-Bit GraalVM CE 19.3.0 (build 11.0.5+10-jvmci-19.3-b05-LTS, mixed mode, sharing)
Case 1:
import…

Woland
- 623
- 2
- 13
- 31
2
votes
2 answers
GraalVM: forbidding methods of certain classes to be called from scripts
We are using GraalVM for some scripting requirements in our product. The version of the GraalVM is 21.2.0 We are using JavaScript and Groovy. We want to forbid some methods on certain classes from using in scripts.
Example :
mytest.js
var…

Sushen Sable
- 21
- 1
2
votes
1 answer
GraalVM JS: How I do pass Truffle options via Bindings (Nashorn compat mode) and Context in a Java application?
I'm trying to understand performance of my JavaScript running within a Java application but I can't find a way to pass Truffle options through the Java interfaces like Bindings (when in Nashorn compat mode) and Context.
Specifically, I'm trying to…

Lester
- 113
- 8
2
votes
1 answer
Is there a way to use a java object as an argument for a function and return one of said objects's values in GraalJS?
I want to use a Java object new Train() as an argument to pass into a JavaScript function, here is the Java code
public void execute() {
File script = new File("/Test.js");
ScriptEngine engine = new…

Lenny Boi
- 23
- 3
2
votes
1 answer
GraalSDK Value as JSON structure
I'm trying to get the result of a JavaScript call to resemble a JSON structure of Map where the values may be number, string, boolean, objects (Maps) or arrays (Lists), similar to what Jackson does if you convert a value to a…

Brecht Yperman
- 1,209
- 13
- 27
2
votes
1 answer
How to exit infinite JS execution loop when reading/loading Javascript in Java using GraalVM?
I found sandbox options as a way to set sandbox.MaxCPUTime in the graalVM documentation, to limit how long the thread runs - https://www.graalvm.org/reference-manual/embed-languages/
I've tried the following code -
try (Context…

Osy
- 115
- 1
- 6
- 22
2
votes
1 answer
Difference between SimpleBindings vs ScriptEngine.createBindings() (Graal and Nashhorn)
Note, I use both Nashhorn and Graal, so it's possible that the ScriptEngine used below is an instance of GraalJSScriptEngine or the nashhorn engine.
When I call createBindings using the GraalJSScriptEngine engine:
Bindings bindings =…

rmf
- 625
- 2
- 9
- 39
2
votes
0 answers
Replace nashorn with graalVM
I am migrating a Javascript engine from Nashorn to GraalVm and it's failing to instantiate GraalJSScriptEngine/ScriptEngine.
I tried different ways of doing it:
GraalJSEngineFactory factory = new GraalJSEngineFactory();
GraalJSScriptEngine engine…

rajnikant7008
- 76
- 2
- 10
2
votes
1 answer
Artifact for making it possible to debug graaljs in Chrome
I'm trying to adopt debugging in graaljs:
Context.newBuilder("js")
.option("inspect", port)
.option("inspect.Path", path)
.option("inspect.Remote", remoteConnect)
java.lang.IllegalArgumentException:…

shabunc
- 23,119
- 19
- 77
- 102
2
votes
1 answer
Graal Javascript - thread safety
What is the recommended way to use Graal.js in a multi-threaded application (such as per servlet request)? We are using Graal.js like this
jsContext = Context.newBuilder("js").allowAllAccess(true).build();
bindings =…

adamM
- 1,116
- 10
- 29
1
vote
1 answer
How can I get Graal.js to handle a custom numeric Java type?
To dive in, we have an app where we have had Nashorn embedded.
With 17 I'm replacing it with GraalJS and there are some issues.
The current one is where I want GraalJS treat a custom class as an int (or double)for the purpose of basic arithmetic…

Erik
- 2,013
- 11
- 17