Avoid multiple declarations in an EN_ASM({}) block

Some emscripten versions don't seem to support it.
This commit is contained in:
Frank Denis 2017-09-11 11:49:59 +02:00
parent b26de68a67
commit 0ae678b0f9

View File

@ -94,9 +94,9 @@ randombytes_stir(void)
EM_ASM({
if (Module.getRandomValue === undefined) {
try {
var window_ = 'object' === typeof window ? window : self,
crypto_ = typeof window_.crypto !== 'undefined' ? window_.crypto : window_.msCrypto,
randomValuesStandard = function() {
var window_ = 'object' === typeof window ? window : self;
var crypto_ = typeof window_.crypto !== 'undefined' ? window_.crypto : window_.msCrypto;
var randomValuesStandard = function() {
var buf = new Uint32Array(1);
crypto_.getRandomValues(buf);
return buf[0] >>> 0;
@ -105,8 +105,8 @@ randombytes_stir(void)
Module.getRandomValue = randomValuesStandard;
} catch (e) {
try {
var crypto = require('crypto'),
randomValueNodeJS = function() {
var crypto = require('crypto');
var randomValueNodeJS = function() {
var buf = crypto.randomBytes(4);
return (buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3]) >>> 0;
};