Skip to content

Commit

Permalink
fix: Restore correct functionToString behavior for updated fill method (
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed Dec 6, 2019
1 parent 61385c3 commit a876d46
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/integrations/functiontostring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class FunctionToString implements Integration {
originalFunctionToString = Function.prototype.toString;

Function.prototype.toString = function(this: WrappedFunction, ...args: any[]): string {
const context = this.__sentry__ ? this.__sentry_original__ : this;
const context = this.__sentry_original__ || this;
// tslint:disable-next-line:no-unsafe-any
return originalFunctionToString.apply(context, args);
};
Expand Down
25 changes: 25 additions & 0 deletions packages/core/test/lib/integrations/functiontostring.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { fill } from '../../../../utils/src/object';
import { FunctionToString } from '../../../src/integrations/functiontostring';

describe('FunctionToString', () => {
it('it works as expected', () => {
const foo = {
bar(wat: boolean): boolean {
return wat;
},
};
const originalFunction = foo.bar.toString();
fill(foo, 'bar', function wat(whatever: boolean): () => void {
return function watwat(): boolean {
return whatever;
};
});

expect(foo.bar.toString()).not.toBe(originalFunction);

const fts = new FunctionToString();
fts.setupOnce();

expect(foo.bar.toString()).toBe(originalFunction);
});
});
4 changes: 2 additions & 2 deletions packages/utils/src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ export function consoleSandbox(callback: () => any): any {

// Restore all wrapped console methods
levels.forEach(level => {
if (level in global.console && (originalConsole[level] as WrappedFunction).__sentry__) {
wrappedLevels[level] = (originalConsole[level] as WrappedFunction).__sentry_wrapped__;
if (level in global.console && (originalConsole[level] as WrappedFunction).__sentry_original__) {
wrappedLevels[level] = originalConsole[level] as WrappedFunction;
originalConsole[level] = (originalConsole[level] as WrappedFunction).__sentry_original__;
}
});
Expand Down

0 comments on commit a876d46

Please sign in to comment.