Skip to content

Commit 66251e0

Browse files
authored
Use globalThis instead of global (#3763)
Switches use of `global` to `globalThis`, which is better supported when building with modern build tools like Vite. Refs #2903 Signed-off-by: Damon Vestervand <[email protected]> Signed-off-by: Damon <[email protected]>
1 parent ff53557 commit 66251e0

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

spec/olm-loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { logger } from "../src/logger";
2020
// try to load the olm library.
2121
try {
2222
// eslint-disable-next-line @typescript-eslint/no-var-requires
23-
global.Olm = require("@matrix-org/olm");
23+
globalThis.Olm = require("@matrix-org/olm");
2424
logger.log("loaded libolm");
2525
} catch (e) {
2626
logger.warn("unable to run crypto tests: libolm not available", e);

src/browser-index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ declare global {
2424
/* eslint-enable no-var */
2525
}
2626

27-
if (global.__js_sdk_entrypoint) {
27+
if (globalThis.__js_sdk_entrypoint) {
2828
throw new Error("Multiple matrix-js-sdk entrypoints detected!");
2929
}
30-
global.__js_sdk_entrypoint = true;
30+
globalThis.__js_sdk_entrypoint = true;
3131

3232
// just *accessing* indexedDB throws an exception in firefox with indexeddb disabled.
3333
let indexedDB: IDBFactory | undefined;
3434
try {
35-
indexedDB = global.indexedDB;
35+
indexedDB = globalThis.indexedDB;
3636
} catch (e) {}
3737

3838
// if our browser (appears to) support indexeddb, use an indexeddb crypto store.
@@ -44,4 +44,4 @@ if (indexedDB) {
4444
// It's awkward, but required.
4545
export * from "./matrix";
4646
export default matrixcs; // keep export for browserify package deps
47-
global.matrixcs = matrixcs;
47+
globalThis.matrixcs = matrixcs;

src/crypto/crypto.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ limitations under the License.
1616

1717
import { logger } from "../logger";
1818

19-
export let crypto = global.window?.crypto;
20-
export let subtleCrypto = global.window?.crypto?.subtle ?? global.window?.crypto?.webkitSubtle;
21-
export let TextEncoder = global.window?.TextEncoder;
19+
export let crypto = globalThis.window?.crypto;
20+
export let subtleCrypto = globalThis.window?.crypto?.subtle ?? global.window?.crypto?.webkitSubtle;
21+
export let TextEncoder = globalThis.window?.TextEncoder;
2222

2323
/* eslint-disable @typescript-eslint/no-var-requires */
2424
if (!crypto) {

src/crypto/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export const verificationMethods = {
134134
export type VerificationMethod = keyof typeof verificationMethods | string;
135135

136136
export function isCryptoAvailable(): boolean {
137-
return Boolean(global.Olm);
137+
return Boolean(globalThis.Olm);
138138
}
139139

140140
// minimum time between attempting to unwedge an Olm session, if we succeeded

0 commit comments

Comments
 (0)