From 4b2286c3f947a981dd470c67d25a92aab9c215ff Mon Sep 17 00:00:00 2001 From: dryajov Date: Thu, 2 Feb 2017 08:36:09 -0800 Subject: [PATCH] use self instead of window for webworker compatibility --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 17f0855..5144381 100644 --- a/index.js +++ b/index.js @@ -16,19 +16,19 @@ Rand.prototype.generate = function generate(len) { return this._rand(len); }; -if (typeof window === 'object') { - if (window.crypto && window.crypto.getRandomValues) { +if (typeof self === 'object') { + if (self.crypto && self.crypto.getRandomValues) { // Modern browsers Rand.prototype._rand = function _rand(n) { var arr = new Uint8Array(n); - window.crypto.getRandomValues(arr); + self.crypto.getRandomValues(arr); return arr; }; - } else if (window.msCrypto && window.msCrypto.getRandomValues) { + } else if (self.msCrypto && self.msCrypto.getRandomValues) { // IE Rand.prototype._rand = function _rand(n) { var arr = new Uint8Array(n); - window.msCrypto.getRandomValues(arr); + self.msCrypto.getRandomValues(arr); return arr; }; } else { @@ -38,7 +38,7 @@ if (typeof window === 'object') { }; } } else { - // Node.js or Web worker + // Node.js or Web worker with no crypto support try { var crypto = require('crypto');