@@ -221,6 +221,9 @@ Raven.prototype = {
221221 TraceKit . report . subscribe ( function ( ) {
222222 self . _handleOnErrorStackInfo . apply ( self , arguments ) ;
223223 } ) ;
224+
225+ self . _patchFunctionToString ( ) ;
226+
224227 if ( self . _globalOptions . instrument && self . _globalOptions . instrument . tryCatch ) {
225228 self . _instrumentTryCatch ( ) ;
226229 }
@@ -377,6 +380,7 @@ Raven.prototype = {
377380 uninstall : function ( ) {
378381 TraceKit . report . uninstall ( ) ;
379382
383+ this . _unpatchFunctionToString ( ) ;
380384 this . _restoreBuiltIns ( ) ;
381385
382386 Error . stackTraceLimit = this . _originalErrorStackTraceLimit ;
@@ -939,6 +943,25 @@ Raven.prototype = {
939943 } ) ;
940944 } ,
941945
946+ _patchFunctionToString : function ( ) {
947+ var self = this ;
948+ self . _originalFunctionToString = Function . prototype . toString ;
949+ // eslint-disable-next-line no-extend-native
950+ Function . prototype . toString = function ( ) {
951+ if ( typeof this === 'function' && this . __raven__ ) {
952+ return self . _originalFunctionToString . apply ( this . __orig_method__ , arguments ) ;
953+ }
954+ return self . _originalFunctionToString . apply ( this , arguments ) ;
955+ } ;
956+ } ,
957+
958+ _unpatchFunctionToString : function ( ) {
959+ if ( this . _originalFunctionToString ) {
960+ // eslint-disable-next-line no-extend-native
961+ Function . prototype . toString = this . _originalFunctionToString ;
962+ }
963+ } ,
964+
942965 /**
943966 * Wrap timer functions and event targets to catch errors and provide
944967 * better metadata.
0 commit comments