- GraalVM for JDK 23 (Latest)
- GraalVM for JDK 24 (Early Access)
- GraalVM for JDK 21
- GraalVM for JDK 17
- Archives
- Dev Build
- JavaScript and Node.js Reference
- Node.js Runtime
- Java Interoperability
- JavaScript Compatibility
- Using JavaScript Modules and Packages
- Multithreading
- Migration Guide from Nashorn to GraalVM JavaScript
- Migration Guide from Rhino to GraalVM JavaScript
- Differences Between Node.js and Java Embeddings
- Options
- Run GraalVM JavaScript on a Stock JDK
- ScriptEngine Implementation
- FAQ
Options
Running JavaScript on GraalVM can be configured with several options.
GraalVM JavaScript Launcher Options #
These options are to control the behaviour of the js
launcher:
-e, --eval CODE
: evaluate the JavaScript source code, then exit the engine.js -e 'print(1+2);'
-f, --file FILE
: load and execute the provided script file. Note that the-f
flag is optional and can be omitted in most cases, as any additional argument tojs
will be interpreted as file anyway.js -f myfile.js
--version
: print the version information of GraalVM JavaScript, then exit.--strict
: execute the engine in JavaScript’s strict mode.
GraalVM JavaScript Engine Options #
There are several options to configure the behavior of the GraalVM JavaScript engine. Depending on how the engine is started, the options can be passed either to the launcher or programmatically.
For a full list of options of the JavaScript engine, pass the --help:js
flag to the js
launcher (available from GraalVM 22.1., for older releases use --help:languages
).
To include internal options, use --help:js:internal
.
Note that those lists both include stable, supported options and experimental options.
Provide Options to the Launcher #
To the launcher, the options are passed with --js.<option-name>=<value>
:
js --js.ecmascript-version=6
Provide Options Programmatically Using the Context API #
When started from Java using GraalVM’s Polyglot API, the options are passed programmatically to the Context
object:
Context context = Context.newBuilder("js")
.option("js.ecmascript-version", "6")
.build();
context.eval("js", "42");
See the Polyglot Programming reference for information on how to set options programmatically.
Stable and Experimental Options #
The available options are distinguished in stable and experimental options. If an experimental option is used, an extra flag has to be provided upfront.
In the native launchers (js
and node
), --experimental-options
has to be passed before all experimental options.
When using a Context
, the option allowExperimentalOptions(true)
has to be called on the Context.Builder
.
See ScriptEngine Implementation on how to use experimental options with a ScriptEngine
.
Frequently Used Stable Options #
The following stable options are frequently relevant:
--js.ecmascript-version
: emulate a specific ECMAScript version. Integer value (5
,6
, etc.,2015
-2022
),"latest"
(latest supported version of the spec, including finished proposals), or"staging"
(latest version including supported unfinished proposals), default is"latest"
.--js.foreign-object-prototype
: provide JavaScript’s default prototype to foreign objects that mimic JavaScript’s own types (foreign Arrays, Objects and Functions). Boolean value, default isfalse
.--js.intl-402
: enable ECMAScript Internationalization API. Boolean value, default isfalse
.--js.regexp-static-result
: provide staticRegExp
properties containing the results of the last successful match, e.g.,RegExp.$1
(legacy). Boolean value, default istrue
.--js.strict
: enable strict mode for all scripts. Boolean value, default isfalse
.
For a complete list, use js --help:js:internal
ECMAScript Version
This option provides compatibility to a specific version of the ECMAScript specification.
It expects an integer value, where both the counting version numbers (5
, 6
, …) and the publication years (starting from 2015
) are supported.
As of GraalVM 21.2, latest
, staging
are supported, too.
The default in GraalVM 22.x is the ECMAScript 2022 specification
.
GraalVM JavaScript implements some features of the future draft specification and of open proposals, if you explicitly select that version and/or enable specific experimental flags.
For production settings, it is recommended to set the ecmascript-version
to a released, finalized version of the specification (e.g., 2022
).
Available versions are:
5
for ECMAScript 5.x6
or2015
for ECMAScript 20157
or2016
for ECMAScript 20168
or2017
for ECMAScript 20179
or2018
for ECMAScript 201810
or2019
for ECMAScript 201911
or2020
for ECMAScript 202012
or2021
for ECMAScript 2021 (default in 21.3)13
or2022
for ECMAScript 2022 (default in 22.0+, latest released version, ECMAScript 2022 specification)latest
for the latest supported language version (the default version)staging
for the latest supported language features including experimental unstable, unfinished proposals (do not use in production!)
intl-402
This option enables ECMAScript’s Internationalization API.
It expects a Boolean value and the default is false
.
Strict Mode
This option enables JavaScript’s strict mode for all scripts.
It expects a Boolean value and the default is false
.
Frequently Used Experimental Options #
Note that these options are experimental and are not guaranteed to be maintained or supported in the future.
To use them, the --experimental-options
flag is required or the experimental options have to be enabled on the Context, see above.
--js.nashorn-compat
: provide compatibility mode with the Nashorn engine. Sets ECMAScript version to 5 by default. Might conflict with newer ECMAScript versions. Boolean value, default isfalse
.--js.timezone
: set the local time zone. String value, default is the system default.--js.v8-compat
: provide better compatibility with Google’s V8 engine. Boolean value, default isfalse
.