Skip to content

Commit 8191d7f

Browse files
authored
Merge pull request #143 from josephlr/fixing-webpack-warning
Apply #137 to 0.2 branch
2 parents 7bfdabf + ec4a3e1 commit 8191d7f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

custom/wasm-bindgen/src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn getrandom_init() -> Result<RngSource, Error> {
7676
return Ok(RngSource::Browser(crypto));
7777
}
7878

79-
return Ok(RngSource::Node(node_require("crypto")));
79+
return Ok(RngSource::Node(MODULE.require("crypto")));
8080
}
8181

8282
#[wasm_bindgen]
@@ -102,12 +102,17 @@ extern "C" {
102102
#[wasm_bindgen(method, js_name = getRandomValues, structural)]
103103
fn get_random_values(me: &BrowserCrypto, buf: &mut [u8]);
104104

105-
#[wasm_bindgen(js_name = require)]
106-
fn node_require(s: &str) -> NodeCrypto;
107-
108105
#[derive(Clone, Debug)]
109106
type NodeCrypto;
110107

111108
#[wasm_bindgen(method, js_name = randomFillSync, structural)]
112109
fn random_fill_sync(me: &NodeCrypto, buf: &mut [u8]);
110+
111+
type NodeModule;
112+
113+
#[wasm_bindgen(js_name = module)]
114+
static MODULE: NodeModule;
115+
116+
#[wasm_bindgen(method)]
117+
fn require(this: &NodeModule, s: &str) -> NodeCrypto;
113118
}

0 commit comments

Comments
 (0)