Break Point ignored while debugging Nashorn Javascript

Hi I have a small project and want to debug a Nashorn Javascript with Intellij 13.1 Ultimate Edition. The break point is shown in the Javascript, but the debugger does not stop at the break point while debugging.

Please find following the java class and the javascript. I am running Intellij 13.1 on Redhat Linux 6 64-Bit with the SDK 1.8.0 64-Bit.

package com.company;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.io.InputStream;
import java.io.InputStreamReader;

public class ExecuteJavascript {

    public static void main(String[] args) throws Exception {
        ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
        ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("nashorn");

        if (null == scriptEngine) {
            throw new Exception("No Nashorn!");
        }

        InputStream scriptFile = ExecuteJavascript.class.getResourceAsStream("UUIDGenerator.js");

        if (null == scriptFile) {
            throw new Exception("JavaScript file HelloWorls.js not found");
        }

        scriptEngine.eval(new InputStreamReader(scriptFile));
    }
}

var requestUuid = null;

if (!requestUuid) {
    var uuid = generateUUID();
    print(uuid);
}

function generateUUID() {
    var d = new Date().getTime();
    var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = (d + Math.random()*16)%16 | 0;
        d = Math.floor(d/16);
        return (c=='x' ? r : (r&0x7|0x8)).toString(16);
    });
    return uuid;
};

5 comments

Hi, when you load js script as a stream, there is no way in the debugger to map it back to the script file.
Please use approach like this:
scriptEngine.eval("load(\"UUIDGenerator.js\");");
and it will work.

0

Bingo!

Thanks for your support!

Cyrill

0

Is this the only form of the load that one can use to debug Nashorn JS in Intellij? That is

 
engine.eval("load('js/test.js');");

?? I have tried it (and would be interested to use it) via other methods such as

 
engine.eval("load('file:///C:/dir1/dir2/dir3/js/test.js');");


which evals properly, but does NOT enable debugging. Also,

engine.eval("load('../dir2/dir3/js/test.js');");

also evals properly but also does NOT enable debugging.

The problem is that the JS files may be remote to the project (which is why Nashorn supports pulling them in from elsewhere on the file system). If they are remote to the Intellij Project, one (apparently) cannot debug them via Intellij IDEA.

Why this restriction? Anyone know of any workarounds to enable other forms

thank you

0

3 issues were closed recently – https://youtrack.jetbrains.com/issue/IDEA-126149, https://youtrack.jetbrains.com/issue/IDEA-133825, https://youtrack.jetbrains.com/issue/IDEA-126148 Will be available in next IDEA 14.1 EAP. If you want, I can send you pre-EAP built to test.

>> If they are remote to the Intellij Project, one (apparently) cannot debug them via Intellij IDEA.
Feel free to file issue about it and it will be fixed soon.

0

Yes please send. Thank you for the prompt response!!! (I'm at misterblinky@yahoo.com)

0

Please sign in to leave a comment.