Skip to content

targets/wasm_exec: add runtime.getRandomData to gojs imports#5363

Open
pedramktb wants to merge 1 commit intotinygo-org:devfrom
pedramktb:fix/wasm-exec-getRandomData
Open

targets/wasm_exec: add runtime.getRandomData to gojs imports#5363
pedramktb wants to merge 1 commit intotinygo-org:devfrom
pedramktb:fix/wasm-exec-getRandomData

Conversation

@pedramktb
Copy link
Copy Markdown

@pedramktb pedramktb commented May 1, 2026

TinyGo v0.37.0 updated the net submodule (tinygo-org/net) which introduced
a call to runtime.getRandomData in the compiled wasm binary. Without a
corresponding JS implementation in the gojs import object, instantiating
the module throws:

LinkError: WebAssembly.Instance(): Import # 17 "gojs" "runtime.getRandomData":
function import requires a callable

The addition is already present at the official go runtime package: https://github.com/golang/go/blob/master/lib/wasm/wasm_exec.js#L306-L309.

Fixes #5357

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates TinyGo’s wasm_exec.js import object to include runtime.getRandomData, matching the upstream Go wasm_exec.js behavior, to prevent instantiation failures with newer TinyGo-generated WASM modules.

Changes:

  • Add a gojs import implementation for runtime.getRandomData that fills a WASM memory slice via crypto.getRandomValues.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pedramktb pedramktb force-pushed the fix/wasm-exec-getRandomData branch from df45c80 to 4c851a3 Compare May 1, 2026 23:51
@pedramktb pedramktb requested a review from Copilot May 1, 2026 23:56
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread targets/wasm_exec.js
Comment on lines +297 to +304
// func getRandomData(r []byte)
"runtime.getRandomData": (slice_ptr, slice_len, slice_cap) => {
const buf = loadSlice(slice_ptr, slice_len, slice_cap);
// crypto.getRandomValues has a 65536-byte limit per call
for (let offset = 0; offset < buf.length; offset += 65536) {
crypto.getRandomValues(buf.subarray(offset, Math.min(offset + 65536, buf.length)));
}
},
@pedramktb pedramktb force-pushed the fix/wasm-exec-getRandomData branch from 4c851a3 to 0be4a9a Compare May 1, 2026 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wasm: gojs.runtime.getRandomData is missing from wasm_exec.js, breaking crypto/ecdsa, crypto/rsa, and other DRBG users

2 participants