High-performance JavaScript with GraalVM
Run JavaScript applications faster and more efficiently with GraalVM
Benefits
Latest JavaScript features
GraalVM is fully compatible with the ECMAScript 2021 specification
High performance on the JVM
Run JavaScript faster using fewer resources
Node.js support
Run Node.js apps and use packages in Java and other languages
Interoperability with Java
Share data and code with other GraalVM languages like Java, Ruby, Python, LLVM, R, and others
Easy upgrade from Nashorn
GraalVM supports all Nashorn features, improves performance, and includes all the latest ECMAScript features
Advanced tools
JavaScript is supported by GraalVM tools including Insight, VisualVM, Chrome Debugger, VS Code extensions, and others
High Performance
GraalVM Community, GraalVM Enterprise, and V8 Benchmarks Comparison
There are significant benefits with the GraalJS runtime environment and how that gives SuiteScript developers access to the most current ECMAScript features and syntax out of the box. Aligning SuiteScript with ECMAScript delivers enhanced developer productivity, more maintainable code and ensures ongoing conformance to an evolving standard.
Use Cases
Run JavaScript on GraalVM for optimal performance
JavaScript on GraalVM leverages the Graal compiler to provided unparalleled performance
Examples
Java <> JavaScript Interoperability
importorg.graalvm.polyglot.*;
public classExample1Context {
public staticvoid main(String[] args) {
System.out.println("[Java] Hello, Java!");
try (Context context = Context.newBuilder("js").option("js.ecmascript-version", "2020").build()) {
Value jsFunction = context.eval("js", "" +
"(function myJavaScriptFunction(parameter) { \n" +
" console.log('[JS] Hello, ' + parameter + '!'); \n" +
" return parameter.toUpperCase(); \n" +
"}) \n");
Value result = jsFunction.execute("JavaScript");
if (result.isString()) {
System.out.println("[Java] result: " + result.asString());
} else {
System.out.println("[Java] unexpected result type returned from JavaScript");
}
}
}
}
Using Ruby in Node.js App on GraalVM
import// make sure to install the libraries first: `npm install http ansispan colors`
public classconst http = require("http");
public classconst span = require("ansispan");
require("colors");
http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/html"});
response.write(span("Hello Graal.js!< br/>".green));
/start with `node --jvm --polyglot Example2Interop.js` to enable interop with Ruby:
try {
response.write("Ruby: " + Polyglot.eval("ruby", "[41,42,43]")[1] + "
");
} catch (ex) {
// Polyglot.eval("ruby", ...) failed
response.write("Ruby language not found
");
{
response.end("Request completed");
}).listen(8000, function() { console.log("Graal.js server at http://127.0.0.1:8000/".red); });
/*
to execute:
$ npm install http ansispan colors
$ node --jvm --polyglot Example2_Interop.js
*/