You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[wasm] Catch error from loading "node:crypto" module (#78916)
* Catch error from loading node:crypto module.
* Throw error with explanation when crypto module is not available.
* Fix providing error throwing polyfill.
Copy file name to clipboardExpand all lines: src/mono/wasm/runtime/polyfills.ts
+12-2Lines changed: 12 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -201,8 +201,18 @@ export async function init_polyfills_async(): Promise<void> {
201
201
globalThis.crypto=<any>{};
202
202
}
203
203
if(!globalThis.crypto.getRandomValues){
204
-
constnodeCrypto=INTERNAL.require("node:crypto");
205
-
if(nodeCrypto.webcrypto){
204
+
letnodeCrypto: any=undefined;
205
+
try{
206
+
nodeCrypto=INTERNAL.require("node:crypto");
207
+
}catch(err: any){
208
+
// Noop, error throwing polyfill provided bellow
209
+
}
210
+
211
+
if(!nodeCrypto){
212
+
globalThis.crypto.getRandomValues=()=>{
213
+
thrownewError("Using node without crypto support. To enable current operation, either provide polyfill for 'globalThis.crypto.getRandomValues' or enable 'node:crypto' module.");
0 commit comments