Test the eventual desired interface

This commit is contained in:
Alex Crichton
2017-12-14 20:07:26 -08:00
parent d2d9f6be11
commit d5897c6e56
2 changed files with 15 additions and 4 deletions

View File

@ -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);

View File

@ -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();