In Node.js, I'm trying to get the line number of each function that is called in a script. Is there any way to generate a summary of each function that is called in a script? I'd like to get a list of line numbers that are called by each function in the script, so that I can comment out one of the function calls (which I'm still trying to find.)
An example:
function printStuff(){
console.log("This is an example.");
}
printStuff();
printStuff();
Now I'd like to get a summary of all the events in this script (without modifying the script). It might look something like this:
calling printStuff at line 4
calling console.log at line 2
calling printStuff at line 5
calling console.log at line 2
Are there any testing/debugging tools that make it possible to do this?
Not EXACTLY what you are looking for, I guess, but you should be able to modify it to your needs:
Object.defineProperty(global, '__stack', {
get: function(){
var orig = Error.prepareStackTrace;
Error.prepareStackTrace = function(_, stack){ return stack; };
var err = new Error;
Error.captureStackTrace(err, arguments.callee);
var stack = err.stack;
Error.prepareStackTrace = orig;
return stack;
}
});
Object.defineProperty(global, '__line', {
get: function(){
return __stack[1].getLineNumber();
}
});
console.log("I am running from line " + __line);
It was discussed here