Number of Nashorn bugs in JIRA is way too low

André Bargull andrebargull at googlemail.com
Tue Sep 17 02:26:14 PDT 2013


Apparently I've never reported the following bugs, shame on me! :(
Fortunately (or rather unfortunately) they are still reproducible on hg tip.

- André


StackOverFlowError in LambdaForm bootstrapping is annoying to handle:

Test 1:
jjs> function test() { try { test(); } catch(e) { throw e+""} }
function test() { try { test(); } catch(e) { throw e+""} }
jjs> try { test(); } catch (e) {e.printStackTrace()}
java.lang.NoClassDefFoundError: Could not initialize class 
jdk.nashorn.internal.runtime.ConsString
jjs> try {""+{}}catch(e){e.printStackTrace()}
java.lang.NoClassDefFoundError: Could not initialize class 
jdk.nashorn.internal.runtime.ConsString

Test 2:
jjs> function test() { try { test(1,test(1)); } catch(e) { throw 
function(){throw e}()} }
function test() { try { test(1,test(1)); } catch(e) { throw 
function(){throw e}()} }
jjs> try { test(); } catch (e) {e}
java.lang.BootstrapMethodError: call site initialization exception



jjs> (function f(o){with(o){  }})()

Expected: should have thrown TypeError


jjs> (function(){ try{throw 0} catch(e){try { try {throw 1}catch(e){ 
return e }  } finally {print(e)}}  })()

Expected: 0 - 1
Actual: 1 - 1


jjs> (function(o){ try{with(o){return x}}finally{return x} })({x: 1})

Expected: ReferenceError


jjs> (function(){ eval("print('fail')", x)  })()

Expected: ReferenceError


jjs> (function f(){return f; var f})()
function f(){return f; var f}

Expected: undefined


jjs> (function f(){return eval("f")})()

Expected: function f(){...}


jjs> (function f(){return eval("f")})()
jjs> (function f(){return function(){return eval("f")}()})()
java.lang.ClassCastException: Cannot cast 
jdk.nashorn.internal.scripts.JO0P0 to jdk.nashorn.internal.scripts.JO1P0


jjs> (function(x){var o={x:0}; with(o){delete x} return o.x})()

Expected: undefined


jjs> String.prototype[3] = "hello"; Object.prototype[4] = "world"; for 
(var i in "123")print(i)

Expected: 0 1 2 3 4


jjs> (function f(){var a,b; with(a={set x(v){print("fail")}})with(b={get 
x(){delete this.x; return 0}})x-=1; return b.x})()

Expected: -1, don't print "fail"


jjs> (function(global){"use strict"; 
Object.defineProperty(global,"x",{get: function(){delete global.x; 
return 0}, configurable:true}); x-=1  })(this)

Expected: global "x" is -1
Actual: ReferenceError


jjs> (function(global){"use strict"; 
Object.defineProperty(global,"x",{get: function(){delete global.x; 
return 0}, configurable:true}); x--  })(this)

Expected: global "x" is -1
Actual: ReferenceError


jjs> (function f(){ Object.defineProperty({},"x",{get: function(){return 
{valueOf:function(){throw 0}}}}).x -= Object.defineProperty({},"x",{get: 
function(){throw 1}}).x  })()

Expected: throws 1
Actual: throws 0


jjs> (function f(){ Object.defineProperty({},"x",{get: function(){return 
{valueOf:function(){throw 0}}}}).x - Object.defineProperty({},"x",{get: 
function(){throw 1}}).x  })()

Expected: throws 1
Actual: throws 0


jjs> (function f(){try{throw 0}catch(e){print(e); eval("var e=1"); 
print(e); eval("delete e"); print(e)} print(e) })()

Expected: 0 1 1 undefined
Actual: 0 0 0 1


jjs> describe = function(o, 
pk){print(JSON.stringify(Object.getOwnPropertyDescriptor(o,pk)))}
function(o, 
pk){print(JSON.stringify(Object.getOwnPropertyDescriptor(o,pk)))}
jjs> var x=0; eval("var y=0")
jjs> describe(this,"x"); describe(this,"y")
{"configurable":false,"enumerable":true,"writable":true,"value":0}
{"configurable":false,"enumerable":true,"writable":true,"value":0}

Expected: second property descriptor is configurable=true
Actual: second property descriptor is configurable=false


jjs> "use strict"; throw "not early"; delete x

Expected: early SyntaxError (spec is a bit unclear here)


jjs> (function(){var x; (function(){"use strict"; eval("delete x"); 
})(); })()
jjs> (function(){var x; (function(){ eval("delete x"); })(); })()

Expected: Second expression should not throw SyntaxError
Actual: SyntaxError from first expression also thrown in second expression


jjs> ({valueOf: function(){throw 0}}) - ({valueOf: function(){throw 1}} - 1)

Expected: throws 1
Actual: throws 0


jjs> (function f(){ if(0){var x}; return x })()

Expected: returns undefined
Actual: ReferenceError "x" is not defined


jjs> function f(){ try{throw null}catch(e){return}finally{return e} var 
e; }; print(f())

Expected: prints "undefined"
Actual: prints "null"


jjs> function f(){ try{throw null}catch(e){return}finally{} return 3; }; f()
0
jjs> function f(){ try{throw null}catch(e){return}finally{} return true; 
}; f()
false
jjs> function f(){ try{throw null}catch(e){return}finally{} return 2.1; 
}; f()
NaN

Expected: returns always "undefined"


jjs> function f(){ do{do{break}while(0); return}while(0);  }

Expected: outer do-while's body is marked as terminal (inspect generated 
bytecode, dup of JDK-8012472?)

jjs> function f(v){switch(v){case 0: case 1: return "zero-or-one"; 
default: return "other"}}

Expected: switch is marked as terminal (inspect generated bytecode)


jjs> function f(v){switch(0){case 0: return "ups"; case false: return "aw"}}
java.lang.ClassCastException: java.lang.Boolean cannot be cast to 
java.lang.Integer


jjs> Object.defineProperty(this,"x",{value:0})
[object global]
jjs> eval("function x(){}")
0

Expected: Throw TypeError
Actual: no TypeError

jjs> 
Object.defineProperty(this,"x",{value:0,writable:true,enumerable:false})
[object global]
jjs> eval("function x(){}")
function x(){}

Expected: Throw TypeError
Actual: no TypeError


jjs> Object.defineProperty(this,"x",{set: function(v){print("fail")}})
[object global]
jjs> eval("function x(){}")
function x(){}

Expected: Throw TypeError
Actual: prints "fail"


jjs> (function f(v){switch(v|0){}})({valueOf: function(){throw 0}})

Expected: throws 0
Actual: no exception thrown

Also: tableswitch never emitted for size < 4!


jjs> (function(global){var x=1; with(global){eval("eval('var x=0')")} 
return x})(this)
Expected: 0
Actual: 1

jjs> (function(global){var x=1; with({eval: 
global.eval}){eval("eval('var x=0')")} return x})(this)
Expected: 0
Actual: 1


jjs> s = ""; for (i = 0; i < 1000; ++i) s+="o = new Object()\n"; 
s+="g()"; try{eval("function f(){"+s+"}")()}catch(e){e.stack+""}

Expected: $split method not present in stacktrace
Actual: $split method in stacktrace


jjs> 1/(new Date(1969, 8, 1)).getHours()

(-Duser.timezone=America/Los_Angeles)
Expected: Infinity
Actual: -Infinity


jjs> function RandomObject() {  this.toString = function() { return 
(Math.random() * 100).toString(); } }
jjs> for (var j=0; j <100; ++j) {var arr = []; for (var i = 0; i < 64; 
++i) arr[i] = new RandomObject; arr.sort();}

Expected: no IllegalArgumentException is thrown
Actual: java.lang.IllegalArgumentException: Comparison method violates 
its general contract!


jjs> x = "global"; (function(){eval("var x='local'"); delete x; return x})()
local
jjs> x = "global"; (function(){eval("var x='local'"); delete x; return x})()
jjs>

Expected: "global" "global"
Actual: "local" -


More information about the nashorn-dev mailing list