|
JavaScriptStackTraceApi
This page has moved to https://code.google.com/p/v8-wiki/wiki/JavaScriptStackTraceApi |
► Sign in to add a comment
|
Search
|
|
JavaScriptStackTraceApi
This page has moved to https://code.google.com/p/v8-wiki/wiki/JavaScriptStackTraceApi |
Is there any way to get exact source line for each stack frame? This would greatly simplify implementation of real C-like ASSERT function.
you can implement line etc with this, and C-style assert()s: https://github.com/joyent/node/commit/007b7181e307a8d52970947d2b6432a2addd9ef0
I'm trying to use an override of prepareStackTrace() to provide more information than Chrome does by default, specifically, the value of the arguments passed to functions in the stack. This works for manually creating an error in order to get the current stack, but not when catching a thrown error and trying to look at the stack where it came from.
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.
Is there any way to get these arguments from a catch() block?
If not, could V8 be enhanced to simply call prepareStackTrace() sooner, that is, before the stack frames have been destroyed?
Note I'm aware that if there are recursive calls the best I can get are the arguments to the deepest frame for a given function. The ideal enhancement is really that CallSite? objects support a getArguments() call (and I'd love a getLocalVariables() call as well).
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); }I've submitted this as V8 issue 2169 : http://code.google.com/p/v8/issues/detail?id=2169
it's really annoying that you can't get the callsite objects after the error is created... this would be fantastic for logging, IMO this should be part of the ecmascript spec, string stacks are pretty weak
IMO this should be part of the ecmascript spec,string stacks are pretty week
here's a link to how the default StackTrace? formatter looks. I think someone could find it useful: https://github.com/v8/v8/blob/master/src/messages.js#L1050
PLEASE CORRECT JAVA
Great info keep it coming
Error.prepareStackTrace = function(error, stack) {
};var someObj = {
} function bar(barArg) { someObj.someMethod(); }; function foo(fooArg) { bar("barArgString"); };function getTrace(e) {
}try {
} catch (e) { }I've noticed that getFunction for node 0.11 and above or even the func property on the callsites. Anyone knows something about this?
Allow me to upload my script here. But still in the process of making
http://www.kangtips.com/2015/04/minuman-berenergi-aman-tidak-berbahaya.html
I do accept as true with all the ideas you've introduced in your post. They are very convincing and can definitely work. ignou.ac.in Nonetheless, the posts are very quick for newbies.
Thanks for your information
http://evomovie.com
Nice and thanks http://www.code-sample.com/