GraalVM JavaScript can be configured with several options provided when starting the engine.
Additional options control the behaviour of the js binary launcher.
The js launcher can be configured with the following options:
Evaluate the passed in JavaScript source code, then exit the engine.
js -e 'print(1+2);'
Load and executed the provided script file.
js -f myfile.js
Note that the -f flag is optional and can be omitted in most cases, as any additional argument to js will be interpreted as file anyway.
Prints the version information of GraalVM JavaScript and then exits.
Executes the engine in JavaScript's strict mode.
The engine options configure the behavior of the JavaScript engine. Depending on how the engine is started, the options can be passed in different ways:
To the launcher, the options are passed with --js.<option-name>=<value>:
js --js.ecmascript-version=6
When started from Java via GraalVM's Polyglot feature, the options are passed to the Context object:
Context context = Context.newBuilder("js")
.option("js.ecmascript-version", "6")
.build();
context.eval("js", "42");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, 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.md on how to use experimental options with a ScriptEngine.
Stability: stable
Provides compatibility to a specific version of the ECMAScript specification.
Expects an integer value, where both the counting version numbers (5 to 11) and the publication years (starting from 2015) are supported.
The default is the latest finalized version of the specification, currently the ECMAScript 2019 specification.
Starting with GraalVM 20.1.0, the default will be moved to the draft ECMAScript 2020 specification.
Graal.js 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 an existing, finalized version of the specification.
Available versions:
5for ECMAScript 5.x6or2015for ECMAScript 20157or2016for ECMAScript 20168or2017for ECMAScript 20179or2018for ECMAScript 201810or2019for ECMAScript 2019 (latest finalized version of the specification)11or2020for ECMAScript 2020 (currently in draft stage, mostly supported by GraalVM JavaScript)12or2021for ECMAScript 2021 (advanced proposals not expected to land in ECMAScript 2020)
Stability: stable
Enable ECMAScript's Internationalization API.
Expects a Boolean value, the default is false.
Stability: stable
Enables JavaScript's strict mode for all scripts.
Expects a boolean value, default is false.