FULL PRODUCT VERSION :
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) Client VM (build 25.60-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.3.9600]
A DESCRIPTION OF THE PROBLEM :
There is a bug while executing the following javascript program with Nashorn via command line:
jjs.exe program.js
Probably the dead code elimination corrupts the global scope, hence the Nashorn's predefined "print" function is undefined during runtime.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Save the following javascript program to file (program.js) and run it by CLI:
jjs.exe program.js
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
the expected output would be (as it does in other javascript engines):
string
string
ACTUAL -
the actual output is:
string
run.js:7 TypeError: Cannot call undefined
ERROR MESSAGES/STACK TRACES THAT OCCUR :
run.js:7 TypeError: Cannot call undefined
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
var x = "string";
print(x);
(function () {
(function () {
// print is undefined!
print(x);
})();
if (false) {
(function () {
var x;
})();
}
})();
---------- END SOURCE ----------