Skip to content

Commit

Permalink
Fix illegal invocation of getRandomValues (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimelrian authored and broofa committed Jan 16, 2018
1 parent c0d44fd commit 262a8ea
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/rng-browser.js
Expand Up @@ -3,8 +3,9 @@
// and inconsistent support for the `crypto` API. We do the best we can via
// feature-detection

var getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues) ||
(typeof(msCrypto) != 'undefined' && msCrypto.getRandomValues);
// getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
var getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues.bind(crypto)) ||
(typeof(msCrypto) != 'undefined' && msCrypto.getRandomValues.bind(msCrypto));
if (getRandomValues) {
// WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto
var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef
Expand Down

0 comments on commit 262a8ea

Please sign in to comment.