summaryrefslogtreecommitdiff
path: root/test/default/pre.js
blob: 812253de299e17f756ca32864df9b0569700edb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
try {
    this['Module'] = Module;
    Module.test;
} catch(e) {
    this['Module'] = Module = {};
}
Module['preRun'] = Module['preRun'] || [];
Module['preRun'].push(function(){
    var randombyte = null;    
    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;
        } catch(e) { }
    }
    FS.init();
    var devFolder = FS.findObject('/dev') ||
        Module['FS_createFolder']('/', 'dev', true, true);    
    Module['FS_createDevice'](devFolder, 'random', randombyte);
    Module['FS_createDevice'](devFolder, 'urandom', randombyte);    
});