mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-12 20:41:24 +00:00
Test the eventual desired interface
This commit is contained in:
@ -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);
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user