mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 18:20:51 +00:00
Allow imports to return JS objects
This commit is contained in:
parent
294c5e147b
commit
5e80b082a9
@ -327,6 +327,12 @@ impl Js {
|
|||||||
convert = Some("_assertBoolean");
|
convert = Some("_assertBoolean");
|
||||||
self.expose_assert_bool();
|
self.expose_assert_bool();
|
||||||
}
|
}
|
||||||
|
Some(shared::Type::JsObject) => {
|
||||||
|
ts_dst.push_str("any");
|
||||||
|
dst.push_str("number");
|
||||||
|
self.expose_add_heap_object();
|
||||||
|
convert = Some("addHeapObject");
|
||||||
|
}
|
||||||
None => {
|
None => {
|
||||||
ts_dst.push_str("void");
|
ts_dst.push_str("void");
|
||||||
dst.push_str("void");
|
dst.push_str("void");
|
||||||
|
@ -15,6 +15,7 @@ fn simple() {
|
|||||||
fn foo(s: &str);
|
fn foo(s: &str);
|
||||||
fn another(a: u32) -> i32;
|
fn another(a: u32) -> i32;
|
||||||
fn take_and_return_bool(a: bool) -> bool;
|
fn take_and_return_bool(a: bool) -> bool;
|
||||||
|
fn return_object() -> JsObject;
|
||||||
}
|
}
|
||||||
pub fn bar(s: &str) {
|
pub fn bar(s: &str) {
|
||||||
foo(s);
|
foo(s);
|
||||||
@ -25,6 +26,10 @@ fn simple() {
|
|||||||
pub fn bool_thunk(a: bool) -> bool {
|
pub fn bool_thunk(a: bool) -> bool {
|
||||||
take_and_return_bool(a)
|
take_and_return_bool(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_the_object() -> JsObject {
|
||||||
|
return_object()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#)
|
||||||
.file("test.ts", r#"
|
.file("test.ts", r#"
|
||||||
@ -33,6 +38,7 @@ fn simple() {
|
|||||||
|
|
||||||
let ARG: string | null = null;
|
let ARG: string | null = null;
|
||||||
let ANOTHER_ARG: number | null = null;
|
let ANOTHER_ARG: number | null = null;
|
||||||
|
let SYM = Symbol('a');
|
||||||
|
|
||||||
export const imports: Imports = {
|
export const imports: Imports = {
|
||||||
foo(s) {
|
foo(s) {
|
||||||
@ -49,6 +55,9 @@ fn simple() {
|
|||||||
take_and_return_bool(s: boolean): boolean {
|
take_and_return_bool(s: boolean): boolean {
|
||||||
return s;
|
return s;
|
||||||
},
|
},
|
||||||
|
return_object(): any {
|
||||||
|
return SYM;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export function test(wasm: Exports) {
|
export function test(wasm: Exports) {
|
||||||
@ -62,6 +71,8 @@ fn simple() {
|
|||||||
|
|
||||||
assert.strictEqual(wasm.bool_thunk(true), true);
|
assert.strictEqual(wasm.bool_thunk(true), true);
|
||||||
assert.strictEqual(wasm.bool_thunk(false), false);
|
assert.strictEqual(wasm.bool_thunk(false), false);
|
||||||
|
|
||||||
|
assert.strictEqual(wasm.get_the_object(), SYM);
|
||||||
}
|
}
|
||||||
"#)
|
"#)
|
||||||
.test();
|
.test();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user