Skip to content

Commit 6ef46fd

Browse files
committed
use self instead of window in JS
this allows the same code to work in both windowed contexts (ie, the usual browser stuff) and in non-windowed contexts (like web workers). see https://developer.mozilla.org/en-US/docs/Web/API/Window/self node doesn't have `self` or `window`, so it shouldn't matter either way
1 parent ad14217 commit 6ef46fd

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/rngs/os.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,9 +1023,9 @@ mod imp {
10231023
let result = js! {
10241024
try {
10251025
if (
1026-
typeof window === "object" &&
1027-
typeof window.crypto === "object" &&
1028-
typeof window.crypto.getRandomValues === "function"
1026+
typeof self === "object" &&
1027+
typeof self.crypto === "object" &&
1028+
typeof self.crypto.getRandomValues === "function"
10291029
) {
10301030
return { success: true, ty: 1 };
10311031
}
@@ -1063,7 +1063,7 @@ mod imp {
10631063
OsRngMethod::Browser => js! {
10641064
try {
10651065
let array = new Uint8Array(@{ len });
1066-
window.crypto.getRandomValues(array);
1066+
self.crypto.getRandomValues(array);
10671067
HEAPU8.set(array, @{ ptr });
10681068

10691069
return { success: true };

0 commit comments

Comments
 (0)