2013-07-08 01:04:13 -04:00
|
|
|
try {
|
|
|
|
this['Module'] = Module;
|
|
|
|
Module.test;
|
|
|
|
} catch(e) {
|
|
|
|
this['Module'] = Module = {};
|
|
|
|
}
|
|
|
|
Module['preRun'] = Module['preRun'] || [];
|
|
|
|
Module['preRun'].push(function(){
|
2014-11-22 14:56:01 -05:00
|
|
|
var randombyte = null;
|
2013-07-08 01:04:13 -04:00
|
|
|
try {
|
|
|
|
function randombyte_standard() {
|
|
|
|
var buf = new Int8Array(1);
|
|
|
|
window.crypto.getRandomValues(buf);
|
|
|
|
return buf[0];
|
|
|
|
}
|
|
|
|
randombyte_standard();
|
|
|
|
randombyte = randombyte_standard;
|
|
|
|
} catch (e) {
|
|
|
|
try {
|
|
|
|
var crypto = require('crypto');
|
|
|
|
function randombyte_node() {
|
|
|
|
return crypto.randomBytes(1)[0];
|
|
|
|
}
|
|
|
|
randombyte_node();
|
|
|
|
randombyte = randombyte_node;
|
2014-11-22 14:24:32 -05:00
|
|
|
} catch(e) {
|
|
|
|
throw 'No secure random number generator found';
|
|
|
|
}
|
2013-07-08 01:04:13 -04:00
|
|
|
}
|
|
|
|
FS.init();
|
2014-11-22 16:46:09 -05:00
|
|
|
FS.mkdir('/test-data');
|
2014-11-22 17:33:58 -05:00
|
|
|
FS.mount(NODEFS, { root: '.' }, '/test-data');
|
2014-11-22 14:56:01 -05:00
|
|
|
FS.analyzePath('/dev/random').exists && FS.unlink('/dev/random');
|
|
|
|
FS.analyzePath('/dev/urandom') && FS.unlink('/dev/urandom');
|
2013-07-08 01:04:13 -04:00
|
|
|
var devFolder = FS.findObject('/dev') ||
|
2014-11-22 14:56:01 -05:00
|
|
|
Module['FS_createFolder']('/', 'dev', true, true);
|
2013-07-08 01:04:13 -04:00
|
|
|
Module['FS_createDevice'](devFolder, 'random', randombyte);
|
2014-11-22 16:46:09 -05:00
|
|
|
Module['FS_createDevice'](devFolder, 'urandom', randombyte);
|
2013-07-08 01:04:13 -04:00
|
|
|
});
|