Artemis
Artemis copied to clipboard
Find names/variables for anonymouns functions in PathTracer
Many of the real-world sites use a lot of anonymous functions assigned into variables. Calls such as myObj.myFunc = function(){...}; myObj.myFunc()
show up in PathTracer as <no name>
because the function is anonymous and assigned into a variable. Ideally we would like to be able to retrieve the variable which was used when the function was invoked. This tells us what the source code for the function call would look like.
I have been looking quite a bit this morning in javascript_called_function()
from qwebexecutionlistener.cpp
, trying to see if any of the frame
object's members would be useful for this, but haven't managed to find anything.
Casper: did you have an idea of how this might be done when we spoke before?
If we want to show information about the call site, we can either try to get the callee's CallFrame (and CodeBlock / SourceProvider) and show the exact source code of the call site.
Alternatively we would need to identify the name of the variable the anonymous function is bound to (preferably at the call site). I'm reading through WebKit's implementation of scopes and symbol tables right now, so hopefully I will be able to answer this particular "how" soon.
In both cases however we would need to find the call site. For this we can use the callerFrame() function on a callFrame. A quick solution for now would be to use this, and extract either a file and line representation, or pull out the exact line in the source code and show that.