javascript - Multi-threaded Nashorn: o.constructor === o.constructor gives false -
i'm experimenting multi-threaded scripts loading , evaluation in nashorn , kind of shocking behavior:
// having object o loaded in thread print(o.constructor === o.constructor); // false print(o.constructor === object); // false print(o.foo === o.foo); // true - ok how can possible within single script engine? o above object created using object literal notation (in thread). printing o.constructor gives usual function object() { [native code] };.
at same time:
print({}.constructor === {}.constructor); // true any ideas?
update
it turned out unrelated multi-threading @ all. see answer below details.
it turned out not relate multi-threading @ all. here simple scala program reproduces problem:
object test extends app {   val engine = new scriptenginemanager().getenginebyname("nashorn")   var o = engine.eval("({ foo: 'bar' })")   var result = engine.eval("(o.constructor === o.constructor)", new simplebindings() {     put("o", o)   })   print(result) // false } i using bindings parameter incorrectly. instead, should take existing bindings , update 'em in-place. i'm still not convinced should result in o.constructor === o.constructor false, @ least works now. corrected version:
object test extends app {   val engine = new scriptenginemanager().getenginebyname("nashorn")   var o = engine.eval("({ foo: 'bar' })")    val bindings =  engine.getbindings(scriptcontext.engine_scope)   bindings.put("o", o)    var result = engine.eval("(o.constructor === o.constructor)", bindings)   print(result) // true } 
Comments
Post a Comment