Nashorn Javascript 使用 CompiledScript 进行调试?

Nashorn Javascript debugging with CompiledScript?

似乎必须使用 load(filename) Nashorn extension when wanting to be able to debug both Java and Javascript in an IDE, see e.g. Debugging Nashorn JavaScript with Intellij

不幸的是,这禁止使用CompiledScript,因为上面returns一个ScriptObjectMirror对象,至少没有compile(filename) Nashorn扩展被记录。

此处丢失的 CompiledScript 功能之一是,例如CompiledScript.eval(ScriptContext context)。我找不到使用 ScriptObjectMirror 实现相同目的的方法。此外,load(filename) 将立即执行脚本,这可能不是我们想要的。

您可以使用此调试任何 Nashorn/JavaScript 和 IDEs ->

https://blogs.oracle.com/sundararajan/entry/remote_debugging_of_nashorn_scripts

  • 在脚本中引入 "debugger" 语句
  • 使用您的 IDE 在 jdk.nashorn.internal.runtime.ScriptRuntime.DEBUGGER 方法中插入断点
  • 开始 "Debug" 在你的 IDE

另请参阅 IntelliJ:

对于最近的 NetBeans 构建,不需要第二部分。 NetBeans 将自动分成任何 "debugger" 语句。

https://twitter.com/sundararajan_a/status/773375676103602178