As usual, I have a much higher-level question than usually appears on this 
list! Please direct me elsewhere if there's a more appropriate forum....

As far as I can tell, in order to use Netbeans JS debugger with JS code that 
uses Nashorn I have to use "load" in the eval of my JS. Load apparently does 
something to preserve the distinct lines in the JS, which enables the setting 
of breakpoints, etc. Simply using engine.eval(string-of-code) or 
engine.eval(Reader) means you can't use the debugger.

However, I am writing a platform on which I enable developers to write their JS 
code and, like for node.js, etc., I wrap their code invisibly to make it into a 
module. That is, I add something along the lines of

(function() { var exports = {};                      <<<< this
<user's code>
})();                                                                        
<<<< and this

to "modularize" the user's code. So if I want to both "wrap" my user's code and 
enable them to use the Netbeans debugger, I'm stuck because I either a) read 
the JS from its file as a string, wrap it, and then load it; or b) load it as a 
file (in which case I don't get the chance to "wrap" it). Here are the two 
cases:
a)
                String code = getMyJavascriptAsAString("c/somedir/some.js");
                code = wrapMyJsCode(code);
engine.eval("load({ script: '" + code + "', name: \"some.js\"})");

ERROR: Problem loading: somedir/some.js': javax.script.ScriptException: 
<eval>:1:55 Missing close quote
load({ script: 'var x = {};
                           ^ in <eval> at line number 1 at column number 13

FAILS because the JS code consists of multiple lines and java doesn't support 
multi-line strings.

b)
Loading from a file directly

                engine.eval("load('c:/somedir/some.js');");

which works in a debugger, but doesn't enable me to "wrap" user's code.

Aside from writing out temporary files, does somebody have a better suggestion? 
Is it possible to intercept the handling of "load(<filePath>)" so that I can 
inject stuff into the user's code to "modularize" it?

I hope I'm clear.

thanks

This email and any attachments are intended solely for the use of the 
individual or entity to whom it is addressed and may be confidential and/or 
privileged.

If you are not one of the named recipients or have received this email in error,

(i) you should not read, disclose, or copy it,

(ii) please notify sender of your receipt by reply email and delete this email 
and all attachments,

(iii) Dassault Systemes does not accept or assume any liability or 
responsibility for any use of or reliance on this email.

For other languages, go to http://www.3ds.com/terms/email-disclaimer

Reply via email to