Skip to content

Commit 4c851a3

Browse files
committed
targets/wasm_exec: add runtime.getRandomData to gojs imports
1 parent 1a1506e commit 4c851a3

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

targets/wasm_exec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,15 @@
294294
return BigInt((timeOrigin + performance.now()) * 1e6);
295295
},
296296

297+
// func getRandomData(r []byte)
298+
"runtime.getRandomData": (slice_ptr, slice_len, slice_cap) => {
299+
const buf = loadSlice(slice_ptr, slice_len, slice_cap);
300+
// crypto.getRandomValues has a 65536-byte limit per call
301+
for (let offset = 0; offset < buf.length; offset += 65536) {
302+
crypto.getRandomValues(buf.subarray(offset, Math.min(offset + 65536, buf.length)));
303+
}
304+
},
305+
297306
// func sleepTicks(timeout int64)
298307
"runtime.sleepTicks": (timeout) => {
299308
// Do not sleep, only reactivate scheduler after the given timeout.

0 commit comments

Comments
 (0)