Skip to content
Snippets Groups Projects
Commit 7bfdabf3 authored by zer0x64's avatar zer0x64 Committed by Joseph Richey
Browse files

wasm-bindgen: Added support for Internet Explorer 11

parent 717b5cc6
No related branches found
No related tags found
No related merge requests found
...@@ -58,17 +58,17 @@ fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { ...@@ -58,17 +58,17 @@ fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
fn getrandom_init() -> Result<RngSource, Error> { fn getrandom_init() -> Result<RngSource, Error> {
if let Ok(self_) = Global::get_self() { if let Ok(self_) = Global::get_self() {
// If `self` is defined then we're in a browser somehow (main window // If `self` is defined then we're in a browser somehow (main window
// or web worker). Here we want to try to use // or web worker). We get `self.crypto` (called `msCrypto` on IE), so we
// `crypto.getRandomValues`, but if `crypto` isn't defined we assume // can call `crypto.getRandomValues`. If `crypto` isn't defined, we
// we're in an older web browser and the OS RNG isn't available. // assume we're in an older web browser and the OS RNG isn't available.
let crypto = self_.crypto(); let crypto: BrowserCrypto = match (self_.crypto(), self_.ms_crypto()) {
if crypto.is_undefined() { (crypto, _) if !crypto.is_undefined() => crypto.into(),
return Err(Error::BINDGEN_CRYPTO_UNDEF); (_, crypto) if !crypto.is_undefined() => crypto.into(),
} _ => return Err(Error::BINDGEN_CRYPTO_UNDEF),
};
// Test if `crypto.getRandomValues` is undefined as well // Test if `crypto.getRandomValues` is undefined as well
let crypto: BrowserCrypto = crypto.into();
if crypto.get_random_values_fn().is_undefined() { if crypto.get_random_values_fn().is_undefined() {
return Err(Error::BINDGEN_GRV_UNDEF); return Err(Error::BINDGEN_GRV_UNDEF);
} }
...@@ -86,6 +86,8 @@ extern "C" { ...@@ -86,6 +86,8 @@ extern "C" {
fn get_self() -> Result<Self_, JsValue>; fn get_self() -> Result<Self_, JsValue>;
type Self_; type Self_;
#[wasm_bindgen(method, getter, js_name = "msCrypto", structural)]
fn ms_crypto(me: &Self_) -> JsValue;
#[wasm_bindgen(method, getter, structural)] #[wasm_bindgen(method, getter, structural)]
fn crypto(me: &Self_) -> JsValue; fn crypto(me: &Self_) -> JsValue;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment