provegard / ncdbg

A debugger for Nashorn that uses Chrome DevTools as frontend
BSD 3-Clause "New" or "Revised" License
31 stars 5 forks source link

Name scripts #99

Closed brainopener closed 6 years ago

brainopener commented 6 years ago

Is it possible to name the scripts that show up in the Chrome Debugger?

Currently, I see Script, Script1, Script2, etc...

name-scripts
provegard commented 6 years ago

I think you have 2-3 options.

One is to use Nashorn's load function that takes an object with script and name, see https://wiki.openjdk.java.net/display/Nashorn/Nashorn+extensions.

Another is to do scriptEngine.put(ScriptEngine.FILENAME, scriptPath) before evaluating code. I'm not sure about this one, I have had varying success with it.

A third is to embed an inline source map. A bit far-fetched perhaps... :)

brainopener commented 6 years ago

So I ended adding this to the top of my JavaScript files:

//# sourceURL=mlspriority.js

Is that what you meant by source map?

provegard commented 6 years ago

No, I was thinking:

//@ sourceMappingURL=data:application/json;charset=utf-8;base64,...

But it was just a guess. Does sourceURL work well?

brainopener commented 6 years ago

It works pretty well.

Here's what it looks like:

named-script

In that view mlspriority.js is the named script using the technique above. Script and Script1 are different scripts that do not use the technique.

In this project, we compile the scripts. If we notice that the JS file has changed on disk, we reload the script and recompile it. Here's what that looks like then:

script-on-edit

The new script is now mlspriority_ndx1.js.

provegard commented 6 years ago

I have changed the code that detects script reload due to #98, but it's not merged to master yet (because the issue reporter hasn't tested yet). Feel free to test branch issue-98 for the new reload behavior!

brainopener commented 6 years ago

Just tried it...

It does indeed suppress the creation of those _ndx# scripts in DevTools on script change.

Breakpoints survive across script changes too.

Thanks!