Skip to content

Commit 1b41bc2

Browse files
committed
fix: add runtime.getRandomData import for tinygo v0.37.0+
1 parent 06859bd commit 1b41bc2

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

cmd/workers-assets-gen/assets/wasm_exec_tinygo.js

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

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

0 commit comments

Comments
 (0)