From d92df54f69378d935b0cbfac8d8aafbc8379b0a2 Mon Sep 17 00:00:00 2001 From: Thomas BrĂ¼derli Date: Wed, 27 Aug 2008 08:33:01 +0000 Subject: Read backtrace in it_catcherr() --- itjs/boot.js | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/itjs/boot.js b/itjs/boot.js index d25a800..9ae92d4 100644 --- a/itjs/boot.js +++ b/itjs/boot.js @@ -7,19 +7,47 @@ var it_starttime = new Date().getTime(); function it_catcherr(msg, url, line) { var stacktrace = ""; + var callstack_done = false; - for (var c = it_catcherr.caller; c != null; c = c.caller) + try { i.dont.exist += 0; } // does not exist - that's the point + catch (e) { - var funcname = c.toString().match(/function (\w*)/)[1]; - stacktrace += (funcname ? funcname : "anon") + "/"; - - if (c.caller == c) // Break simple recursion + if (e.stack) // Firefox { - stacktrace += "*"; - break; + stacktrace = e.stack.replace(/^.*?\n/,'').replace(/(?:\n@:0)?\s+$/m,'').replace(/^\(/gm,'{anonymous}(') + ';'; + callstack_done = true; + } + else if (window.opera && e.message) // Opera + { + var entry, lines = e.message.split("\n"); + for (var i=1, len=lines.length; i < len; i++) + { + if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) + { + entry = lines[i]; + // append next line also since it has the file info + if (lines[i+1]) { + entry += " at " + lines[i+1]; + i++; + } + stacktrace += entry + '/'; + } + } + callstack_done = true; } } + if (!callstack_done) // IE and Safari + { + var fname, current_func = arguments.callee.caller; + while (current_func) + { + fname = /function\s*([\w\-$]+)?\s*\(/.test(current_func.toString()) ? RegExp.$1 || 'anonymous' : 'anonymous'; + stacktrace += fname + '/'; + current_func = current_func.caller; + } + } + if (typeof it_boot.sequence != 'undefined') { // trigger it_boot retry if error occured while evaluating loaded script @@ -29,13 +57,11 @@ function it_catcherr(msg, url, line) return true; } - stacktrace += "it_boot=" + it_boot.sequence + ";"; + stacktrace += "it_boot=" + it_boot.sequence + ";it_boot_file=" + it_boot.file; } if (typeof window.it_loader != 'undefined' && it_loader.sequence) stacktrace += "it_loader=" + it_loader.sequence + ";"; - stacktrace += "it_boot_status=" + it_boot_status + ";it_boot_file=" + it_boot.file; - it_boot_report(msg, url, line, stacktrace); return !window.env || !!window.env.is_live_server; // No env or live server -> suppress error -- cgit v1.2.3