Jurassic supports the integrated debugging that Visual Studio affords .NET programs.


However, the following features are not supported:
  • Locals window
  • Watch window
  • Friendly names in the Call Stack window

To enable debugging, set the EnableDebugging property of the ScriptEngine to true. This will allow debugging within Visual Studio, but it also has the following negative consequences:
  • Code generated with EnableDebugging turned on can not be garbage collected. The more scripts you run, the more memory your program will use.
  • Generated code will be somewhat slower.
Therefore, do not enable this option for production code.

Tip: to stop at a breakpoint programmatically (from within JavaScript), use the debugger statement (see MSDN for more details).

Last edited Aug 5, 2010 at 10:48 AM by paulbartrum, version 5


K10 Sep 12, 2013 at 8:18 AM 
Is there any equivalent for "scope.GetValue("name of global")" for local variable ?

Waqaar Jun 30, 2013 at 12:41 PM 
@XIU Are you able to get the value in LocalWindow ? I also did the same thing but, I am not getting the value in Local Window. I dont know where I did mistake.

paulbartrum Sep 2, 2012 at 11:42 PM 
Global variables are not locals, so I don't think you can call DeclareLocal on them :-) To get the value of a global variable, call scope.GetValue("name of global") (where "scope" is the second parameter of the generated method).

XIU Aug 31, 2012 at 3:31 PM 
One extra comment, the locals will only work for variables that are inside a function, so I debug it like this:

function test() {
var x; // Shows is locals window

Looks like global variables don't call the the DeclareLocal method on ILGenerator

XIU Aug 31, 2012 at 12:40 PM 
I've got the locals window working:

in MethodGenerator.cs:
- optimizationInfo.DebugDocument = reflectionEmitInfo.ModuleBuilder.DefineDocument(this.Source.Path, COMHelpers.LanguageType, COMHelpers.LanguageVendor, COMHelpers.DocumentType);
- methodBuilder.DefineParameter(1, System.Reflection.ParameterAttributes.None, "scriptEngine");
- methodBuilder.DefineParameter(2, System.Reflection.ParameterAttributes.None, "scope");
- methodBuilder.DefineParameter(3, System.Reflection.ParameterAttributes.None, "thisValue");
- generator.MarkSequencePoint(optimizationInfo.DebugDocument, new SourceCodeSpan(1, 1, 1, 1));
+ optimizationInfo.DebugDocument = reflectionEmitInfo.ModuleBuilder.DefineDocument(this.Source.Path, Guid.Empty, Guid.Empty, Guid.Empty);//, COMHelpers.LanguageType, COMHelpers.LanguageVendor, COMHelpers.DocumentType);
+ //methodBuilder.DefineParameter(1, System.Reflection.ParameterAttributes.None, "scriptEngine");
+ //methodBuilder.DefineParameter(2, System.Reflection.ParameterAttributes.None, "scope");
+ //methodBuilder.DefineParameter(3, System.Reflection.ParameterAttributes.None, "thisValue");
+ //generator.MarkSequencePoint(optimizationInfo.DebugDocument, new SourceCodeSpan(1, 1, 1, 1));

in ReflactionEmitILGenerator.cs:
- return new ReflectionEmitILLocalVariable(this.generator.DeclareLocal(type), name);
+ var declareLocal = this.generator.DeclareLocal(type);
+ if (name != null && name != "returnValue")
+ declareLocal.SetLocalSymInfo(name);
+ return new ReflectionEmitILLocalVariable(declareLocal, name);

in OptimizationInfo.cs:
return this.MethodOptimizationHints.HasArguments == false &&
this.MethodOptimizationHints.HasEval == false &&
this.MethodOptimizationHints.HasNestedFunction == false &&
- this.EvalResult == null;
+ this.EvalResult == null &&
+ this.DebugDocument == null;

cmcbf Feb 3, 2012 at 1:31 PM 
@paulbartrum -: hummmm. To hard to implement. The MSDN documentation is very extense and dificult to understand....

paulbartrum Feb 2, 2012 at 9:51 PM 
@cmcbf - if only it was that easy! To make this work, you actually have to write an expression evaluator, which is documented here:

cmcbf Feb 2, 2012 at 2:04 PM 
May be this article help to add visual debug support

I think IL generation needs to add these atributes described in article.


Also I modified FirebugConsole to suport output to Visual Studio Debug Console,

paulbartrum Mar 21, 2011 at 9:48 AM 
Totally agreed - I looked into it a while back and boy, it's a bit of a tough nut to crack! Anyone with experience making debugger expression evaluators, contact me please ;-)

resmond Mar 21, 2011 at 6:08 AM 
How difficult would it be to add support for EITHER the Locals or Watch window?

I am certainly not trying to imply that the effort to support the general debuggin integration is in any way meaningless... by no means! But the primary value to the process lies in the combined ability to Stop, Step & Watch. So you've got the Stop and Step parts... now all you really need is some way to Watch...