@@ -68,8 +68,8 @@ fn getrandom_init() -> Result<RngSource, Error> {
6868 c if c. is_object ( ) => c,
6969 // Node.js CommonJS Crypto module
7070 _ if is_node ( & global) => {
71- // If require isn't a valid function, we are in an ES module.
72- match Module :: require_fn ( ) . dyn_into :: < Function > ( ) {
71+ // If module. require isn't a valid function, we are in an ES module.
72+ match Module :: require_fn ( ) . and_then ( JsCast :: dyn_into :: < Function > ) {
7373 Ok ( require_fn) => match require_fn. call1 ( & global, & JsValue :: from_str ( "crypto" ) ) {
7474 Ok ( n) => return Ok ( RngSource :: Node ( n. unchecked_into ( ) ) ) ,
7575 Err ( _) => return Err ( Error :: NODE_CRYPTO ) ,
@@ -126,8 +126,8 @@ extern "C" {
126126 // js_name = "module.require", so that Webpack doesn't give a warning. See:
127127 // https://github.com/rust-random/getrandom/issues/224
128128 type Module ;
129- #[ wasm_bindgen( getter, static_method_of = Module , js_class = module, js_name = require) ]
130- fn require_fn ( ) -> JsValue ;
129+ #[ wasm_bindgen( getter, static_method_of = Module , js_class = module, js_name = require, catch ) ]
130+ fn require_fn ( ) -> Result < JsValue , JsValue > ;
131131
132132 // Node JS process Object (https://nodejs.org/api/process.html)
133133 #[ wasm_bindgen( method, getter) ]
0 commit comments