diff --git a/crates/wasm-bindgen-cli-support/src/lib.rs b/crates/wasm-bindgen-cli-support/src/lib.rs index aecac7e1..767f838f 100644 --- a/crates/wasm-bindgen-cli-support/src/lib.rs +++ b/crates/wasm-bindgen-cli-support/src/lib.rs @@ -77,8 +77,9 @@ impl Object { fn generate_js(&self) -> String { format!("\ -const xform = (instance) => {{ - return instance; +const xform = (obj) => {{ + obj.exports = obj.instance.exports; + return obj; }}; export const instantiate = (bytes, imports) => {{ return WebAssembly.instantiate(bytes, imports).then(xform); diff --git a/tests/simple.rs b/tests/simple.rs index a67105d5..b1b4b0da 100644 --- a/tests/simple.rs +++ b/tests/simple.rs @@ -14,14 +14,24 @@ fn add() { pub fn add(a: u32, b: u32) -> u32 { a + b } + + pub fn add3(a: u32) -> u32 { + a + 3 + } + + pub fn get2() -> u32 { + 2 + } } "#) .file("test.js", r#" import * as assert from "assert"; export function test(wasm) { - assert.strictEqual(wasm.instance.exports.add(1, 2), 3); - assert.strictEqual(wasm.instance.exports.add(2, 3), 5); + assert.strictEqual(wasm.exports.add(1, 2), 3); + assert.strictEqual(wasm.exports.add(2, 3), 5); + assert.strictEqual(wasm.exports.add3(2), 5); + assert.strictEqual(wasm.exports.get2(), 2); } "#) .test();