Skip to content

Commit 7bfdabf

Browse files
zer0x64josephlr
authored andcommitted
wasm-bindgen: Added support for Internet Explorer 11
1 parent 717b5cc commit 7bfdabf

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

custom/wasm-bindgen/src/lib.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
5858
fn getrandom_init() -> Result<RngSource, Error> {
5959
if let Ok(self_) = Global::get_self() {
6060
// If `self` is defined then we're in a browser somehow (main window
61-
// or web worker). Here we want to try to use
62-
// `crypto.getRandomValues`, but if `crypto` isn't defined we assume
63-
// we're in an older web browser and the OS RNG isn't available.
64-
65-
let crypto = self_.crypto();
66-
if crypto.is_undefined() {
67-
return Err(Error::BINDGEN_CRYPTO_UNDEF);
68-
}
61+
// or web worker). We get `self.crypto` (called `msCrypto` on IE), so we
62+
// can call `crypto.getRandomValues`. If `crypto` isn't defined, we
63+
// assume we're in an older web browser and the OS RNG isn't available.
64+
65+
let crypto: BrowserCrypto = match (self_.crypto(), self_.ms_crypto()) {
66+
(crypto, _) if !crypto.is_undefined() => crypto.into(),
67+
(_, crypto) if !crypto.is_undefined() => crypto.into(),
68+
_ => return Err(Error::BINDGEN_CRYPTO_UNDEF),
69+
};
6970

7071
// Test if `crypto.getRandomValues` is undefined as well
71-
let crypto: BrowserCrypto = crypto.into();
7272
if crypto.get_random_values_fn().is_undefined() {
7373
return Err(Error::BINDGEN_GRV_UNDEF);
7474
}
@@ -86,6 +86,8 @@ extern "C" {
8686
fn get_self() -> Result<Self_, JsValue>;
8787

8888
type Self_;
89+
#[wasm_bindgen(method, getter, js_name = "msCrypto", structural)]
90+
fn ms_crypto(me: &Self_) -> JsValue;
8991
#[wasm_bindgen(method, getter, structural)]
9092
fn crypto(me: &Self_) -> JsValue;
9193

0 commit comments

Comments
 (0)