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