From ac3d44601a6eb125624562d6d0662f7075d1d11b Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sun, 24 Apr 2016 22:53:31 +0300 Subject: [PATCH] Fix rng def in nodejs environment. --- vendor/uuid/rng.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/vendor/uuid/rng.js b/vendor/uuid/rng.js index be1c73ac7b..8cf6dfd756 100644 --- a/vendor/uuid/rng.js +++ b/vendor/uuid/rng.js @@ -9,23 +9,25 @@ "use strict"; goog.provide("uuid.rng"); +goog.require("cljs.core"); goog.scope(function() { - uuid.rng.getBytes = null; + const global = goog.global; // Check if nodejs rng is available (high quality); - if (goog.global.require !== undefined) { - const crypto = goog.global.require("crypto"); + if (cljs.core._STAR_target_STAR_ === "nodejs") { + const crypto = require("crypto"); uuid.rng.getBytes = function(n) { return crypto.randomBytes(n); }; } // Check if whatwg rng is available (high quality); - else if (goog.global.crypto.getRandomValues !== undefined) { + else if (global.crypto !== undefined && + global.crypto.getRandomValues !== undefined) { uuid.rng.getBytes = function(n) { const buf = new Uint8Array(16); - goog.global.crypto.getRandomValues(buf); + global.crypto.getRandomValues(buf); return buf; }; }