Discussion:
ES6 and JavaImporter
Brad Grier
2018-01-19 03:06:28 UTC
Permalink
Hello,

I wanted to experiment with the Java 9 ES6 features in my software.
Unfortunately I can't get far because of an issue involving JavaImporter. I
created a simple jjs example that illustrates the problem. The script works
under ES5 but fails under ES6 with: ./pg4.js:6 ReferenceError: "printIt"
is not defined

#!/usr/bin/jjs -J-Dnashorn.args=--language=es6

var imports = new JavaImporter(java.util);
with(imports){

function printIt(a){
print("map: " + a);
}

function printAndClear(b){
printIt(b);
b.clear();
}

var map = new HashMap();
map.put('js', 'javascript');
map.put("java", "java");
printAndClear(map);
}

Thanks. I'm using build 9.0.1+11 on OS X.

Brad
Hannes Wallnöfer
2018-01-19 14:24:02 UTC
Permalink
Brad,

I as I wrote in my last reply to this list, ES6 support is quite incomplete in Nashorn.

However, that doesn’t really explain this error. I’m looking into it and will file a bug.

Hannes
Post by Brad Grier
Hello,
I wanted to experiment with the Java 9 ES6 features in my software.
Unfortunately I can't get far because of an issue involving JavaImporter. I
created a simple jjs example that illustrates the problem. The script works
under ES5 but fails under ES6 with: ./pg4.js:6 ReferenceError: "printIt"
is not defined
#!/usr/bin/jjs -J-Dnashorn.args=--language=es6
var imports = new JavaImporter(java.util);
with(imports){
function printIt(a){
print("map: " + a);
}
function printAndClear(b){
printIt(b);
b.clear();
}
var map = new HashMap();
map.put('js', 'javascript');
map.put("java", "java");
printAndClear(map);
}
Thanks. I'm using build 9.0.1+11 on OS X.
Brad
Loading...