Skip to content

Commit

Permalink
wasm-bindgen: Added support for Internet Explorer 11
Browse files Browse the repository at this point in the history
  • Loading branch information
zer0x64 committed Apr 24, 2020
1 parent 33b859b commit 7f6dcbc
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/wasm32_bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,15 @@ fn getrandom_init() -> Result<RngSource, Error> {
// `crypto.getRandomValues`, but if `crypto` isn't defined we assume
// we're in an older web browser and the OS RNG isn't available.

let crypto = self_.crypto();
let mut crypto = self_.crypto();
if crypto.is_undefined() {
return Err(BINDGEN_CRYPTO_UNDEF);
// If crypto is undefined, we can also check if msCrypto is defined,
// in case it's Internet Explorer
crypto = self_.ms_crypto();

if crypto.is_undefined() {
return Err(BINDGEN_CRYPTO_UNDEF);
}
}

// Test if `crypto.getRandomValues` is undefined as well
Expand All @@ -88,6 +94,11 @@ extern "C" {
fn get_self() -> Result<Self_, JsValue>;

type Self_;

// Internet Explorer 11
#[wasm_bindgen(method, getter, js_name="msCrypto", structural)]
fn ms_crypto(me: &Self_) -> JsValue;

#[wasm_bindgen(method, getter, structural)]
fn crypto(me: &Self_) -> JsValue;

Expand Down

0 comments on commit 7f6dcbc

Please sign in to comment.