'use strict';
(({ setTimeout: setTimeoutNative, setInterval: setIntervalNative, clearTimer }) => {
globalThis.setTimeout = (callback, delay = 0, ...args) => {
if (typeof callback !== 'function') {
throw new TypeError('setTimeout requires a callback function');
}
const ms = Math.max(0, delay);
return setTimeoutNative(() => callback(...args), ms);
};
globalThis.setInterval = (callback, delay = 0, ...args) => {
if (typeof callback !== 'function') {
throw new TypeError('setInterval requires a callback function');
}
const ms = Math.max(0, delay);
return setIntervalNative(() => callback(...args), ms);
};
globalThis.clearTimeout = (id) => {
if (id !== undefined && id !== null) {
clearTimer(id);
}
};
globalThis.clearInterval = (id) => {
if (id !== undefined && id !== null) {
clearTimer(id);
}
};
});