Skip to content

Commit

Permalink
capricorn86#712@patch: fix handling of callback arguments passing giv…
Browse files Browse the repository at this point in the history
…en to setTimeout / setInterval
  • Loading branch information
CSchulz committed Feb 3, 2023
1 parent cdd1b99 commit 54391b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions packages/happy-dom/src/window/IWindow.ts
Expand Up @@ -302,9 +302,10 @@ export default interface IWindow extends IEventTarget, NodeJS.Global {
*
* @param callback Function to be executed.
* @param [delay=0] Delay in ms.
* @param args Arguments passed to the callback function.
* @returns Timeout ID.
*/
setTimeout(callback: () => void, delay?: number): NodeJS.Timeout;
setTimeout(callback: Function, delay?: number, ...args: any[]): NodeJS.Timeout;

/**
* Cancels a timeout previously established by calling setTimeout().
Expand All @@ -318,9 +319,10 @@ export default interface IWindow extends IEventTarget, NodeJS.Global {
*
* @param callback Function to be executed.
* @param [delay=0] Delay in ms.
* @param args Arguments passed to the callback function.
* @returns Interval ID.
*/
setInterval(callback: () => void, delay?: number): NodeJS.Timeout;
setInterval(callback: Function, delay?: number, ...args: any[]): NodeJS.Timeout;

/**
* Cancels a timed repeating action which was previously established by a call to setInterval().
Expand Down
10 changes: 6 additions & 4 deletions packages/happy-dom/src/window/Window.ts
Expand Up @@ -622,12 +622,13 @@ export default class Window extends EventTarget implements IWindow {
* @override
* @param callback Function to be executed.
* @param [delay=0] Delay in ms.
* @param args Arguments passed to the callback function.
* @returns Timeout ID.
*/
public setTimeout(callback: () => void, delay = 0): NodeJS.Timeout {
public setTimeout(callback: Function, delay = 0, ...args: any[]): NodeJS.Timeout {
const id = this._setTimeout(() => {
this.happyDOM.asyncTaskManager.endTimer(id);
callback();
callback(args);
}, delay);
this.happyDOM.asyncTaskManager.startTimer(id);
return id;
Expand All @@ -650,10 +651,11 @@ export default class Window extends EventTarget implements IWindow {
* @override
* @param callback Function to be executed.
* @param [delay=0] Delay in ms.
* @param args Arguments passed to the callback function.
* @returns Interval ID.
*/
public setInterval(callback: () => void, delay = 0): NodeJS.Timeout {
const id = this._setInterval(callback, delay);
public setInterval(callback: Function, delay = 0, ...args: any[]): NodeJS.Timeout {
const id = this._setInterval(callback, delay, args);
this.happyDOM.asyncTaskManager.startTimer(id);
return id;
}
Expand Down

0 comments on commit 54391b3

Please sign in to comment.