From 43132738d2961ea28bc487327da524709b80b3fe Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 7 Jul 2013 22:04:13 -0700 Subject: [PATCH] Add a pre-js script for providing /dev/urandom to tests in Javascript. Not plugged to the build system yet. --- test/default/pre.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/default/pre.js diff --git a/test/default/pre.js b/test/default/pre.js new file mode 100644 index 00000000..812253de --- /dev/null +++ b/test/default/pre.js @@ -0,0 +1,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); +});