Alan
Alan

Reputation: 9620

ECMA 6 support in Nashorn

I just tried out Nashorn and it seems not to support Array.prototype.fill. Is this surprising? Is there a timeline somewhere for Nashorn's intended support? Is the best way to get an array of say 5 0s in Nashorn currently Array.apply(null, Array(5)).map(x=>0)?

Upvotes: 5

Views: 6962

Answers (3)

Bruno Gonçalves
Bruno Gonçalves

Reputation: 51

As mentioned, some features have been implemented. What I didn't find in any answer is how to activate it at runtime.

Currently, using the standalone version (Nashorn was removed in JRE 15) you can enable ES6 (partial) with:

System.setProperty("nashorn.args","--language=es6");

Make sure the property has been set before use. I suggest adding the code below to the class that contains main or another initialization point.

static {
    System.setProperty("nashorn.args","--language=es6");
}

To get more info about standalone version: https://github.com/openjdk/nashorn

Upvotes: 1

metasoarous
metasoarous

Reputation: 2943

This documentation would have me believe that you can get ES6 even in Java 8 by using -Dnashorn.args=--language=es6:

https://developer.oracle.com/databases/nashorn-javascript-part2

Indeed, I managed to get some basic ES6 support from Clojure (adding :jvm-opts ["-Dnashorn.args=--language=es6"] to project.clj), though I was still not able to load the library I wanted, so there may indeed still be pieces missing.

Upvotes: 4

Panu Logic
Panu Logic

Reputation: 2271

Seems there is partial support for ES6 in Java9 and more coming later: https://www.oracle.com/corporate/features/nashorn-javascript-engine-jdk9.html

Also see: http://openjdk.java.net/jeps/292

Upvotes: 3

Related Questions