From d5897c6e56347b741e397267c09489b235dda8d8 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 14 Dec 2017 20:07:26 -0800 Subject: [PATCH] Test the eventual desired interface --- crates/wasm-bindgen-cli-support/src/lib.rs | 5 +++-- tests/simple.rs | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) 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();