Sunday, April 4, 2010

JS Profiler development - enumeration of global scope functions and variables

Here you go, again on JavaScript engine internals.
Embedded browsers do not have much developer's support and lack of javascript profiler on Ant Galio [ settop box (web) browser] pushed me to write one.

Fortunately for me JS has all power for hacking into execution code in runtime. Once my JS on page, I own everything as on page as on user's browser and device.
And shame on W3C to support a such security gap in the heart of every web page. But to be honest I glad to see that lack of intellect: It given us (web developers) good peace of bread with butter and eventually drop of caviar:) Way to go, web 2.0 industry!

It was a trick to wrap most of code in modern OOP JS, but the output is precious for browser performance analytics - for each function/constructor/prototyped and static method counter of all functions calls, list of callers w/ counter + exceptions list w/ counter. Advanced UI is still on the go, but first output already useful. Not yet competes with embedded profilers, but once the time is approved, it has a good chance to become better analytic tool. Many unique and not available for JS stuff shall be there: from the exception chains to the caller graphs blended with timing and call count.

As Google Crome is my primary browser, initial code was tuned there and passed whole scope without any hiccups.
Brief try in IE8 exposed the problem of global scope variables enumerating. It appeared that window object does not match the variables scope. And that is the right approach from JS engine side. The closure variables are not subject to be attached to any variable, not "this", nor "window". I was surprised to see the community and web browser developers expectations there. In my mind IE did the right thing. Even if it does not help me with hacking JS :)
http://blogs.msdn.com/ericlippert/archive/2005/05/04/414684.aspx

Even if it is not really needed , now I am puzzled how to get the list of local in function variables? And to be more happy the closure chain ones as well.

In Ant Galio browser the global variables are listed on window, no problems there. But JS engine appeared to be tricky. The catch and throw of same exception appeared to be unlegal JS syntax and module did not compile. Looks I need to give up the stats on exceptions. Another trouble appeared from "in" operator in conjunction with wrapped functions. Digging there...


Anyone do the JS profiling and call graph ? Will be glad to get in touch.
Sasha

No comments:

Post a Comment