Skip to content

Commit

Permalink
Update Module::require internal comments
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Richey <joerichey@google.com>
  • Loading branch information
josephlr committed Oct 6, 2022
1 parent e0c93b1 commit 9962c70
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,12 @@ extern "C" {
#[wasm_bindgen(method, js_name = randomFillSync, catch)]
fn random_fill_sync(this: &NodeCrypto, buf: &mut [u8]) -> Result<(), JsValue>;

// We use a "module" object here instead of just annotating require() with
// js_name = "module.require", so that Webpack doesn't give a warning. See:
// Ideally, we would just use `fn require(s: &str)` here. However, doing
// this causes a Webpack warning. So we instead return the function itself
// and manually invoke it using call1. This also lets us to check that the
// function actually exists, allowing for better error messages. See:
// https://github.com/rust-random/getrandom/issues/224
// https://github.com/rust-random/getrandom/issues/256
type Module;
#[wasm_bindgen(getter, static_method_of = Module, js_class = module, js_name = require, catch)]
fn require_fn() -> Result<JsValue, JsValue>;
Expand Down

0 comments on commit 9962c70

Please sign in to comment.