views:

131

answers:

1

After learning about how to print out debug messages using Visual Studio's Tracepoint feature, I was curious to see if it worked in JavaScript files. So far, it does and it doesn't.

If I am editing a .js file in VS 2008, I can click on the margin to create a breakpoint. I can then right-click the breakpoint and select "When Hit" and the dialog comes up to define the action.

I select "Print a Message" and "Continue execution". That way, the breakpoint becomes a tracepoint and prints the message to the output window when the ASP.Net program is running in debug.

This, in itself, is very cool. But, in C# code, I can put variables into the printed message by enclosing them in {}. So I can say "In Function $FUNCTION, x = {x}". When I try to do this with JavaScript tracepoints, no matter what I put in the brackets, it just says "variable is not defined".

Is there any way to print meaningful information other than "You are here" type messages in JavaScript tracepoints?

My intent was to put in timing code that would print to the output console in debug but not have to be commented out for releases.

It does at least kinda support JavaScript because if I use it's builtin variables, like $FUNCTION for the function name it works. Actually I just got it to print "JScript anonymous function" for $FUNCTION, but it was in an anonymous function. If there was a $TIMESTAMP I would be in good shape.

A: 

There isn't a $TIMESTAMP, but there is a $TICK. It prints the millisecond count 'tick' in hexadecimal, so it looks like this:

Document Ready Start - 0x890A27
Document Ready End - 0x890E7C

So a little calculator work can figure out the difference between the two.

Still don't know how to evaluate JavaScript variables though...

UPDATE:

It isn't quite as nice as using tracepoints (since you don't actually add things to the code for them), but Sys.Debug.trace() does what I want as far as timing code sections.

CMPalmer