8000 [v7] Refactor TimersWrap to reuse same wrapping function · xiaohuoni/sentry-javascript@24c8a9d · GitHub
[go: up one dir, main page]

Skip to content

Commit 24c8a9d

Browse files
committed
[v7] Refactor TimersWrap to reuse same wrapping function
1 parent 81ca2e8 commit 24c8a9d

File tree

1 file changed

+9
-22
lines changed
  • packages/integration-browser-wrap/src

1 file changed

+9
-22
lines changed

packages/integration-browser-wrap/src/timers.ts

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,47 +26,34 @@ export class TimersWrap implements Integration {
2626
const global = getGlobalObject();
2727

2828
if (this._setTimeout) {
29-
fill(global, 'setTimeout', this._wrapTimeFunction.bind(this));
29+
fill(global, 'setTimeout', this._wrapTimerFunction.bind(this));
3030
}
3131

3232
if (this._setInterval) {
33-
fill(global, 'setInterval', this._wrapTimeFunction.bind(this));
33+
fill(global, 'setInterval', this._wrapTimerFunction.bind(this));
3434
}
3535

3636
if (this._requestAnimationFrame) {
37-
fill(global, 'requestAnimationFrame', this._wrapRAF.bind(this));
37+
fill(global, 'requestAnimationFrame', this._wrapTimerFunction.bind(this));
3838
}
3939
}
4040

41-
private _wrapTimeFunction(original: () => void): () => number {
42-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
43-
return function(this: any, ...args: any[]): number {
44-
const originalCallback = args[0];
45-
args[0] = wrap(originalCallback, {
46-
// TODO: Change to `handler` and add `setTimeout/setInterval` as function name.
47-
data: { function: getFunctionName(original) },
48-
handled: true,
49-
type: 'instrument',
50-
});
51-
return original.apply(this, args);
52-
};
53-
}
54-
5541
// eslint-disable-next-line @typescript-eslint/no-explicit-any
56-
private _wrapRAF(original: any): (callback: () => void) => any {
42+
private _wrapTimerFunction(original: any): (callback: () => void) => any {
5743
// eslint-disable-next-line @typescript-eslint/no-explicit-any
58-
return function(this: any, callback: () => void): () => void {
44+
return function(this: any, ...args: any[]): any {
5945
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6046
return original.call(
6147
this,
62-
wrap(callback, {
48+
wrap(args[0], {
6349
data: {
64-
function: 'requestAnimationFrame',
65-
handler: getFunctionName(original),
50+
function: getFunctionName(original),
51+
handler: getFunctionName(args[0]),
6652
},
6753
handled: true,
6854
type: 'instrument',
6955
}),
56+
...args.slice(0),
7057
);
7158
};
7259
}

0 commit comments

Comments
 (0)
0