In javascript, I can use foo.caller to get a reference to the function above foo in the stack trace. However, that doesn't work when a function appears multiple times in the same stack trace, foo.caller just returns foo.
Is there a stable, cross-platform method of getting a full stack trace in Javascript? I do not want to get a printable stack trace; rather, I'm doing stack inspection to see if a certain method is anywhere above me in the stack. Here's my current code:
function inFunction(foo) {
var caller = inFunction.caller;
var maxDepth = 20;
while(caller && --maxDepth > 0) {
if(caller == foo)
return true;
caller = caller.caller;
}
return false;
}
Any ideas how to deal with a function existing multiple times in the stack trace?