This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 238839 - line number issue for scripts wrapped with URLStreamHandler
Summary: line number issue for scripts wrapped with URLStreamHandler
Status: RESOLVED FIXED
Alias: None
Product: javascript
Classification: Unclassified
Component: Debugger (show other bugs)
Version: 8.0
Hardware: PC Mac OS X
: P2 normal (vote)
Assignee: Martin Entlicher
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-26 16:47 UTC by jeanfrancoisdenise
Modified: 2013-11-29 15:54 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
testcase (18.01 KB, application/zip)
2013-11-26 16:47 UTC, jeanfrancoisdenise
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jeanfrancoisdenise 2013-11-26 16:47:49 UTC
Created attachment 142609 [details]
testcase

To summarise, all avatar.js loaded scripts are, on the fly (when eval or load occurs) wrapped within a function. This is done thanks to the combination of URL/ jdk.nashorn.api.scripting.URLReader and java.net.URLStreamHandler.

For example, a user script : 

print("ss");
//Due to this comment, breakpoint on next line is not reached
print("ss2");

becomes:

(function(exports, modules) {
print("ss");
//Due to this comment, breakpoint on next line is not reached
print("ss2");
});

So when a user set a breakpoints in line 1 of his script he is actually setting a breakpoint on the function, setting a breakpoint on the last line will have no effect, once wrapped, the last line is actually a commented line, so no breakpoint set there.

I have attached a nb project that reproduces what we are doing in Avatar.js.
In the test directory, you will find testcase.js (previous example).
Comment 1 jeanfrancoisdenise 2013-11-26 17:09:39 UTC
You will also noticed that, once the breakpoint is reached, although the exports argument is a string value, the Variables Tab displays it as a "[object Undefined]"
Comment 2 Martin Entlicher 2013-11-27 16:17:53 UTC
Reproduced.

It would be tricky to fix, since we submit the Java breakpoints before we know anything about the script file.

Thus we must add a class prepare breakpoint for the script's class first, then analyze the source (compare the file content where URL points to and the content returned from the source) and shift the breakpoint line numbers accordingly. And then we can submit Java breakpoints. Not a trivial task. :-(
Comment 3 Martin Entlicher 2013-11-29 15:54:40 UTC
Fixed by changeset:   268372:30efd5c95204
http://hg.netbeans.org/core-main/rev/30efd5c95204

But breakpoints in "runtime sources" are not visible yet. They need to be submitted/removed in the original file source. This is to be solved next (see issue #238977).