Debugging JS code

Feb 14, 2013 at 9:16 AM
Hello,

i was following on ReadMe instructions for setup debug environment.
I have installed eclipse, and tools. Basically I was able to attach to V8 engine, but
problem is that all breakpoints i have set were ignored.

And I'm not clear what should be done to have debug working within eclipse.
And how to sync source code.

Could you give any suggestions what i am doing wrong?
Coordinator
Feb 19, 2013 at 1:12 AM
Hi pro100sanya,

If you can successfully attach via Eclipse, your code is probably doing all it needs to do. Did you set up the breakpoints in Eclipse? It is difficult to diagnose your issue without more information. Also, we're not sure what you mean by "syncing" the source code.

Please tell us more if possible!
Feb 19, 2013 at 9:14 AM
"syncing" is a typos )) i meant syncing - synchronization.

I have defined breakpoints. But eclipse didn't stop there.

May be it is possible to prepare video or illustrated documentation with detailed example how to debug?
Coordinator
Feb 27, 2013 at 2:03 AM
Thanks pro100sanya! You're right that ClearScript needs better documentation for Eclipse-V8 debugging. Stay tuned!
Feb 28, 2013 at 10:39 PM
Just wondering: Is it not possible to trap and report errors from the V8 engine via the ClearScript "wrapper" around V8? Is a port connection really necessary? (I don't know, just asking. ;) ) It would be nice to be able to intercept JavaScript errors and report them in a custom way.
Coordinator
Feb 28, 2013 at 11:17 PM
Yes, absolutely, ClearScript propagates script errors to the host.

Script errors are usually translated into InvalidOperationException or something similar, with the script engine's error message in the exception object. And if script code calls a host method that throws an exception, that exception, unless caught, should be thrown out of the script engine back to the host, fully intact.

However, if you're developing nontrivial script code, ClearScript lets you attach a script debugger as well.
Nov 5, 2013 at 2:09 PM
Hi guys,

I may be the worst from a knowledge of eclipse usage point of view but bear with me and please help...

I've created a C# console app that uses the V8 engine started up with_jsEngine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging);. The console app then loads up some js files:_jsEngine.Execute(filePath, File.ReadAllText(filePath));.

Now, i'd like to be able to call a specific function and debug everything from within an eclipse project.
I've installed eclipse (with Google Chrome Developer Tools). I've created an eclipse JavaScript project containing all the js files added by the C# console app.

I can start the debugger, and it attaches to the TCP server just fine, displaying the complete list of loaded documents (from the C# code) but they don't seem to be synchronized with the files in eclipse

So here's a couple of misunderstandings/questions:
  • How do i add files from Eclipse tot he debugger ?
  • How can i execute a specific method in a file ? (guessing i can always add a new script that calls out on that specific method but going back go q 1).
P.S. while in visual studio, and using the JScriptEngine, i can debug things fine (well almost fine, as the breakpoints that are set on files before loading don't hit, but inserting a 'debugger' statement allows re adding them)
Coordinator
Nov 5, 2013 at 4:58 PM
Hello AndiVlad!

I can start the debugger, and it attaches to the TCP server just fine, displaying the complete list of loaded documents (from the C# code) but they don't seem to be synchronized with the files in eclipse

As far as we know, the Google Chrome Developer Tools do not correlate loaded scripts with Eclipse project files. The intended workflow is to use the Project Explorer window to open loaded scripts and set breakpoints as necessary.

How can i execute a specific method in a file ?

When you're stopped at a breakpoint in Eclipse, you can use the Expressions window to evaluate arbitrary expressions, including invoking existing functions and defining new ones.

How do i add files from Eclipse to the debugger ?

Our recommendation would be to expose a host (C#) object or function for this purpose. You could then invoke it from Eclipse via the Expressions window.

Cheers!