@@ -22,6 +22,8 @@ var TK = TraceKit.noConflict();
22
22
// Disable Tracekit's remote fetching by default
23
23
TK . remoteFetching = false ;
24
24
25
+ var ravenCallbacks = { } ;
26
+
25
27
/*
26
28
* The core Raven singleton
27
29
*
@@ -214,9 +216,111 @@ var Raven = {
214
216
globalUser = user ;
215
217
216
218
return Raven ;
219
+ } ,
220
+
221
+ on : function ( eventType , eventCallback , eventContext ) {
222
+ var eventCallbacks ;
223
+
224
+ if ( ! eventType || typeof eventType !== "string" ) {
225
+ throw new TypeError ( "Unknown Event: " + eventType ) ;
226
+ }
227
+
228
+ if ( ! isFunction ( eventCallback ) ) {
229
+ throw new TypeError ( "Cannot attach non-function as a callback: " + eventCallback ) ;
230
+ }
231
+
232
+ eventCallbacks = ravenCallbacks [ eventType ] || ( ravenCallbacks [ eventType ] = [ ] ) ;
233
+
234
+ eventCallbacks . push ( {
235
+ callback : eventCallback ,
236
+ context : eventContext
237
+ } ) ;
238
+
239
+ return Raven ;
240
+ } ,
241
+
242
+ off : function ( eventType , eventFunction , eventContext ) {
243
+ var eventCallbacks , matches , key ;
244
+
245
+ if ( typeof eventType !== "string" && eventType != null ) {
246
+ throw new TypeError ( "Event must be null or a string to remove: " + eventType ) ;
247
+ }
248
+
249
+ if ( eventFunction == null && eventContext == null ) {
250
+ matches = callbackMatchesAlways ;
251
+ } else if ( eventFunction == null && eventContext != null ) {
252
+ matches = callbackMatchesContext ;
253
+ } else if ( eventFunction != null && eventContext == null ) {
254
+ matches = callbackMatchesFunction ;
255
+ } else {
256
+ matches = callbackMatchesBoth ;
257
+ }
258
+
259
+ eventCallbacks = ravenCallbacks [ eventType ] ;
260
+
261
+ if ( eventType == null ) {
262
+ for ( key in ravenCallbacks ) {
263
+ if ( ravenCallbacks . hasOwnProperty ( key ) ) {
264
+ eventCallbacks = ravenCallbacks [ key ] ;
265
+ removeCallbacks ( eventCallbacks , matches , eventFunction , eventContext ) ;
266
+ }
267
+ }
268
+ } else {
269
+ removeCallbacks ( eventCallbacks , matches , eventFunction , eventContext ) ;
270
+ }
271
+
272
+ return Raven ;
217
273
}
218
274
} ;
219
275
276
+ function callbackMatchesFunction ( callback , func , ctx ) {
277
+ return callback . callback === func ;
278
+ }
279
+
280
+ function callbackMatchesContext ( callback , func , ctx ) {
281
+ return callback . context === ctx ;
282
+ }
283
+
284
+ function callbackMatchesBoth ( callback , func , ctx ) {
285
+ return callbackMatchesFunction . apply ( null , arguments ) && callbackMatchesContext . apply ( null , arguments ) ;
286
+ }
287
+
288
+ function callbackMatchesAlways ( ) {
289
+ return true ;
290
+ }
291
+
292
+ function removeCallbacks ( callbacks , matches , func , ctx ) {
293
+ var i , callback , len ;
294
+
295
+ if ( ! callbacks ) {
296
+ return ;
297
+ }
298
+
299
+ for ( i = 0 , len = callbacks . length ; i < len ; ) {
300
+ callback = callbacks [ i ] ;
301
+ if ( callback && matches ( callback , func , ctx ) ) {
302
+ callbacks . splice ( i , 1 ) ;
303
+ len -= 1 ;
304
+ } else {
305
+ i += 1 ;
306
+ }
307
+ }
308
+ }
309
+
310
+ function triggerEvent ( eventType , args ) {
311
+ var eventCallbacks = ravenCallbacks [ eventType ] ,
312
+ len ,
313
+ i ;
314
+
315
+ if ( ! eventCallbacks ) {
316
+ return ;
317
+ }
318
+
319
+ for ( i = 0 , len = eventCallbacks . length ; i < len ; ++ i ) {
320
+ eventCallbacks [ i ] . callback . apply ( eventCallbacks [ i ] . context , args ) ;
321
+ }
322
+ }
323
+
220
324
var uriKeys = 'source protocol authority userInfo user password host port relative path directory file query anchor' . split ( ' ' ) ,
221
325
uriPattern = / ^ (?: (? ! [ ^ : @ ] + : [ ^ : @ \/ ] * @ ) ( [ ^ : \/ ? # . ] + ) : ) ? (?: \/ \/ ) ? ( (?: ( ( [ ^ : @ ] * ) (?: : ( [ ^ : @ ] * ) ) ? ) ? @ ) ? ( [ ^ : \/ ? # ] * ) (?: : ( \d * ) ) ? ) ( ( ( \/ (?: [ ^ ? # ] (? ! [ ^ ? # \/ ] * \. [ ^ ? # \/ . ] + (?: [ ? # ] | $ ) ) ) * \/ ? ) ? ( [ ^ ? # \/ ] * ) ) (?: \? ( [ ^ # ] * ) ) ? (?: # ( .* ) ) ? ) / ;
222
326
@@ -287,6 +391,8 @@ function handleStackInfo(stackInfo, options) {
287
391
} ) ;
288
392
}
289
393
394
+ triggerEvent ( 'handle' , [ stackInfo , options ] ) ;
395
+
290
396
processException (
291
397
stackInfo . name ,
292
398
stackInfo . message ,
@@ -458,8 +564,24 @@ function send(data) {
458
564
makeRequest ( data ) ;
459
565
}
460
566
567
+
461
568
function makeRequest ( data ) {
462
- new Image ( ) . src = globalServer + getAuthQueryString ( ) + '&sentry_data=' + encodeURIComponent ( JSON . stringify ( data ) ) ;
569
+ var img , src ;
570
+
571
+ function success ( ) {
572
+ triggerEvent ( 'success' , [ data , src ] ) ;
573
+ }
574
+
575
+ function failure ( ) {
576
+ triggerEvent ( 'failure' , [ data , src ] ) ;
577
+ }
578
+
579
+ src = globalServer + getAuthQueryString ( ) + '&sentry_data=' + encodeURIComponent ( JSON . stringify ( data ) ) ;
580
+ img = new Image ( ) ;
581
+ img . onload = success ;
582
+ img . onerror = failure ;
583
+ img . onabort = failure ;
584
+ img . src = src ;
463
585
}
464
586
465
587
function isSetup ( ) {
0 commit comments