@@ -55,6 +55,7 @@ function Raven() {
5555 this . _originalConsoleMethods = { } ;
5656 this . _plugins = [ ] ;
5757 this . _startTime = now ( ) ;
58+ this . _wrappedBuiltIns = [ ] ;
5859
5960 for ( var method in this . _originalConsole ) { // eslint-disable-line guard-for-in
6061 this . _originalConsoleMethods [ method ] = this . _originalConsole [ method ] ;
@@ -267,6 +268,9 @@ Raven.prototype = {
267268 */
268269 uninstall : function ( ) {
269270 TraceKit . report . uninstall ( ) ;
271+
272+ this . _restoreBuiltIns ( ) ;
273+
270274 this . _isRavenInstalled = false ;
271275
272276 return this ;
@@ -547,9 +551,12 @@ Raven.prototype = {
547551 _wrapBuiltIns : function ( ) {
548552 var self = this ;
549553
550- function fill ( obj , name , replacement ) {
554+ function fill ( obj , name , replacement , noUndo ) {
551555 var orig = obj [ name ] ;
552556 obj [ name ] = replacement ( orig ) ;
557+ if ( ! noUndo ) {
558+ self . _wrappedBuiltIns . push ( [ obj , name , orig ] ) ;
559+ }
553560 }
554561
555562 function wrapTimeFn ( orig ) {
@@ -611,26 +618,42 @@ Raven.prototype = {
611618 var origOpen ;
612619 if ( 'XMLHttpRequest' in window ) {
613620 origOpen = XMLHttpRequest . prototype . open ;
614- XMLHttpRequest . prototype . open = function ( data ) { // preserve arity
615- var xhr = this ;
616- 'onreadystatechange onload onerror onprogress' . replace ( / \w + / g, function ( prop ) {
617- if ( prop in xhr && Object . prototype . toString . call ( xhr [ prop ] ) === '[object Function]' ) {
618- fill ( xhr , prop , function ( orig ) {
619- return self . wrap ( orig ) ;
620- } ) ;
621- }
622- } ) ;
623- origOpen . apply ( this , arguments ) ;
624- } ;
621+ fill ( XMLHttpRequest . prototype , 'open' , function ( origOpen ) {
622+ return function ( data ) { // preserve arity
623+ var xhr = this ;
624+ 'onreadystatechange onload onerror onprogress' . replace ( / \w + / g, function ( prop ) {
625+ if ( prop in xhr && Object . prototype . toString . call ( xhr [ prop ] ) === '[object Function]' ) {
626+ fill ( xhr , prop , function ( orig ) {
627+ return self . wrap ( orig ) ;
628+ } , true /* noUndo */ ) ; // don't track filled methods on XHR instances
629+ }
630+ } ) ;
631+ origOpen . apply ( this , arguments ) ;
632+ } ;
633+ } ) ;
625634 }
626635
627636 var $ = window . jQuery || window . $ ;
628- var origReady ;
629637 if ( $ && $ . fn && $ . fn . ready ) {
630- origReady = $ . fn . ready ;
631- $ . fn . ready = function ravenjQueryReadyWrapper ( fn ) {
632- return origReady . call ( this , self . wrap ( fn ) ) ;
633- } ;
638+ fill ( $ . fn , 'ready' , function ( orig ) {
639+ return function ( fn ) {
640+ orig . call ( this , self . wrap ( fn ) ) ;
641+ } ;
642+ } ) ;
643+ }
644+ } ,
645+
646+ _restoreBuiltIns : function ( ) {
647+ // restore any wrapped builtins
648+ var builtin ;
649+ while ( this . _wrappedBuiltIns . length ) {
650+ builtin = this . _wrappedBuiltIns . shift ( ) ;
651+
652+ var obj = builtin [ 0 ] ,
653+ name = builtin [ 1 ] ,
654+ orig = builtin [ 2 ] ;
655+
656+ obj [ name ] = orig ;
634657 }
635658 } ,
636659
0 commit comments