MCPcopy Create free account
hub / github.com/github/gh-aw / loadWasmExecJs

Function loadWasmExecJs

scripts/test-wasm-golden.mjs:56–73  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54
55// ── Load Go wasm_exec.js runtime ─────────────────────────────────────
56function loadWasmExecJs() {
57 const goRoot = execSync("go env GOROOT", { encoding: "utf8" }).trim();
58 // Go 1.24+ moved wasm_exec.js from misc/wasm/ to lib/wasm/
59 let wasmExecPath = join(goRoot, "lib/wasm/wasm_exec.js");
60 if (!existsSync(wasmExecPath)) {
61 wasmExecPath = join(goRoot, "misc/wasm/wasm_exec.js");
62 }
63 if (!existsSync(wasmExecPath)) {
64 throw new Error(`wasm_exec.js not found in ${goRoot}/lib/wasm/ or ${goRoot}/misc/wasm/`);
65 }
66 // wasm_exec.js expects a global `require` for Node.js
67 globalThis.require = createRequire(import.meta.url);
68 // Load the wasm_exec.js script (it defines globalThis.Go)
69 const script = readFileSync(wasmExecPath, "utf8");
70 // Use indirect eval to run in global scope
71 const fn = new Function(script);
72 fn();
73}
74
75// ── Instantiate wasm module ──────────────────────────────────────────
76async function instantiateWasm() {

Callers 1

mainFunction · 0.85

Calls 2

readFileSyncFunction · 0.85
fnFunction · 0.85

Tested by

no test coverage detected