多线程 Nashorn: o.constructor === o.constructor 给出 false
Multi-threaded Nashorn: o.constructor === o.constructor gives false
我正在 Nashorn 中尝试多线程脚本加载和评估,并得到了令人震惊的行为:
// having some object o loaded in another thread
print(o.constructor === o.constructor); // false
print(o.constructor === Object); // false as well
print(o.foo === o.foo); // true - OK
这在单个脚本引擎中如何实现? 上面的o
只是一个使用对象文字表示法(在另一个线程中)创建的对象。打印o.constructor
通常function Object() { [native code] };
。
同时:
print({}.constructor === {}.constructor); // true
有什么想法吗?
更新
事实证明,这与多线程完全无关。有关详细信息,请参阅下面的回答。
事实证明,这与多线程完全无关。这是一个简单的Scala程序,它重现了这个问题:
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
}
我错误地使用了bindings
参数。相反,我应该采用现有bindings
并就地更新它们。我仍然不相信这应该导致o.constructor === o.constructor
是错误的,但至少它现在有效。更正版本:
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
}
相关文章:
- 如果 a 为 false,则 if(a) === if(false)
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- 如何将localStorage值设置为false
- JavaScript-切换“;全部检查”;复选框true/false
- gulp Iconify任务抛出错误TypeError:Path必须是字符串.收到false
- 如何使用javascript将字段强制设置为false
- (false==false==true)怎么可能是真的
- Array.every返回false,而不是类型error
- Javascript If else 只返回 TRUE 或只返回 FALSE
- 为什么当我在数组上测试regex时,它会返回false
- WIll window.addEventListener(“加载”,function(),false);等待浏览器自动填
- 过滤器返回true或false
- 什么是'true'和'false'和'null'
- 在if语句中,undefined等于false
- 检查文本区域是否为空总是返回false
- PHP strtotime()为JavaScript日期字符串返回false
- 为什么当async标志设置为false时,xmlhttprequest中的代码可以工作,而当它设置为true时却不能工作
- 在JavaScript中为true==1和false==0
- 使用ajax调用中的数据而不使用async:false
- 多线程 Nashorn: o.constructor === o.constructor 给出 false