Skip to content

Commit

Permalink
Using globalThis instead of all global and window
Browse files Browse the repository at this point in the history
  • Loading branch information
xuri committed Jan 17, 2025
1 parent 6a9338e commit 00c6457
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ node_modules/

# Intermediate and distribution artifacts
dist/
.devcontainer/devcontainer.json
29 changes: 15 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
!globalThis.crypto && (globalThis.crypto = {
async getRandomValues(b) {
const { randomFillSync } = await import('crypto');
randomFillSync(b);
}
});
!globalThis.performance && (globalThis.performance = {
now() {
const [sec, nsec] = process.hrtime();
return sec * 1000 + nsec / 1000000;
}
});
if (typeof globalThis.navigator === 'undefined') {
!globalThis.crypto && (globalThis.crypto = {
async getRandomValues(b) {
const { randomFillSync } = await import('crypto');
randomFillSync(b);
}
});
!globalThis.performance && (globalThis.performance = {
now() {
const [sec, nsec] = process.hrtime();
return sec * 1000 + nsec / 1000000;
}
});
}
(() => {
const enosys = () => {
const err = new Error("not implemented");
Expand Down Expand Up @@ -570,7 +572,7 @@ import pako from 'pako';
export async function init(wasmPath) {
const go = new Go();
var buffer;
if (fs && fs.readFileSync) {
if (typeof globalThis.navigator === 'undefined') {
globalThis.excelize = {};
const fs = await import('fs');
buffer = pako.ungzip(fs.readFileSync(wasmPath));
Expand All @@ -585,4 +587,3 @@ export async function init(wasmPath) {
go.run(result.instance);
return excelize;
};

0 comments on commit 00c6457

Please sign in to comment.