/**
* https://github.com/csnover/TraceKit
* @license MIT
* @namespace TraceKit
*/
(function(window, undefined) {
if (!window) {
return;
}
var TraceKit = {};
var _oldTraceKit = window.TraceKit;
// global reference to slice
var _slice = [].slice;
var UNKNOWN_FUNCTION = '?';
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Error_types
var ERROR_TYPES_RE = /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/;
/**
* A better form of hasOwnProperty<br/>
* Example: `_has(MainHostObject, property) === true/false`
*
* @param {Object} object to check property
* @param {string} key to check
* @return {Boolean} true if the object has the key and it is not inherited
*/
function _has(object, key) {
return Object.prototype.hasOwnProperty.call(object, key);
}
/**
* Returns true if the parameter is undefined<br/>
* Example: `_isUndefined(val) === true/false`
*
* @param {*} what Value to check
* @return {Boolean} true if undefined and false otherwise
*/
function _isUndefined(what) {
return typeof what === 'undefined';
}
/**
* Export TraceKit out to another variable<br/>
* Example: `var TK = TraceKit.noConflict()`
* @return {Object} The TraceKit object
* @memberof TraceKit
*/
TraceKit.noConflict = function noConflict() {
window.TraceKit = _oldTraceKit;
return TraceKit;
};
/**
* Wrap any function in a TraceKit reporter<br/>
* Example: `func = TraceKit.wrap(func);`
*
* @param {Function} func Function to be wrapped
* @return {Function} The wrapped func
* @memberof TraceKit
*/
TraceKit.wrap = function traceKitWrapper(func) {
function wrapped() {
try {
return func.apply(this, arguments);
} catch (e) {
TraceKit.report(e);
throw e;
}
}
return wrapped;
};
/**
* Cross-browser processing of unhandled exceptions
*
* Syntax:
* ```js
* TraceKit.report.subscribe(function(stackInfo) { ... })
* TraceKit.report.unsubscribe(function(stackInfo) { ... })
* TraceKit.report(exception)
* try { ...code... } catch(ex) { TraceKit.report(ex); }
* ```
*
* Supports:
* - Firefox: full stack trace with line numbers, plus column number
* on top frame; column number is not guaranteed
* - Opera: full stack trace with line and column numbers
* - Chrome: full stack trace with line and column numbers
* - Safari: line and column number for the top frame only; some frames
* may be missing, and column number is not guaranteed
* - IE: line and column number for the top frame only; some frames
* may be missing, and column number is not guaranteed
*
* In theory, TraceKit should work on all of the following versions:
* - IE5.5+ (only 8.0 tested)
* - Firefox 0.9+ (only 3.5+ tested)
* - Opera 7+ (only 10.50 tested; versions 9 and earlier may require
* Exceptions Have Stacktrace to be enabled in opera:config)
* - Safari 3+ (only 4+ tested)
* - Chrome 1+ (only 5+ tested)
* - Konqueror 3.5+ (untested)
*
* Requires TraceKit.computeStackTrace.
*
* Tries to catch all unhandled exceptions and report them to the
* subscribed handlers. Please note that TraceKit.report will rethrow the
* exception. This is REQUIRED in order to get a useful stack trace in IE.
* If the exception does not reach the top of the browser, you will only
* get a stack trace from the point where TraceKit.report was called.
*
* Handlers receive a TraceKit.StackTrace object as described in the
* TraceKit.computeStackTrace docs.
*
* @memberof TraceKit
* @namespace
*/
TraceKit.report = (function reportModuleWrapper() {
var handlers = [],
lastException = null,
lastExceptionStack = null;
/**
* Add a crash handler.
* @param {Function} handler
* @memberof TraceKit.report
*/
function subscribe(handler) {
installGlobalHandler();
handlers.push(handler);
}
/**
* Remove a crash handler.
* @param {Function} handler
* @memberof TraceKit.report
*/
function unsubscribe(handler) {
for (var i = handlers.length - 1; i >= 0; --i) {
if (handlers[i] === handler) {
handlers.splice(i, 1);
}
}
if (handlers.length === 0) {
window.onerror = _oldOnerrorHandler;
_onErrorHandlerInstalled = false;
}
}
/**
* Dispatch stack information to all handlers.
* @param {TraceKit.StackTrace} stack
* @param {boolean} isWindowError Is this a top-level window error?
* @param {Error=} error The error that's being handled (if available, null otherwise)
* @memberof TraceKit.report
* @throws An exception if an error occurs while calling an handler.
*/
function notifyHandlers(stack, isWindowError, error) {
var exception = null;
if (isWindowError && !TraceKit.collectWindowErrors) {
return;
}
for (var i in handlers) {
if (_has(handlers, i)) {
try {
handlers[i](stack, isWindowError, error);
} catch (inner) {
exception = inner;
}
}
}
if (exception) {
throw exception;
}
}
var _oldOnerrorHandler, _onErrorHandlerInstalled;
/**
* Ensures
|