Skip to content

Functions returning structs are not working in no-modules mode #190

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

Closed
ngg opened this issue May 6, 2018 · 0 comments
Closed

Functions returning structs are not working in no-modules mode #190

ngg opened this issue May 6, 2018 · 0 comments

Comments

@ngg
Copy link
Contributor

ngg commented May 6, 2018

Smallest example that reproduces this bug:

#[wasm_bindgen]
pub struct S;

#[wasm_bindgen]
pub fn create_s() -> S {
    S
}

The generated JS file (with --no-modules) contains something like this:

__exports.create_s = function() {
    return S.__construct(wasm.create_s());
}

__exports.S = class S {
    // ...
}

When I call the create_s function it fails with ReferenceError: S is not defined.
If I modify the JS file either to call __exports.S.__construct or export the class as let S = null; __exports.S = S = class S { ... } then it works as supposed.

The second way seems like a really easy fix, I'll create a pull request.

ngg added a commit to ngg/wasm-bindgen that referenced this issue May 6, 2018
This only affects --no-modules and --nodejs modes.

Fixes rustwasm#190.
ngg added a commit to ngg/wasm-bindgen that referenced this issue May 6, 2018
This only affects --no-modules and --nodejs modes.

Fixes rustwasm#190.
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

1 participant