From 3002b6da18dce27c749fce42a3ffe236cc08c51c Mon Sep 17 00:00:00 2001 From: Frank Ebersoll Date: Wed, 11 Nov 2015 22:25:20 +0100 Subject: [PATCH 1/3] Implemented DuplicateChecker --- .../default/DuplicateCheckerPlugin-spec.ts | 83 ++++++++++++++++++ src/plugins/default/DuplicateCheckerPlugin.ts | 87 +++++++++++++++++++ src/plugins/default/EnvironmentInfoPlugin.ts | 2 +- src/plugins/default/ErrorPlugin-spec.ts | 23 ++--- src/plugins/default/EventPluginTestFixture.ts | 42 +++++++++ src/plugins/default/ModuleInfoPlugin.ts | 2 +- src/plugins/default/RequestInfoPlugin.ts | 2 +- 7 files changed, 221 insertions(+), 20 deletions(-) create mode 100644 src/plugins/default/DuplicateCheckerPlugin-spec.ts create mode 100644 src/plugins/default/DuplicateCheckerPlugin.ts create mode 100644 src/plugins/default/EventPluginTestFixture.ts diff --git a/src/plugins/default/DuplicateCheckerPlugin-spec.ts b/src/plugins/default/DuplicateCheckerPlugin-spec.ts new file mode 100644 index 00000000..d1bd87d6 --- /dev/null +++ b/src/plugins/default/DuplicateCheckerPlugin-spec.ts @@ -0,0 +1,83 @@ +import { ContextData } from '../ContextData'; +import { EventPluginContext } from '../EventPluginContext'; +import { DuplicateCheckerPlugin } from './DuplicateCheckerPlugin'; +import { ErrorPlugin } from './ErrorPlugin'; +import { createFixture } from './EventPluginTestFixture'; + +describe('DuplicateCheckerPlugin', () => { + + let target: DuplicateCheckerPlugin; + let now: number; + + beforeEach(() => { + target = new DuplicateCheckerPlugin(); + (target).getNow = () => now; + now = 0; + }); + + function run(exception: Error) { + let context: EventPluginContext; + let contextData: ContextData; + ({ + context, + contextData + } = createFixture()); + + contextData.setException(exception); + + let errorPlugin = new ErrorPlugin(); + errorPlugin.run(context); + target.run(context); + + return context; + } + + it('should ignore duplicate within window', () => { + let exception = createException([{ + name: "methodA" + }]); + run(exception); + let contextOfSecondRun = run(exception); + expect(contextOfSecondRun.cancelled).toBeTruthy(); + }); + + it('shouldn\'t ignore error without stack', () => { + let exception = createException(); + run(exception); + let contextOfSecondRun = run(exception); + expect(contextOfSecondRun.cancelled).toBeFalsy(); + }); + + it('shouldn\'t ignore different stack within window', () => { + let exception1 = createException([{ + name: "methodA" + }]); + run(exception1); + let exception2 = createException([{ + name: "methodB" + }]); + let contextOfSecondRun = run(exception2); + expect(contextOfSecondRun.cancelled).toBeFalsy(); + }); + + it('shouldn\'t ignore duplicate after window', () => { + let exception = createException([{ + name: "methodA" + }]); + run(exception); + + now = 3000; + let contextOfSecondRun = run(exception); + expect(contextOfSecondRun.cancelled).toBeFalsy(); + }); +}); + +function createException(stack?) { + try { + throw new Error(); + } + catch (e) { + e.testStack = stack; + return e; + } +} \ No newline at end of file diff --git a/src/plugins/default/DuplicateCheckerPlugin.ts b/src/plugins/default/DuplicateCheckerPlugin.ts new file mode 100644 index 00000000..7c439714 --- /dev/null +++ b/src/plugins/default/DuplicateCheckerPlugin.ts @@ -0,0 +1,87 @@ +import { IInnerError } from '../../models/IInnerError'; +import { IStackFrame } from '../../models/IStackFrame'; + +import { ILog } from '../../logging/ILog'; + +import { IEventPlugin } from '../IEventPlugin'; +import { EventPluginContext } from '../EventPluginContext'; + +const ERROR_KEY: string = '@error'; +const WINDOW_MILLISECONDS = 2000; +const MAX_QUEUE_LENGTH = 10; + +export class DuplicateCheckerPlugin implements IEventPlugin { + public priority: number = 40; + public name: string = 'DuplicateCheckerPlugin'; + + private recentlyProcessedErrors: TimestampedHash[] = []; + + public run(context: EventPluginContext, next?: () => void): void { + if (context.event.type === 'error') { + let error = context.event.data[ERROR_KEY]; + let isDuplicate = this.checkDuplicate(error, context.log); + if (isDuplicate) { + context.cancelled = true; + return; + } + } + + next && next(); + } + + private getNow() { + return Date.now(); + } + + private checkDuplicate(error: IInnerError, log: ILog): boolean { + let now = this.getNow(); + let repeatWindow = now - WINDOW_MILLISECONDS; + let hashCode: number; + while (error) { + hashCode = getHashCodeForError(error); + + // make sure that we don't process the same error multiple times within the repeat window + if (hashCode && this.recentlyProcessedErrors.some(h => + h.hash == hashCode && h.timestamp >= repeatWindow)) { + log.info(`Ignoring duplicate error event: hash=${hashCode}`); + return true; + } + + // add this exception to our list of recent errors that we have processed + this.recentlyProcessedErrors.push({ hash: hashCode, timestamp: now }); + + // only keep the last 10 recent errors + while (this.recentlyProcessedErrors.length > MAX_QUEUE_LENGTH) { + this.recentlyProcessedErrors.shift(); + } + + error = error.inner; + } + + return false; + } +} + +interface TimestampedHash { + hash: number; + timestamp: number +} + +function getHashCodeForError(error: IInnerError): number { + if (!error.stack_trace) { + return null; + } + + let stack = JSON.stringify(error.stack_trace); + return getHashCode(stack); +} + +function getHashCode(s: string): number { + let hash = 0, length = s.length, char; + for (let i = 0; i < length; i++) { + char = s.charCodeAt(i); + hash = ((hash << 5) - hash) + char; + hash |= 0; + } + return hash; +} diff --git a/src/plugins/default/EnvironmentInfoPlugin.ts b/src/plugins/default/EnvironmentInfoPlugin.ts index 29e06a6a..a6449338 100644 --- a/src/plugins/default/EnvironmentInfoPlugin.ts +++ b/src/plugins/default/EnvironmentInfoPlugin.ts @@ -3,7 +3,7 @@ import { EventPluginContext } from '../EventPluginContext'; import { IEnvironmentInfo } from '../../models/IEnvironmentInfo'; export class EnvironmentInfoPlugin implements IEventPlugin { - public priority:number = 70; + public priority:number = 80; public name:string = 'EnvironmentInfoPlugin'; public run(context:EventPluginContext, next?:() => void): void { diff --git a/src/plugins/default/ErrorPlugin-spec.ts b/src/plugins/default/ErrorPlugin-spec.ts index 8f86f762..469bd674 100644 --- a/src/plugins/default/ErrorPlugin-spec.ts +++ b/src/plugins/default/ErrorPlugin-spec.ts @@ -6,7 +6,7 @@ import { IErrorParser } from '../../services/IErrorParser'; import { ErrorPlugin } from './ErrorPlugin'; import { CapturedExceptions } from './ErrorPlugin-spec-exceptions'; - +import { createFixture } from './EventPluginTestFixture'; function BaseTestError() { this.name = 'NotImplementedError'; @@ -31,22 +31,11 @@ describe('ErrorPlugin', () => { let event: IEvent; beforeEach(() => { - errorParser = { - parse: (c: EventPluginContext, exception: Error) => ({ - type: exception.name, - message: exception.message - }) - }; - client = { - config: { - errorParser - } - }; - event = { - data: {} - }; - contextData = new ContextData(); - context = new EventPluginContext(client, event, contextData); + ({ + contextData, + context, + client, + event} = createFixture()); }); function processError(error) { diff --git a/src/plugins/default/EventPluginTestFixture.ts b/src/plugins/default/EventPluginTestFixture.ts new file mode 100644 index 00000000..2dea28b1 --- /dev/null +++ b/src/plugins/default/EventPluginTestFixture.ts @@ -0,0 +1,42 @@ +import { ContextData } from '../ContextData'; +import { EventPluginContext } from '../EventPluginContext'; +import { IEvent } from '../../models/IEvent'; +import { IError } from '../../models/IError'; +import { IErrorParser } from '../../services/IErrorParser'; +import { IStackFrame } from '../../models/IStackFrame'; + +export function createFixture() { + let contextData: ContextData; + let context: EventPluginContext; + let errorParser: IErrorParser; + let client: any; + let event: IEvent; + + errorParser = { + parse: (c: EventPluginContext, exception: Error) => ({ + type: exception.name, + message: exception.message, + stack_trace: (exception).testStack || null + }) + }; + client = { + config: { + errorParser, + log: { + info: () => { } + } + } + }; + event = { + data: {} + }; + contextData = new ContextData(); + context = new EventPluginContext(client, event, contextData); + + return { + contextData, + context, + client, + event + } +} diff --git a/src/plugins/default/ModuleInfoPlugin.ts b/src/plugins/default/ModuleInfoPlugin.ts index d880edef..dc51710d 100644 --- a/src/plugins/default/ModuleInfoPlugin.ts +++ b/src/plugins/default/ModuleInfoPlugin.ts @@ -3,7 +3,7 @@ import { EventPluginContext } from '../EventPluginContext'; import { IModule } from '../../models/IModule'; export class ModuleInfoPlugin implements IEventPlugin { - public priority:number = 40; + public priority:number = 50; public name:string = 'ModuleInfoPlugin'; public run(context:EventPluginContext, next?:() => void): void { diff --git a/src/plugins/default/RequestInfoPlugin.ts b/src/plugins/default/RequestInfoPlugin.ts index 0b53a7d9..62b3ad2d 100644 --- a/src/plugins/default/RequestInfoPlugin.ts +++ b/src/plugins/default/RequestInfoPlugin.ts @@ -3,7 +3,7 @@ import { EventPluginContext } from '../EventPluginContext'; import { IRequestInfo } from '../../models/IRequestInfo'; export class RequestInfoPlugin implements IEventPlugin { - public priority:number = 60; + public priority:number = 70; public name:string = 'RequestInfoPlugin'; public run(context:EventPluginContext, next?:() => void): void { From 19aba22afbadcc9d24fb05a84d896ded754dd8e4 Mon Sep 17 00:00:00 2001 From: Frank Ebersoll Date: Wed, 11 Nov 2015 22:30:24 +0100 Subject: [PATCH 2/3] Added DuplicateChecker to default plugins --- src/plugins/EventPluginManager.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugins/EventPluginManager.ts b/src/plugins/EventPluginManager.ts index 7b6c7f14..f3c72448 100644 --- a/src/plugins/EventPluginManager.ts +++ b/src/plugins/EventPluginManager.ts @@ -7,6 +7,7 @@ import { ModuleInfoPlugin } from './default/ModuleInfoPlugin'; import { RequestInfoPlugin } from './default/RequestInfoPlugin'; import { EnvironmentInfoPlugin } from './default/EnvironmentInfoPlugin'; import { SubmissionMethodPlugin } from './default/SubmissionMethodPlugin'; +import { DuplicateCheckerPlugin } from './default/DuplicateCheckerPlugin'; export class EventPluginManager { public static run(context:EventPluginContext, callback:(context?:EventPluginContext) => void): void { @@ -43,6 +44,7 @@ export class EventPluginManager { public static addDefaultPlugins(config:Configuration): void { config.addPlugin(new ConfigurationDefaultsPlugin()); config.addPlugin(new ErrorPlugin()); + config.addPlugin(new DuplicateCheckerPlugin()); config.addPlugin(new ModuleInfoPlugin()); config.addPlugin(new RequestInfoPlugin()); config.addPlugin(new EnvironmentInfoPlugin()); From 5806f96226b3872461dbda2e45ae41c4f2d09e59 Mon Sep 17 00:00:00 2001 From: Frank Ebersoll Date: Wed, 11 Nov 2015 22:55:44 +0100 Subject: [PATCH 3/3] Code style and generated files --- dist/exceptionless.d.ts | 68 +++++----- dist/exceptionless.js | 69 +++++++++- dist/exceptionless.js.map | 2 +- dist/exceptionless.min.js | 4 +- dist/exceptionless.min.js.map | 2 +- dist/exceptionless.node.js | 69 +++++++++- dist/exceptionless.node.js.map | 2 +- .../default/DuplicateCheckerPlugin-spec.ts | 125 +++++++++--------- src/plugins/default/DuplicateCheckerPlugin.ts | 12 +- src/plugins/default/EventPluginTestFixture.ts | 62 ++++----- 10 files changed, 274 insertions(+), 141 deletions(-) diff --git a/dist/exceptionless.d.ts b/dist/exceptionless.d.ts index cce444f1..50106c7a 100644 --- a/dist/exceptionless.d.ts +++ b/dist/exceptionless.d.ts @@ -326,6 +326,37 @@ export interface IEnvironmentInfo { runtime_version?: string; data?: any; } +export interface IParameter { + data?: any; + generic_arguments?: string[]; + name?: string; + type?: string; + type_namespace?: string; +} +export interface IMethod { + data?: any; + generic_arguments?: string[]; + parameters?: IParameter[]; + is_signature_target?: boolean; + declaring_namespace?: string; + declaring_type?: string; + name?: string; + module_id?: number; +} +export interface IStackFrame extends IMethod { + file_name?: string; + line_number?: number; + column?: number; +} +export interface IInnerError { + message?: string; + type?: string; + code?: string; + data?: any; + inner?: IInnerError; + stack_trace?: IStackFrame[]; + target_method?: IMethod; +} export declare class ConfigurationDefaultsPlugin implements IEventPlugin { priority: number; name: string; @@ -358,36 +389,13 @@ export declare class SubmissionMethodPlugin implements IEventPlugin { name: string; run(context: EventPluginContext, next?: () => void): void; } -export interface IParameter { - data?: any; - generic_arguments?: string[]; - name?: string; - type?: string; - type_namespace?: string; -} -export interface IMethod { - data?: any; - generic_arguments?: string[]; - parameters?: IParameter[]; - is_signature_target?: boolean; - declaring_namespace?: string; - declaring_type?: string; - name?: string; - module_id?: number; -} -export interface IStackFrame extends IMethod { - file_name?: string; - line_number?: number; - column?: number; -} -export interface IInnerError { - message?: string; - type?: string; - code?: string; - data?: any; - inner?: IInnerError; - stack_trace?: IStackFrame[]; - target_method?: IMethod; +export declare class DuplicateCheckerPlugin implements IEventPlugin { + priority: number; + name: string; + private recentlyProcessedErrors; + run(context: EventPluginContext, next?: () => void): void; + private getNow(); + private checkDuplicate(error, log); } export interface IError extends IInnerError { modules?: IModule[]; diff --git a/dist/exceptionless.js b/dist/exceptionless.js index ea542e07..0a7639f4 100644 --- a/dist/exceptionless.js +++ b/dist/exceptionless.js @@ -1332,6 +1332,7 @@ var EventPluginManager = (function () { EventPluginManager.addDefaultPlugins = function (config) { config.addPlugin(new ConfigurationDefaultsPlugin()); config.addPlugin(new ErrorPlugin()); + config.addPlugin(new DuplicateCheckerPlugin()); config.addPlugin(new ModuleInfoPlugin()); config.addPlugin(new RequestInfoPlugin()); config.addPlugin(new EnvironmentInfoPlugin()); @@ -2336,7 +2337,7 @@ var ErrorPlugin = (function () { exports.ErrorPlugin = ErrorPlugin; var ModuleInfoPlugin = (function () { function ModuleInfoPlugin() { - this.priority = 40; + this.priority = 50; this.name = 'ModuleInfoPlugin'; } ModuleInfoPlugin.prototype.run = function (context, next) { @@ -2355,7 +2356,7 @@ var ModuleInfoPlugin = (function () { exports.ModuleInfoPlugin = ModuleInfoPlugin; var RequestInfoPlugin = (function () { function RequestInfoPlugin() { - this.priority = 60; + this.priority = 70; this.name = 'RequestInfoPlugin'; } RequestInfoPlugin.prototype.run = function (context, next) { @@ -2374,7 +2375,7 @@ var RequestInfoPlugin = (function () { exports.RequestInfoPlugin = RequestInfoPlugin; var EnvironmentInfoPlugin = (function () { function EnvironmentInfoPlugin() { - this.priority = 70; + this.priority = 80; this.name = 'EnvironmentInfoPlugin'; } EnvironmentInfoPlugin.prototype.run = function (context, next) { @@ -2406,6 +2407,68 @@ var SubmissionMethodPlugin = (function () { return SubmissionMethodPlugin; })(); exports.SubmissionMethodPlugin = SubmissionMethodPlugin; +var ERROR_KEY = '@error'; +var WINDOW_MILLISECONDS = 2000; +var MAX_QUEUE_LENGTH = 10; +var DuplicateCheckerPlugin = (function () { + function DuplicateCheckerPlugin() { + this.priority = 40; + this.name = 'DuplicateCheckerPlugin'; + this.recentlyProcessedErrors = []; + } + DuplicateCheckerPlugin.prototype.run = function (context, next) { + if (context.event.type === 'error') { + var error = context.event.data[ERROR_KEY]; + var isDuplicate = this.checkDuplicate(error, context.log); + if (isDuplicate) { + context.cancelled = true; + return; + } + } + next && next(); + }; + DuplicateCheckerPlugin.prototype.getNow = function () { + return Date.now(); + }; + DuplicateCheckerPlugin.prototype.checkDuplicate = function (error, log) { + var now = this.getNow(); + var repeatWindow = now - WINDOW_MILLISECONDS; + var hashCode; + while (error) { + hashCode = getHashCodeForError(error); + if (hashCode && this.recentlyProcessedErrors.some(function (h) { + return h.hash === hashCode && h.timestamp >= repeatWindow; + })) { + log.info("Ignoring duplicate error event: hash=" + hashCode); + return true; + } + this.recentlyProcessedErrors.push({ hash: hashCode, timestamp: now }); + while (this.recentlyProcessedErrors.length > MAX_QUEUE_LENGTH) { + this.recentlyProcessedErrors.shift(); + } + error = error.inner; + } + return false; + }; + return DuplicateCheckerPlugin; +})(); +exports.DuplicateCheckerPlugin = DuplicateCheckerPlugin; +function getHashCodeForError(error) { + if (!error.stack_trace) { + return null; + } + var stack = JSON.stringify(error.stack_trace); + return getHashCode(stack); +} +function getHashCode(s) { + var hash = 0, length = s.length, char; + for (var i = 0; i < length; i++) { + char = s.charCodeAt(i); + hash = ((hash << 5) - hash) + char; + hash |= 0; + } + return hash; +} var SettingsResponse = (function () { function SettingsResponse(success, settings, settingsVersion, exception, message) { if (settingsVersion === void 0) { settingsVersion = -1; } diff --git a/dist/exceptionless.js.map b/dist/exceptionless.js.map index cc8d56d1..6218fa89 100644 --- a/dist/exceptionless.js.map +++ b/dist/exceptionless.js.map @@ -1 +1 @@ -{"version":3,"sources":["tracekit.js","/source/exceptionless.ts"],"names":["getDefaultsSettingsFromScriptTag","processUnhandledException"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AC7oCA,8BAA8B,+BAA+B,CAAC,CAAA;AAqC9D,mCAAmC,+BAA+B,CAAC,CAAA;AACnE,uCAAuC,mCAAmC,CAAC,CAAA;AAC3E,4CAA4C,wCAAwC,CAAC,CAAA;AAIrF,yCAAyC,uCAAuC,CAAC,CAAA;AAKjF,oCAAoC,uBAAuB,CAAC,CAAA;AAC5D,sBAAsB,SAAS,CAAC,CAAA;AAEhC;IACEA,EAAEA,CAACA,CAACA,CAACA,QAAQA,IAAIA,CAACA,QAAQA,CAACA,oBAAoBA,CAACA,CAACA,CAACA;QAChDA,MAAMA,CAACA,IAAIA,CAACA;IACdA,CAACA;IAEDA,IAAIA,OAAOA,GAAGA,QAAQA,CAACA,oBAAoBA,CAACA,QAAQA,CAACA,CAACA;IACtDA,GAAGA,CAACA,CAACA,GAAGA,CAACA,KAAKA,GAAGA,CAACA,EAAEA,KAAKA,GAAGA,OAAOA,CAACA,MAAMA,EAAEA,KAAKA,EAAEA,EAAEA,CAACA;QACpDA,EAAEA,CAACA,CAACA,OAAOA,CAACA,KAAKA,CAACA,CAACA,GAAGA,IAAIA,OAAOA,CAACA,KAAKA,CAACA,CAACA,GAAGA,CAACA,OAAOA,CAACA,gBAAgBA,CAACA,GAAGA,CAACA,CAACA,CAACA,CAACA,CAACA;YAC5EA,MAAMA,CAACA,aAAKA,CAACA,gBAAgBA,CAACA,OAAOA,CAACA,KAAKA,CAACA,CAACA,GAAGA,CAACA,KAAKA,CAACA,GAAGA,CAACA,CAACA,GAAGA,EAAEA,CAACA,CAACA;QACrEA,CAACA;IACHA,CAACA;IACDA,MAAMA,CAACA,IAAIA,CAACA;AACdA,CAACA;AAED,mCAAmC,UAA8B,EAAE,OAAY;IAC7EC,IAAIA,OAAOA,GAAGA,yCAAmBA,CAACA,OAAOA,CAACA,wBAAwBA,CAACA,IAAIA,KAAKA,CAACA,UAAUA,CAACA,OAAOA,IAAIA,CAACA,OAAOA,IAAIA,EAAEA,CAACA,CAACA,MAAMA,IAAIA,cAAcA,CAACA,EAAEA,SAASA,CAACA,CAACA;IACzJA,OAAOA,CAACA,iBAAiBA,CAACA,wBAAwBA,CAACA,GAAGA,UAAUA,CAACA;IACjEA,OAAOA,CAACA,MAAMA,EAAEA,CAACA;AACnBA,CAACA;AAmBD,IAAI,QAAQ,GAAG,6BAAa,CAAC,QAAQ,CAAC;AACtC,IAAI,QAAQ,GAAG,gCAAgC,EAAE,CAAC;AAClD,EAAE,CAAC,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACxD,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;IAClC,QAAQ,CAAC,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC;AAC1C,CAAC;AAED,QAAQ,CAAC,WAAW,GAAG,IAAI,uCAAkB,EAAE,CAAC;AAChD,QAAQ,CAAC,eAAe,GAAG,IAAI,+CAAsB,EAAE,CAAC;AACxD,QAAQ,CAAC,oBAAoB,GAAG,IAAI,yDAA2B,EAAE,CAAC;AAClE,QAAQ,CAAC,iBAAiB,GAAG,IAAI,mDAAwB,EAAE,CAAC;AAE5D,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,yBAAyB,CAAC,CAAC;AACrD,QAAQ,CAAC,6BAA6B,EAAE,CAAC;AAUnC,KAAM,CAAC,eAAe,GAAG,QAAQ,CAAC","file":"exceptionless.js","sourcesContent":["/*\n TraceKit - Cross browser stack traces - github.com/csnover/TraceKit\n MIT license\n*/\n\n(function(window, undefined) {\nif (!window) {\n return;\n}\n\nvar TraceKit = {};\nvar _oldTraceKit = window.TraceKit;\n\n// global reference to slice\nvar _slice = [].slice;\nvar UNKNOWN_FUNCTION = '?';\n\n\n/**\n * _has, a better form of hasOwnProperty\n * Example: _has(MainHostObject, property) === true/false\n *\n * @param {Object} object to check property\n * @param {string} key to check\n */\nfunction _has(object, key) {\n return Object.prototype.hasOwnProperty.call(object, key);\n}\n\nfunction _isUndefined(what) {\n return typeof what === 'undefined';\n}\n\n/**\n * TraceKit.noConflict: Export TraceKit out to another variable\n * Example: var TK = TraceKit.noConflict()\n */\nTraceKit.noConflict = function noConflict() {\n window.TraceKit = _oldTraceKit;\n return TraceKit;\n};\n\n/**\n * TraceKit.wrap: Wrap any function in a TraceKit reporter\n * Example: func = TraceKit.wrap(func);\n *\n * @param {Function} func Function to be wrapped\n * @return {Function} The wrapped func\n */\nTraceKit.wrap = function traceKitWrapper(func) {\n function wrapped() {\n try {\n return func.apply(this, arguments);\n } catch (e) {\n TraceKit.report(e);\n throw e;\n }\n }\n return wrapped;\n};\n\n/**\n * TraceKit.report: cross-browser processing of unhandled exceptions\n *\n * Syntax:\n * TraceKit.report.subscribe(function(stackInfo) { ... })\n * TraceKit.report.unsubscribe(function(stackInfo) { ... })\n * TraceKit.report(exception)\n * try { ...code... } catch(ex) { TraceKit.report(ex); }\n *\n * Supports:\n * - Firefox: full stack trace with line numbers, plus column number\n * on top frame; column number is not guaranteed\n * - Opera: full stack trace with line and column numbers\n * - Chrome: full stack trace with line and column numbers\n * - Safari: line and column number for the top frame only; some frames\n * may be missing, and column number is not guaranteed\n * - IE: line and column number for the top frame only; some frames\n * may be missing, and column number is not guaranteed\n *\n * In theory, TraceKit should work on all of the following versions:\n * - IE5.5+ (only 8.0 tested)\n * - Firefox 0.9+ (only 3.5+ tested)\n * - Opera 7+ (only 10.50 tested; versions 9 and earlier may require\n * Exceptions Have Stacktrace to be enabled in opera:config)\n * - Safari 3+ (only 4+ tested)\n * - Chrome 1+ (only 5+ tested)\n * - Konqueror 3.5+ (untested)\n *\n * Requires TraceKit.computeStackTrace.\n *\n * Tries to catch all unhandled exceptions and report them to the\n * subscribed handlers. Please note that TraceKit.report will rethrow the\n * exception. This is REQUIRED in order to get a useful stack trace in IE.\n * If the exception does not reach the top of the browser, you will only\n * get a stack trace from the point where TraceKit.report was called.\n *\n * Handlers receive a stackInfo object as described in the\n * TraceKit.computeStackTrace docs.\n */\nTraceKit.report = (function reportModuleWrapper() {\n var handlers = [],\n lastException = null,\n lastExceptionStack = null;\n\n /**\n * Add a crash handler.\n * @param {Function} handler\n */\n function subscribe(handler) {\n installGlobalHandler();\n handlers.push(handler);\n }\n\n /**\n * Remove a crash handler.\n * @param {Function} handler\n */\n function unsubscribe(handler) {\n for (var i = handlers.length - 1; i >= 0; --i) {\n if (handlers[i] === handler) {\n handlers.splice(i, 1);\n }\n }\n }\n\n /**\n * Dispatch stack information to all handlers.\n * @param {Object.} stack\n */\n function notifyHandlers(stack, isWindowError) {\n var exception = null;\n if (isWindowError && !TraceKit.collectWindowErrors) {\n return;\n }\n for (var i in handlers) {\n if (_has(handlers, i)) {\n try {\n handlers[i].apply(null, [stack].concat(_slice.call(arguments, 2)));\n } catch (inner) {\n exception = inner;\n }\n }\n }\n\n if (exception) {\n throw exception;\n }\n }\n\n var _oldOnerrorHandler, _onErrorHandlerInstalled;\n\n /**\n * Ensures all global unhandled exceptions are recorded.\n * Supported by Gecko and IE.\n * @param {string} message Error message.\n * @param {string} url URL of script that generated the exception.\n * @param {(number|string)} lineNo The line number at which the error\n * occurred.\n * @param {?(number|string)} columnNo The column number at which the error\n * occurred.\n * @param {?Error} errorObj The actual Error object.\n */\n function traceKitWindowOnError(message, url, lineNo, columnNo, errorObj) {\n var stack = null;\n\n if (errorObj) {\n stack = TraceKit.computeStackTrace(errorObj);\n }\n else\n {\n if (lastExceptionStack) {\n TraceKit.computeStackTrace.augmentStackTraceWithInitialElement(lastExceptionStack, url, lineNo, message);\n stack = lastExceptionStack;\n lastExceptionStack = null;\n lastException = null;\n } else {\n var location = {\n 'url': url,\n 'line': lineNo,\n 'column': columnNo\n };\n location.func = TraceKit.computeStackTrace.guessFunctionName(location.url, location.line);\n location.context = TraceKit.computeStackTrace.gatherContext(location.url, location.line);\n stack = {\n 'mode': 'onerror',\n 'message': message,\n 'stack': [location]\n };\n }\n }\n\n notifyHandlers(stack, 'from window.onerror');\n\n if (_oldOnerrorHandler) {\n return _oldOnerrorHandler.apply(this, arguments);\n }\n\n return false;\n }\n\n function installGlobalHandler ()\n {\n if (_onErrorHandlerInstalled === true) {\n return;\n }\n _oldOnerrorHandler = window.onerror;\n window.onerror = traceKitWindowOnError;\n _onErrorHandlerInstalled = true;\n }\n\n /**\n * Reports an unhandled Error to TraceKit.\n * @param {Error} ex\n */\n function report(ex) {\n var args = _slice.call(arguments, 1);\n if (lastExceptionStack) {\n if (lastException === ex) {\n return; // already caught by an inner catch block, ignore\n } else {\n var s = lastExceptionStack;\n lastExceptionStack = null;\n lastException = null;\n notifyHandlers.apply(null, [s, null].concat(args));\n }\n }\n\n var stack = TraceKit.computeStackTrace(ex);\n lastExceptionStack = stack;\n lastException = ex;\n\n // If the stack trace is incomplete, wait for 2 seconds for\n // slow slow IE to see if onerror occurs or not before reporting\n // this exception; otherwise, we will end up with an incomplete\n // stack trace\n window.setTimeout(function () {\n if (lastException === ex) {\n lastExceptionStack = null;\n lastException = null;\n notifyHandlers.apply(null, [stack, null].concat(args));\n }\n }, (stack.incomplete ? 2000 : 0));\n\n throw ex; // re-throw to propagate to the top level (and cause window.onerror)\n }\n\n report.subscribe = subscribe;\n report.unsubscribe = unsubscribe;\n return report;\n}());\n\n/**\n * TraceKit.computeStackTrace: cross-browser stack traces in JavaScript\n *\n * Syntax:\n * s = TraceKit.computeStackTrace.ofCaller([depth])\n * s = TraceKit.computeStackTrace(exception) // consider using TraceKit.report instead (see below)\n * Returns:\n * s.name - exception name\n * s.message - exception message\n * s.stack[i].url - JavaScript or HTML file URL\n * s.stack[i].func - function name, or empty for anonymous functions (if guessing did not work)\n * s.stack[i].args - arguments passed to the function, if known\n * s.stack[i].line - line number, if known\n * s.stack[i].column - column number, if known\n * s.stack[i].context - an array of source code lines; the middle element corresponds to the correct line#\n * s.mode - 'stack', 'stacktrace', 'multiline', 'callers', 'onerror', or 'failed' -- method used to collect the stack trace\n *\n * Supports:\n * - Firefox: full stack trace with line numbers and unreliable column\n * number on top frame\n * - Opera 10: full stack trace with line and column numbers\n * - Opera 9-: full stack trace with line numbers\n * - Chrome: full stack trace with line and column numbers\n * - Safari: line and column number for the topmost stacktrace element\n * only\n * - IE: no line numbers whatsoever\n *\n * Tries to guess names of anonymous functions by looking for assignments\n * in the source code. In IE and Safari, we have to guess source file names\n * by searching for function bodies inside all page scripts. This will not\n * work for scripts that are loaded cross-domain.\n * Here be dragons: some function names may be guessed incorrectly, and\n * duplicate functions may be mismatched.\n *\n * TraceKit.computeStackTrace should only be used for tracing purposes.\n * Logging of unhandled exceptions should be done with TraceKit.report,\n * which builds on top of TraceKit.computeStackTrace and provides better\n * IE support by utilizing the window.onerror event to retrieve information\n * about the top of the stack.\n *\n * Note: In IE and Safari, no stack trace is recorded on the Error object,\n * so computeStackTrace instead walks its *own* chain of callers.\n * This means that:\n * * in Safari, some methods may be missing from the stack trace;\n * * in IE, the topmost function in the stack trace will always be the\n * caller of computeStackTrace.\n *\n * This is okay for tracing (because you are likely to be calling\n * computeStackTrace from the function you want to be the topmost element\n * of the stack trace anyway), but not okay for logging unhandled\n * exceptions (because your catch block will likely be far away from the\n * inner function that actually caused the exception).\n *\n * Tracing example:\n * function trace(message) {\n * var stackInfo = TraceKit.computeStackTrace.ofCaller();\n * var data = message + \"\\n\";\n * for(var i in stackInfo.stack) {\n * var item = stackInfo.stack[i];\n * data += (item.func || '[anonymous]') + \"() in \" + item.url + \":\" + (item.line || '0') + \"\\n\";\n * }\n * if (window.console)\n * console.info(data);\n * else\n * alert(data);\n * }\n */\nTraceKit.computeStackTrace = (function computeStackTraceWrapper() {\n var debug = false,\n sourceCache = {};\n\n /**\n * Attempts to retrieve source code via XMLHttpRequest, which is used\n * to look up anonymous function names.\n * @param {string} url URL of source code.\n * @return {string} Source contents.\n */\n function loadSource(url) {\n if (!TraceKit.remoteFetching) { //Only attempt request if remoteFetching is on.\n return '';\n }\n try {\n var getXHR = function() {\n try {\n return new window.XMLHttpRequest();\n } catch (e) {\n // explicitly bubble up the exception if not found\n return new window.ActiveXObject('Microsoft.XMLHTTP');\n }\n };\n\n var request = getXHR();\n request.open('GET', url, false);\n request.send('');\n return request.responseText;\n } catch (e) {\n return '';\n }\n }\n\n /**\n * Retrieves source code from the source code cache.\n * @param {string} url URL of source code.\n * @return {Array.} Source contents.\n */\n function getSource(url) {\n if (typeof url !== 'string') {\n return [];\n }\n\n if (!_has(sourceCache, url)) {\n // URL needs to be able to fetched within the acceptable domain. Otherwise,\n // cross-domain errors will be triggered.\n var source = '';\n\n var domain = '';\n try { domain = document.domain; } catch (e) {}\n if (url.indexOf(domain) !== -1) {\n source = loadSource(url);\n }\n sourceCache[url] = source ? source.split('\\n') : [];\n }\n\n return sourceCache[url];\n }\n\n /**\n * Tries to use an externally loaded copy of source code to determine\n * the name of a function by looking at the name of the variable it was\n * assigned to, if any.\n * @param {string} url URL of source code.\n * @param {(string|number)} lineNo Line number in source code.\n * @return {string} The function name, if discoverable.\n */\n function guessFunctionName(url, lineNo) {\n var reFunctionArgNames = /function ([^(]*)\\(([^)]*)\\)/,\n reGuessFunction = /['\"]?([0-9A-Za-z$_]+)['\"]?\\s*[:=]\\s*(function|eval|new Function)/,\n line = '',\n maxLines = 10,\n source = getSource(url),\n m;\n\n if (!source.length) {\n return UNKNOWN_FUNCTION;\n }\n\n // Walk backwards from the first line in the function until we find the line which\n // matches the pattern above, which is the function definition\n for (var i = 0; i < maxLines; ++i) {\n line = source[lineNo - i] + line;\n\n if (!_isUndefined(line)) {\n if ((m = reGuessFunction.exec(line))) {\n return m[1];\n } else if ((m = reFunctionArgNames.exec(line))) {\n return m[1];\n }\n }\n }\n\n return UNKNOWN_FUNCTION;\n }\n\n /**\n * Retrieves the surrounding lines from where an exception occurred.\n * @param {string} url URL of source code.\n * @param {(string|number)} line Line number in source code to centre\n * around for context.\n * @return {?Array.} Lines of source code.\n */\n function gatherContext(url, line) {\n var source = getSource(url);\n\n if (!source.length) {\n return null;\n }\n\n var context = [],\n // linesBefore & linesAfter are inclusive with the offending line.\n // if linesOfContext is even, there will be one extra line\n // *before* the offending line.\n linesBefore = Math.floor(TraceKit.linesOfContext / 2),\n // Add one extra line if linesOfContext is odd\n linesAfter = linesBefore + (TraceKit.linesOfContext % 2),\n start = Math.max(0, line - linesBefore - 1),\n end = Math.min(source.length, line + linesAfter - 1);\n\n line -= 1; // convert to 0-based index\n\n for (var i = start; i < end; ++i) {\n if (!_isUndefined(source[i])) {\n context.push(source[i]);\n }\n }\n\n return context.length > 0 ? context : null;\n }\n\n /**\n * Escapes special characters, except for whitespace, in a string to be\n * used inside a regular expression as a string literal.\n * @param {string} text The string.\n * @return {string} The escaped string literal.\n */\n function escapeRegExp(text) {\n return text.replace(/[\\-\\[\\]{}()*+?.,\\\\\\^$|#]/g, '\\\\$&');\n }\n\n /**\n * Escapes special characters in a string to be used inside a regular\n * expression as a string literal. Also ensures that HTML entities will\n * be matched the same as their literal friends.\n * @param {string} body The string.\n * @return {string} The escaped string.\n */\n function escapeCodeAsRegExpForMatchingInsideHTML(body) {\n return escapeRegExp(body).replace('<', '(?:<|<)').replace('>', '(?:>|>)').replace('&', '(?:&|&)').replace('\"', '(?:\"|")').replace(/\\s+/g, '\\\\s+');\n }\n\n /**\n * Determines where a code fragment occurs in the source code.\n * @param {RegExp} re The function definition.\n * @param {Array.} urls A list of URLs to search.\n * @return {?Object.} An object containing\n * the url, line, and column number of the defined function.\n */\n function findSourceInUrls(re, urls) {\n var source, m;\n for (var i = 0, j = urls.length; i < j; ++i) {\n // console.log('searching', urls[i]);\n if ((source = getSource(urls[i])).length) {\n source = source.join('\\n');\n if ((m = re.exec(source))) {\n // console.log('Found function in ' + urls[i]);\n\n return {\n 'url': urls[i],\n 'line': source.substring(0, m.index).split('\\n').length,\n 'column': m.index - source.lastIndexOf('\\n', m.index) - 1\n };\n }\n }\n }\n\n // console.log('no match');\n\n return null;\n }\n\n /**\n * Determines at which column a code fragment occurs on a line of the\n * source code.\n * @param {string} fragment The code fragment.\n * @param {string} url The URL to search.\n * @param {(string|number)} line The line number to examine.\n * @return {?number} The column number.\n */\n function findSourceInLine(fragment, url, line) {\n var source = getSource(url),\n re = new RegExp('\\\\b' + escapeRegExp(fragment) + '\\\\b'),\n m;\n\n line -= 1;\n\n if (source && source.length > line && (m = re.exec(source[line]))) {\n return m.index;\n }\n\n return null;\n }\n\n /**\n * Determines where a function was defined within the source code.\n * @param {(Function|string)} func A function reference or serialized\n * function definition.\n * @return {?Object.} An object containing\n * the url, line, and column number of the defined function.\n */\n function findSourceByFunctionBody(func) {\n var urls = [window.location.href],\n scripts = document.getElementsByTagName('script'),\n body,\n code = '' + func,\n codeRE = /^function(?:\\s+([\\w$]+))?\\s*\\(([\\w\\s,]*)\\)\\s*\\{\\s*(\\S[\\s\\S]*\\S)\\s*\\}\\s*$/,\n eventRE = /^function on([\\w$]+)\\s*\\(event\\)\\s*\\{\\s*(\\S[\\s\\S]*\\S)\\s*\\}\\s*$/,\n re,\n parts,\n result;\n\n for (var i = 0; i < scripts.length; ++i) {\n var script = scripts[i];\n if (script.src) {\n urls.push(script.src);\n }\n }\n\n if (!(parts = codeRE.exec(code))) {\n re = new RegExp(escapeRegExp(code).replace(/\\s+/g, '\\\\s+'));\n }\n\n // not sure if this is really necessary, but I don’t have a test\n // corpus large enough to confirm that and it was in the original.\n else {\n var name = parts[1] ? '\\\\s+' + parts[1] : '',\n args = parts[2].split(',').join('\\\\s*,\\\\s*');\n\n body = escapeRegExp(parts[3]).replace(/;$/, ';?'); // semicolon is inserted if the function ends with a comment.replace(/\\s+/g, '\\\\s+');\n re = new RegExp('function' + name + '\\\\s*\\\\(\\\\s*' + args + '\\\\s*\\\\)\\\\s*{\\\\s*' + body + '\\\\s*}');\n }\n\n // look for a normal function definition\n if ((result = findSourceInUrls(re, urls))) {\n return result;\n }\n\n // look for an old-school event handler function\n if ((parts = eventRE.exec(code))) {\n var event = parts[1];\n body = escapeCodeAsRegExpForMatchingInsideHTML(parts[2]);\n\n // look for a function defined in HTML as an onXXX handler\n re = new RegExp('on' + event + '=[\\\\\\'\"]\\\\s*' + body + '\\\\s*[\\\\\\'\"]', 'i');\n\n if ((result = findSourceInUrls(re, urls[0]))) {\n return result;\n }\n\n // look for ???\n re = new RegExp(body);\n\n if ((result = findSourceInUrls(re, urls))) {\n return result;\n }\n }\n\n return null;\n }\n\n // Contents of Exception in various browsers.\n //\n // SAFARI:\n // ex.message = Can't find variable: qq\n // ex.line = 59\n // ex.sourceId = 580238192\n // ex.sourceURL = http://...\n // ex.expressionBeginOffset = 96\n // ex.expressionCaretOffset = 98\n // ex.expressionEndOffset = 98\n // ex.name = ReferenceError\n //\n // FIREFOX:\n // ex.message = qq is not defined\n // ex.fileName = http://...\n // ex.lineNumber = 59\n // ex.columnNumber = 69\n // ex.stack = ...stack trace... (see the example below)\n // ex.name = ReferenceError\n //\n // CHROME:\n // ex.message = qq is not defined\n // ex.name = ReferenceError\n // ex.type = not_defined\n // ex.arguments = ['aa']\n // ex.stack = ...stack trace...\n //\n // INTERNET EXPLORER:\n // ex.message = ...\n // ex.name = ReferenceError\n //\n // OPERA:\n // ex.message = ...message... (see the example below)\n // ex.name = ReferenceError\n // ex.opera#sourceloc = 11 (pretty much useless, duplicates the info in ex.message)\n // ex.stacktrace = n/a; see 'opera:config#UserPrefs|Exceptions Have Stacktrace'\n\n /**\n * Computes stack trace information from the stack property.\n * Chrome and Gecko use this property.\n * @param {Error} ex\n * @return {?Object.} Stack trace information.\n */\n function computeStackTraceFromStackProp(ex) {\n if (!ex.stack) {\n return null;\n }\n\n var chrome = /^\\s*at (.*?) ?\\(((?:file|https?|chrome-extension|native|eval).*?)(?::(\\d+))?(?::(\\d+))?\\)?\\s*$/i,\n gecko = /^\\s*(.*?)(?:\\((.*?)\\))?@?((?:file|https?|chrome|\\[).*?)(?::(\\d+))?(?::(\\d+))?\\s*$/i,\n winjs = /^\\s*at (?:((?:\\[object object\\])?.+) )?\\(?((?:ms-appx|http|https):.*?):(\\d+)(?::(\\d+))?\\)?\\s*$/i,\n lines = ex.stack.split('\\n'),\n stack = [],\n parts,\n element,\n reference = /^(.*) is undefined$/.exec(ex.message);\n\n for (var i = 0, j = lines.length; i < j; ++i) {\n if ((parts = chrome.exec(lines[i]))) {\n var isNative = parts[2] && parts[2].indexOf('native') !== -1;\n element = {\n 'url': !isNative ? parts[2] : null,\n 'func': parts[1] || UNKNOWN_FUNCTION,\n 'args': isNative ? [parts[2]] : [],\n 'line': parts[3] ? +parts[3] : null,\n 'column': parts[4] ? +parts[4] : null\n };\n } else if ((parts = winjs.exec(lines[i]))) {\n element = {\n 'url': parts[2],\n 'func': parts[1] || UNKNOWN_FUNCTION,\n 'args': [],\n 'line': +parts[3],\n 'column': parts[4] ? +parts[4] : null\n };\n } else if ((parts = gecko.exec(lines[i]))) {\n element = {\n 'url': parts[3],\n 'func': parts[1] || UNKNOWN_FUNCTION,\n 'args': parts[2] ? parts[2].split(',') : [],\n 'line': parts[4] ? +parts[4] : null,\n 'column': parts[5] ? +parts[5] : null\n };\n } else {\n continue;\n }\n\n if (!element.func && element.line) {\n element.func = guessFunctionName(element.url, element.line);\n }\n\n if (element.line) {\n element.context = gatherContext(element.url, element.line);\n }\n\n stack.push(element);\n }\n\n if (!stack.length) {\n return null;\n }\n\n if (stack[0] && stack[0].line && !stack[0].column && reference) {\n stack[0].column = findSourceInLine(reference[1], stack[0].url, stack[0].line);\n } else if (!stack[0].column && !_isUndefined(ex.columnNumber)) {\n // FireFox uses this awesome columnNumber property for its top frame\n // Also note, Firefox's column number is 0-based and everything else expects 1-based,\n // so adding 1\n stack[0].column = ex.columnNumber + 1;\n }\n\n return {\n 'mode': 'stack',\n 'name': ex.name,\n 'message': ex.message,\n 'stack': stack\n };\n }\n\n /**\n * Computes stack trace information from the stacktrace property.\n * Opera 10+ uses this property.\n * @param {Error} ex\n * @return {?Object.} Stack trace information.\n */\n function computeStackTraceFromStacktraceProp(ex) {\n // Access and store the stacktrace property before doing ANYTHING\n // else to it because Opera is not very good at providing it\n // reliably in other circumstances.\n var stacktrace = ex.stacktrace;\n if (!stacktrace) {\n return;\n }\n\n var opera10Regex = / line (\\d+).*script (?:in )?(\\S+)(?:: in function (\\S+))?$/i,\n opera11Regex = / line (\\d+), column (\\d+)\\s*(?:in (?:]+)>|([^\\)]+))\\((.*)\\))? in (.*):\\s*$/i,\n lines = stacktrace.split('\\n'),\n stack = [],\n parts;\n\n for (var line = 0; line < lines.length; line += 2) {\n var element = null;\n if ((parts = opera10Regex.exec(lines[line]))) {\n element = {\n 'url': parts[2],\n 'line': +parts[1],\n 'column': null,\n 'func': parts[3],\n 'args':[]\n };\n } else if ((parts = opera11Regex.exec(lines[line]))) {\n element = {\n 'url': parts[6],\n 'line': +parts[1],\n 'column': +parts[2],\n 'func': parts[3] || parts[4],\n 'args': parts[5] ? parts[5].split(',') : []\n };\n }\n\n if (element) {\n if (!element.func && element.line) {\n element.func = guessFunctionName(element.url, element.line);\n }\n if (element.line) {\n try {\n element.context = gatherContext(element.url, element.line);\n } catch (exc) {}\n }\n\n if (!element.context) {\n element.context = [lines[line + 1]];\n }\n\n stack.push(element);\n }\n }\n\n if (!stack.length) {\n return null;\n }\n\n return {\n 'mode': 'stacktrace',\n 'name': ex.name,\n 'message': ex.message,\n 'stack': stack\n };\n }\n\n /**\n * NOT TESTED.\n * Computes stack trace information from an error message that includes\n * the stack trace.\n * Opera 9 and earlier use this method if the option to show stack\n * traces is turned on in opera:config.\n * @param {Error} ex\n * @return {?Object.} Stack information.\n */\n function computeStackTraceFromOperaMultiLineMessage(ex) {\n // TODO: Clean this function up\n // Opera includes a stack trace into the exception message. An example is:\n //\n // Statement on line 3: Undefined variable: undefinedFunc\n // Backtrace:\n // Line 3 of linked script file://localhost/Users/andreyvit/Projects/TraceKit/javascript-client/sample.js: In function zzz\n // undefinedFunc(a);\n // Line 7 of inline#1 script in file://localhost/Users/andreyvit/Projects/TraceKit/javascript-client/sample.html: In function yyy\n // zzz(x, y, z);\n // Line 3 of inline#1 script in file://localhost/Users/andreyvit/Projects/TraceKit/javascript-client/sample.html: In function xxx\n // yyy(a, a, a);\n // Line 1 of function script\n // try { xxx('hi'); return false; } catch(ex) { TraceKit.report(ex); }\n // ...\n\n var lines = ex.message.split('\\n');\n if (lines.length < 4) {\n return null;\n }\n\n var lineRE1 = /^\\s*Line (\\d+) of linked script ((?:file|https?)\\S+)(?:: in function (\\S+))?\\s*$/i,\n lineRE2 = /^\\s*Line (\\d+) of inline#(\\d+) script in ((?:file|https?)\\S+)(?:: in function (\\S+))?\\s*$/i,\n lineRE3 = /^\\s*Line (\\d+) of function script\\s*$/i,\n stack = [],\n scripts = document.getElementsByTagName('script'),\n inlineScriptBlocks = [],\n parts;\n\n for (var s in scripts) {\n if (_has(scripts, s) && !scripts[s].src) {\n inlineScriptBlocks.push(scripts[s]);\n }\n }\n\n for (var line = 2; line < lines.length; line += 2) {\n var item = null;\n if ((parts = lineRE1.exec(lines[line]))) {\n item = {\n 'url': parts[2],\n 'func': parts[3],\n 'args': [],\n 'line': +parts[1],\n 'column': null\n };\n } else if ((parts = lineRE2.exec(lines[line]))) {\n item = {\n 'url': parts[3],\n 'func': parts[4],\n 'args': [],\n 'line': +parts[1],\n 'column': null // TODO: Check to see if inline#1 (+parts[2]) points to the script number or column number.\n };\n var relativeLine = (+parts[1]); // relative to the start of the