assemblyscript icon indicating copy to clipboard operation
assemblyscript copied to clipboard

Raw bindings get undefined "exports" var

Open calibertechnology opened this issue 6 months ago • 1 comments

Bug description

Expected exports to contain wasm exports, instead getting undefined value.

Steps to reproduce

Run asc with --bindings raw. In build/release.js line 24 now contains:

const { exports } = await WebAssembly.instantiate(module, adaptedImports);

I think this should instead be

const { instance } = await WebAssembly.instantiate(module, adaptedImports);
const { exports } = instance.exports;

I haven't done a PR before, so I'll describe the proposed change:

In src/bindings/js.ts line 646:

replace sb.push("const { exports } = await WebAssembly.instantiate(module"); with sb.push("const { instance } = await WebAssembly.instantiate(module");

then at line 652 insert:

indent(sb, this.indentLevel); sb.push("const { exports } = instance.exports;\n");

AssemblyScript version

v0.27.36

calibertechnology avatar May 20 '25 16:05 calibertechnology

It should work if you pass in a WebAssembly.Module instance instead of an ArrayBuffer. Confusingly, WebAssembly.instantiate has two different return types, depending on the type of the argument.

CountBleck avatar May 20 '25 23:05 CountBleck

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions!

github-actions[bot] avatar Jun 28 '25 23:06 github-actions[bot]