blob: a46b602220fb87d456a4d7f7a50746024e93e725 [file] [log] [blame]
/*
* weinre is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
* Copyright (c) 2010, 2011 IBM Corporation
*/
//-----------------------------------------------------------------------------
class StackTrace(args)
if (!args || !args.callee) {
throw Error("first parameter to " + arguments.callee.signature + " must be an Arguments object")
}
this.trace = getTrace(args)
//-----------------------------------------------------------------------------
static method dump(args)
args = args || arguments
var stackTrace = new StackTrace(args)
stackTrace.dump()
//-----------------------------------------------------------------------------
method dump
console.log("StackTrace:")
this.trace.forEach(function(frame) {
console.log(" " + frame)
})
//-----------------------------------------------------------------------------
function getTrace(args)
var result = []
var visitedFuncs = []
var func = args.callee
while (func) {
if (func.signature) result.push(func.signature)
else if (func.displayName) result.push(func.displayName)
else if (func.name) result.push(func.name)
else result.push("<anonymous>")
if (-1 != visitedFuncs.indexOf(func)) {
result.push("... recursion")
return result
}
visitedFuncs.push(func)
func = func.caller
}
return result