Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Revert getRandomValues using Math for tests on V8.
  • Loading branch information
maraf committed Nov 23, 2022
commit a4b0fc5bce1f2d7f4de79fe3616e483d03b05d93
12 changes: 12 additions & 0 deletions src/mono/wasm/test-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ if (is_node && process.versions.node.split(".")[0] < 14) {
throw new Error(`NodeJS at '${process.execPath}' has too low version '${process.versions.node}'`);
}

if (!is_node && !is_browser && typeof globalThis.crypto === 'undefined') {
// **NOTE** this is a simple insecure polyfill for testing purposes only
// /dev/random doesn't work on js shells, so define our own
// See library_fs.js:createDefaultDevices ()
globalThis.crypto = {
getRandomValues: function (buffer) {
for (let i = 0; i < buffer.length; i++)
buffer[i] = (Math.random() * 256) | 0;
}
}
}

let v8args;
if (typeof arguments !== "undefined") {
// this must be captured in top level scope in V8
Expand Down