Skip to content

Commit

Permalink
Fix bug with undefined window in web workers
Browse files Browse the repository at this point in the history
Fixes #8
  • Loading branch information
emilbayes committed Nov 3, 2017
1 parent 5511baf commit f336097
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions randombytes.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var assert = require('nanoassert')
var randombytes = (function () {
var QUOTA = 65536 // limit for QuotaExceededException
var crypto = typeof window !== 'undefined' ? (window.crypto || window.msCrypto) : null
var crypto = typeof global !== 'undefined' ? crypto = (global.crypto || global.msCrypto) : null

function windowBytes (out, n) {
function browserBytes (out, n) {
for (var i = 0; i < n; i += QUOTA) {
crypto.getRandomValues(out.subarray(i, i + Math.min(n - i, QUOTA)))
}
Expand All @@ -18,7 +18,7 @@ var randombytes = (function () {
}

if (crypto && crypto.getRandomValues) {
return windowBytes
return browserBytes
} else if (typeof require !== 'undefined') {
// Node.js.
crypto = require('cry' + 'pto');
Expand Down

0 comments on commit f336097

Please sign in to comment.