Skip to content

Commit 584926e

Browse files
authored
wasm_js: remove IE 11 workaround (#554)
Internet Explorer is superseded by Edge (which has 3-5% usage share) and effectively no longer supported. Citing Wikipedia: >For SAC versions of Windows 10, Internet Explorer 11 support ended on June 15, 2022, Internet Explorer was permanently disabled on February 14, 2023, and any remaining icons or shortcuts were due to be removed on June 13, 2023. Technically, it's still supported on LTSC, but Microsoft discourages the use of LTSC editions outside of "special-purpose devices" that perform a fixed function and thus do not require new user experience features, so I think we can ignore it.
1 parent cddf861 commit 584926e

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
in favor of configuration flags [#504]
1919
- `register_custom_getrandom!` macro [#504]
2020
- Implementation of `From<NonZeroU32>` for `Error` and `Error::code` method [#507]
21+
- Internet Explorer 11 support [#554]
2122

2223
### Changed
2324
- Use `ProcessPrng` on Windows 10 and up, and use RtlGenRandom on older legacy Windows versions [#415]
@@ -52,6 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5253
[#532]: https://github.com/rust-random/getrandom/pull/532
5354
[#542]: https://github.com/rust-random/getrandom/pull/542
5455
[#544]: https://github.com/rust-random/getrandom/pull/544
56+
[#554]: https://github.com/rust-random/getrandom/pull/554
5557

5658
## [0.2.15] - 2024-05-06
5759
### Added

src/backends/wasm_js.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,29 +83,23 @@ fn getrandom_init() -> Result<RngSource, Error> {
8383
// Get the Web Crypto interface if we are in a browser, Web Worker, Deno,
8484
// or another environment that supports the Web Cryptography API. This
8585
// also allows for user-provided polyfills in unsupported environments.
86-
let crypto = match global.crypto() {
87-
// Standard Web Crypto interface
88-
c if c.is_object() => c,
89-
// Node.js CommonJS Crypto module
90-
_ if is_node(&global) => {
91-
// If module.require isn't a valid function, we are in an ES module.
92-
match Module::require_fn().and_then(JsCast::dyn_into::<Function>) {
93-
Ok(require_fn) => match require_fn.call1(&global, &JsValue::from_str("crypto")) {
94-
Ok(n) => return Ok(RngSource::Node(n.unchecked_into())),
95-
Err(_) => return Err(Error::NODE_CRYPTO),
96-
},
97-
Err(_) => return Err(Error::NODE_ES_MODULE),
98-
}
99-
}
100-
// IE 11 Workaround
101-
_ => match global.ms_crypto() {
102-
c if c.is_object() => c,
103-
_ => return Err(Error::WEB_CRYPTO),
104-
},
105-
};
106-
107-
let buf = Uint8Array::new_with_length(WEB_CRYPTO_BUFFER_SIZE.into());
108-
Ok(RngSource::Web(crypto, buf))
86+
let crypto = global.crypto();
87+
if crypto.is_object() {
88+
let buf = Uint8Array::new_with_length(WEB_CRYPTO_BUFFER_SIZE.into());
89+
Ok(RngSource::Web(crypto, buf))
90+
} else if is_node(&global) {
91+
// If module.require isn't a valid function, we are in an ES module.
92+
let require_fn = Module::require_fn()
93+
.and_then(JsCast::dyn_into::<Function>)
94+
.map_err(|_| Error::NODE_ES_MODULE)?;
95+
let n = require_fn
96+
.call1(&global, &JsValue::from_str("crypto"))
97+
.map_err(|_| Error::NODE_CRYPTO)?
98+
.unchecked_into();
99+
Ok(RngSource::Node(n))
100+
} else {
101+
Err(Error::WEB_CRYPTO)
102+
}
109103
}
110104

111105
// Taken from https://www.npmjs.com/package/browser-or-node

0 commit comments

Comments
 (0)