I'm trying to write a tool to extract dependencies between JavaScript functions. There's JSAnalyse, but it uses static analysis and it is incomplete. I've try metaprogramming, overwriting all functions to log the execution trace. Something like that:
originalFunction = function () {
//generate stack trace
return originalFunction.apply(this, arguments);
};
But it has some problems and doesn't look like a good solution. I've try Jalangi, but it doesn't help.
I think the best solution is changing a JavaScript engine (like Rhino or V8) or debugger to intercept the functions calls and log a trace with name and location (file and line) of the caller function. How can I log this dynamic information? How can I log an execution trace of JavaScript programs not changing the source code of the program?