From 2b5bbe96ed56d2116b8c627abeb817ad20097174 Mon Sep 17 00:00:00 2001
From: nev21 <82737406+nev21@users.noreply.github.com>
Date: Mon, 18 Mar 2024 00:54:41 -0700
Subject: [PATCH] [Bug] TypeError: Illegal invocation when calling setTimeout
#252 (#253)
---
lib/src/timer/interval.ts | 7 +++----
lib/src/timer/timeout.ts | 18 +++++++++---------
2 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/lib/src/timer/interval.ts b/lib/src/timer/interval.ts
index 7c170b05..92d7ef1f 100644
--- a/lib/src/timer/interval.ts
+++ b/lib/src/timer/interval.ts
@@ -7,7 +7,7 @@
*/
import { fnApply } from "../funcs/funcs";
-import { ArrSlice, CALL } from "../internal/constants";
+import { ArrSlice, CALL, UNDEF_VALUE } from "../internal/constants";
import { ITimerHandler, _createTimerHandler } from "./handler";
/**
@@ -77,14 +77,13 @@ export function scheduleInterval(callback: (...args: A) => void
* ```
*/
export function scheduleInterval(callback: (...args: A) => void, timeout: number): ITimerHandler {
- let self = this;
let theArguments = ArrSlice[CALL](arguments);
let handler = _createTimerHandler(true, (intervalId: any) => {
intervalId && clearInterval(intervalId);
- return fnApply(setInterval, self, theArguments)
+ return fnApply(setInterval, UNDEF_VALUE, theArguments)
}, (intervalId: any) => {
- fnApply(clearInterval, self, [ intervalId ]);
+ fnApply(clearInterval, UNDEF_VALUE, [ intervalId ]);
});
return handler.h;
diff --git a/lib/src/timer/timeout.ts b/lib/src/timer/timeout.ts
index 57de1f11..8aa962bf 100644
--- a/lib/src/timer/timeout.ts
+++ b/lib/src/timer/timeout.ts
@@ -11,7 +11,7 @@ import { isArray } from "../helpers/base";
import { ArrSlice, CALL, UNDEF_VALUE } from "../internal/constants";
import { ITimerHandler, _createTimerHandler } from "./handler";
-function _createTimeoutWith(self: any, startTimer: boolean, overrideFn: TimeoutOverrideFn | TimeoutOverrideFuncs, theArgs: any[]): ITimerHandler {
+function _createTimeoutWith(startTimer: boolean, overrideFn: TimeoutOverrideFn | TimeoutOverrideFuncs, theArgs: any[]): ITimerHandler {
let isArr = isArray(overrideFn);
let len = isArr ? overrideFn.length : 0;
let setFn: TimeoutOverrideFn = (len > 0 ? overrideFn[0] : (!isArr ? overrideFn : UNDEF_VALUE)) || setTimeout;
@@ -20,7 +20,7 @@ function _createTimeoutWith(self: any, startTimer: boolean, overrideFn: TimeoutO
let timerFn = theArgs[0];
theArgs[0] = function () {
handler.dn();
- fnApply(timerFn, self, ArrSlice[CALL](arguments));
+ fnApply(timerFn, UNDEF_VALUE, ArrSlice[CALL](arguments));
};
let handler = _createTimerHandler(startTimer, (timerId?: any) => {
@@ -30,12 +30,12 @@ function _createTimeoutWith(self: any, startTimer: boolean, overrideFn: TimeoutO
return timerId;
}
- fnApply(clearFn, self, [ timerId ]);
+ fnApply(clearFn, UNDEF_VALUE, [ timerId ]);
}
- return fnApply(setFn, self, theArgs);
+ return fnApply(setFn, UNDEF_VALUE, theArgs);
}, function (timerId: any) {
- fnApply(clearFn, self, [ timerId ]);
+ fnApply(clearFn, UNDEF_VALUE, [ timerId ]);
});
return handler.h;
@@ -149,7 +149,7 @@ export function scheduleTimeout(callback: (...args: A) => void,
* ```
*/
export function scheduleTimeout(callback: (...args: A) => void, timeout: number): ITimerHandler {
- return _createTimeoutWith(this, true, UNDEF_VALUE, ArrSlice[CALL](arguments));
+ return _createTimeoutWith(true, UNDEF_VALUE, ArrSlice[CALL](arguments));
}
/**
@@ -317,7 +317,7 @@ export function scheduleTimeoutWith(overrideFn: TimeoutOverride
* ```
*/
export function scheduleTimeoutWith(overrideFn: TimeoutOverrideFn | TimeoutOverrideFuncs, callback: (...args: A) => void, timeout: number): ITimerHandler {
- return _createTimeoutWith(this, true, overrideFn, ArrSlice[CALL](arguments, 1));
+ return _createTimeoutWith(true, overrideFn, ArrSlice[CALL](arguments, 1));
}
/**
@@ -387,7 +387,7 @@ export function createTimeout(callback: (...args: A) => void, t
* ```
*/
export function createTimeout(callback: (...args: A) => void, timeout: number): ITimerHandler {
- return _createTimeoutWith(this, false, UNDEF_VALUE, ArrSlice[CALL](arguments));
+ return _createTimeoutWith(false, UNDEF_VALUE, ArrSlice[CALL](arguments));
}
/**
@@ -535,5 +535,5 @@ export function createTimeoutWith(overrideFn: TimeoutOverrideFn
* ```
*/
export function createTimeoutWith(overrideFn: TimeoutOverrideFn | TimeoutOverrideFuncs, callback: (...args: A) => void, timeout: number): ITimerHandler {
- return _createTimeoutWith(this, false, overrideFn, ArrSlice[CALL](arguments, 1));
+ return _createTimeoutWith(false, overrideFn, ArrSlice[CALL](arguments, 1));
}