Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning a struct from a closure results in "__wrap is not a function" on that struct #1174

Closed
jacobgardner opened this issue Jan 14, 2019 · 1 comment

Comments

@jacobgardner
Copy link

jacobgardner commented Jan 14, 2019

I'm on wasm-bindgen@0.2.31 and getting "__wrap is not a function" when calling a closure which returns a struct that is not used anywhere else.

Here's the smallest example of the bug, I could make:

type ClosureType = FnMut() -> BadStruct;

#[wasm_bindgen]
pub struct ClosureHandle(Closure<ClosureType>);

#[wasm_bindgen]
pub struct BadStruct {}

#[wasm_bindgen]
pub fn closure_returner() -> Result<Object, JsValue> {
    let o = Object::new();

    let some_fn = Closure::wrap(Box::new(move || BadStruct {}) as Box<ClosureType>);
    Reflect::set(
        &o,
        &JsValue::from("someKey"),
        &some_fn.as_ref().unchecked_ref(),
    )
    .map_err(|_| "Unable to set property")?;
    Reflect::set(
        &o,
        &JsValue::from("handle"),
        &JsValue::from(ClosureHandle(some_fn)),
    )
    .map_err(|_| "Unable to set closure handle")?;

    Ok(o)
}

Typescript:

import("../../lib-web/pkg").then(module => {
    const c = module.closure_returner();
    c.someKey(); // Error occurs here
});

Currently this works as a workaround:

#[wasm_bindgen]
pub fn _dont_call() -> BadStruct {
    unimplemented!();
}

Edit: Related to #949, but not exactly the same.

alexcrichton added a commit to alexcrichton/wasm-bindgen that referenced this issue Jan 14, 2019
Surfaced through previous sanity-checking commits, this reorders some
internal operations to...

Closes rustwasm#1174
@alexcrichton
Copy link
Contributor

Thanks for the report! This should be fixed in #1175

alexcrichton added a commit to alexcrichton/wasm-bindgen that referenced this issue Jan 14, 2019
Surfaced through previous sanity-checking commits, this reorders some
internal operations to...

Closes rustwasm#1174
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants