Status: New
Owner: ----
New issue 2169 by [email protected]: can't get function arguments in
stack trace from user scripts
http://code.google.com/p/v8/issues/detail?id=2169
Error.prepareStackTrace() allows user scripts to programmatically put
together a stack trace.
http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
However it's not possible to get the arguments passed to each function in
the stack, and this would be extremely useful. Although
CallSite.getFunction() allows access to function.arguments, there are two
problems:
1. this would only work for non-recursive functions, since if the function
appears more than once in the stack, it's "arguments" property will only
have the most recent arguments. This implies an API to get arguments is
needed directly on CallSite.
2. Sample code below demonstrates that even if you use
CallSite.getFunction(), function.arguments will not be present if you
examine the CallSite objects in a catch block
In the sample code below, the trace alert()d with prefix "trace from before
crash" can get arguments for all functions in the stack, the trace alert()d
with prefix "trace from catch()" can only get them for functions that are
still on the stack at the time the catch() block executes. A third trace is
captured inside prepareStackTrace() just in case - this also cannot get
arguments.
Error.prepareStackTrace = function(error, stack) {
window.traceInsidePrepare = getTrace({ stack : stack });
return stack;
};
var someObj = {
someMethod : function () {
alert("trace from before crash: " + getTrace(new Error()));
crash();
}
}
function bar(barArg) { someObj.someMethod(); };
function foo(fooArg) { bar("barArgString"); };
function getTrace(e) {
var stack = e.stack;
var trace = "";
for (var i = 0; i < stack.length; i++) {
var frame = stack[i],
func = frame.getFunction();
trace += "\r" + frame.getThis() + "." + frame.getFunctionName() +
"\r function first arg: " + (func.arguments != null ?
func.arguments[0] : "<missing>");
}
return trace;
}
try {
foo("fooArgString");
} catch (e) {
alert("trace from catch(): " + getTrace(e));
alert("trace inside prepare: " + window.traceInsidePrepare);
}
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev