Kevin Dente's Blog

The Blip in the Noise
Is the Visual Studio 2008 Javascript debugger crippled?

Sadly, it appears the answer is "yes". Specifically, the debugger has a huge limitation - one that's been there since Visual Studio 2005 (maybe even 2003). You can't set a breakpoint on the first line of an anonymous function. Consider, for example, the following:

   1:  <script type="text/javascript">
   2:  function aFunc()
   3:  {
   4:    alert("hi");
   5:  }
   6:   
   7:  var aFunc2 = function()
   8:  {
   9:      alert("hi, yourself");
  10:      alert("what's your problem?");
  11:  }
  12:   
  13:  aFunc();
  14:  aFunc2();
  15:  </script>
 

Here aFunc is a named function, and aFunc2 is a variable that points to an anonymous function. With the Visual Studio debugger, you can set a breakpoint on line 4, and line 10, but not line 9.

Why is this such a problem? Because most all the major Javascript libraries (at least Prototype, YUI, JQuery, and even, to a lesser extent, Microsoft's own ASP.NET AJAX) use anonymous functions up the ying yang - mostly for object methods. In other words, you can't set a breakpoint on the first line of most functions in most AJAX libraries. And if the function has only one line, yeah, you're screwed - no break-ey break-ey for you.

When I learned that this bug wasn't fixed in Visual Studio 2008 I was, in a word, dumbfounded. Isn't improved Javascript development one of the primary new features of VS2008?

Now, when I characterized the problem as being related to anonymous functions, that isn't quite right. In the above code, even if you give the aFunc2 function a name - "var aFunct2 = function theFunc()..."- the problem remains. There's a brief discussion of this issue on the ASP.NET forums here (note the date - March 2007), but the explanation rather nebulous. Whatever the root cause, it's a horrible limitation that I'm stunned wasn't addressed for RTM.

Guess it's back to Firebug for me. Or maybe it's time for another look at Aptana.

Published Tuesday, November 27, 2007 9:55 PM by kevindente

Filed under:

Comments

# re: Is the Visual Studio 2008 Javascript debugger crippled?@ Wednesday, November 28, 2007 1:45 AM

Hi, why not just use a dummy placeholder call in the first line? Something like "var dummy=0;" and your gone? It does not seems to be very smart but hey, your problem should be fixed, or not? Or are there any other limitations we have to consider first?

Matthias Denkmaier

# re: Is the Visual Studio 2008 Javascript debugger crippled?@ Wednesday, November 28, 2007 4:50 AM

Have you directly reported this in Microsofts Bugtracker?

Steve

# re: Is the Visual Studio 2008 Javascript debugger crippled?@ Wednesday, November 28, 2007 8:12 AM

A huge limitation would be something more along the lines of "I can't set any breakpoints in anonymous functions." There are plenty of workarounds to achieve what you're looking for. It's nothing more than a minor annoyance actually.

jayson knight

# re: Is the Visual Studio 2008 Javascript debugger crippled?@ Wednesday, November 28, 2007 2:32 PM

Can't you just insert the "debugger" keyword where you want to break? That adds a line, doesn't it?

Jeff Atwood

# re: Is the Visual Studio 2008 Javascript debugger crippled?@ Wednesday, November 28, 2007 2:56 PM

Yes, in some cases I could add a line of code to the function. Is that a reasonable thing to be required to do? It's one thing if it's my code - should I have to go changing the YUI or JQuery code all over the place? Isn't setting breakpoints one of the primary functions of a debugger?

And what if the script code is being served from an embedded assembly resource, where I can't change the source?

Here's another way of thinking about it - would you think this a reasonable limitation if the C# or VB debugger required you to change the code in order to set a breakpoint?

kevindente

# re: Is the Visual Studio 2008 Javascript debugger crippled?@ Tuesday, July 01, 2008 11:32 PM

Just ran into this -

To the people minimizing it you are obviously not seriously into javascript.

The language is not a first class citizen with this limitation.

VS 2008 should be able to match Firebug!

ecards

# re: Is the Visual Studio 2008 Javascript debugger crippled?@ Sunday, October 05, 2008 10:49 PM

MS has never seemed to embrace JS as a real language.  Hell, noone seems to.  Why do we have all these extraneous HTML editors and WYSIWYG designers, but no real choices for JavaScript...

I only wish Aptana was more performant.  Last time I tried it (about a year ago) I had to wait minutes for it to start.  That's just not acceptable.  In addition it was incredibly slow to do text editing in...

I guess that's the bane of Java on Windows...

Lucas Goodwin

# re: Is the Visual Studio 2008 Javascript debugger crippled?@ Tuesday, April 07, 2009 7:04 PM

First of all I'm glad someone else has run into this problem and I'm not losing my mind. Thanks for writing this up. I now have a support group. ;)

and, um, this is WAY more than just an annoyance.

Almost ALL of my javascript is written in this fashion so I don't add objects & functions to the global namespace (as "aFunc" does in the above example)!!!

The fact that VS2008 gets tripped up on this inexcusable. Overall I really like it as a debugger, but if I can't set a breakpoint properly within a *valid function* (even if it is anonymous) without having to do some goofy workaround like adding a meaningless line of code or use the debugger statement just infuriates me.

evankstone

Leave a Comment

(required) 
(required) 
(optional)
(required)