File tree Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ export class FunctionToString implements Integration {
2121 originalFunctionToString = Function . prototype . toString ;
2222
2323 Function . prototype . toString = function ( this : WrappedFunction , ...args : any [ ] ) : string {
24- const context = this . __sentry__ ? this . __sentry_original__ : this ;
24+ const context = this . __sentry_original__ || this ;
2525 // tslint:disable-next-line:no-unsafe-any
2626 return originalFunctionToString . apply ( context , args ) ;
2727 } ;
Original file line number Diff line number Diff line change 1+ import { fill } from '../../../../utils/src/object' ;
2+ import { FunctionToString } from '../../../src/integrations/functiontostring' ;
3+
4+ describe ( 'FunctionToString' , ( ) => {
5+ it ( 'it works as expected' , ( ) => {
6+ const foo = {
7+ bar ( wat : boolean ) : boolean {
8+ return wat ;
9+ } ,
10+ } ;
11+ const originalFunction = foo . bar . toString ( ) ;
12+ fill ( foo , 'bar' , function wat ( whatever : boolean ) : ( ) => void {
13+ return function watwat ( ) : boolean {
14+ return whatever ;
15+ } ;
16+ } ) ;
17+
18+ expect ( foo . bar . toString ( ) ) . not . toBe ( originalFunction ) ;
19+
20+ const fts = new FunctionToString ( ) ;
21+ fts . setupOnce ( ) ;
22+
23+ expect ( foo . bar . toString ( ) ) . toBe ( originalFunction ) ;
24+ } ) ;
25+ } ) ;
Original file line number Diff line number Diff line change @@ -181,8 +181,8 @@ export function consoleSandbox(callback: () => any): any {
181181
182182 // Restore all wrapped console methods
183183 levels . forEach ( level => {
184- if ( level in global . console && ( originalConsole [ level ] as WrappedFunction ) . __sentry__ ) {
185- wrappedLevels [ level ] = ( originalConsole [ level ] as WrappedFunction ) . __sentry_wrapped__ ;
184+ if ( level in global . console && ( originalConsole [ level ] as WrappedFunction ) . __sentry_original__ ) {
185+ wrappedLevels [ level ] = originalConsole [ level ] as WrappedFunction ;
186186 originalConsole [ level ] = ( originalConsole [ level ] as WrappedFunction ) . __sentry_original__ ;
187187 }
188188 } ) ;
You can’t perform that action at this time.
0 commit comments