1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-09 10:22:46 +03:00

Replace usages of global with globalThis (#4489)

* Update src with globalThis

* Update spec with globalThis

* Replace in more spec/ places

* More changes to src/

* Add a linter rule for global

* Prettify

* lint
This commit is contained in:
Will Hunt
2024-11-01 09:15:21 +00:00
committed by GitHub
parent d04135cc1c
commit f6a169b5a5
64 changed files with 224 additions and 218 deletions

View File

@@ -33,7 +33,7 @@ const TIMER_CHECK_PERIOD_MS = 1000;
// counter, for making up ids to return from setTimeout
let count = 0;
// the key for our callback with the real global.setTimeout
// the key for our callback with the real globalThis.setTimeout
let realCallbackKey: NodeJS.Timeout | number;
type Callback = {
@@ -114,10 +114,10 @@ export function clearTimeout(key: number): void {
}
}
// use the real global.setTimeout to schedule a callback to runCallbacks.
// use the real globalThis.setTimeout to schedule a callback to runCallbacks.
function scheduleRealCallback(): void {
if (realCallbackKey) {
global.clearTimeout(realCallbackKey as NodeJS.Timeout);
globalThis.clearTimeout(realCallbackKey as NodeJS.Timeout);
}
const first = callbackList[0];
@@ -131,7 +131,7 @@ function scheduleRealCallback(): void {
const delayMs = Math.min(first.runAt - timestamp, TIMER_CHECK_PERIOD_MS);
debuglog("scheduleRealCallback: now:", timestamp, "delay:", delayMs);
realCallbackKey = global.setTimeout(runCallbacks, delayMs);
realCallbackKey = globalThis.setTimeout(runCallbacks, delayMs);
}
function runCallbacks(): void {
@@ -158,7 +158,7 @@ function runCallbacks(): void {
for (const cb of callbacksToRun) {
try {
cb.func.apply(global, cb.params);
cb.func.apply(globalThis, cb.params);
} catch (e) {
logger.error("Uncaught exception in callback function", e);
}