Skip to content

Failed to import the same js functions with same rust fn name under different modules #4268

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
EqualMa opened this issue Nov 13, 2024 · 0 comments · Fixed by #4269
Closed
Labels

Comments

@EqualMa
Copy link

EqualMa commented Nov 13, 2024

Describe the Bug

If I use #[wasm_bindgen(js_name = parseFloat)] to import the same js function in two modules, with the same rust fn name, but with different signatures, things don't work well.

use wasm_bindgen::JsValue;
use wasm_bindgen_test::*;

mod a {
    use wasm_bindgen::prelude::*;

    #[wasm_bindgen]
    extern "C" {
        #[wasm_bindgen(js_name = parseFloat)]
        pub fn parse_float(text: &JsValue) -> f64;
    }
}

mod b {
    use wasm_bindgen::prelude::*;

    #[wasm_bindgen]
    extern "C" {
        #[wasm_bindgen(js_name = parseFloat)]
        pub fn parse_float(text: &str) -> f64;
    }
}

#[wasm_bindgen_test]
pub fn pass_a() {
    let v = JsValue::from_str("1");
    assert_eq!(a::parse_float(&v), 1.);
}

#[wasm_bindgen_test]
pub fn pass_b() {
    assert_eq!(b::parse_float("2"), 2.);
}

The above test failed.

const wasmModule = new WebAssembly.Module(bytes);
                   ^

CompileError: WebAssembly.Module(): Compiling function #838:"f64::a::parse_float::hfd12f3d441bd8268" failed: not enough arguments on the stack for call (need 2, got 1) @+435657

Steps to Reproduce

  1. Test the above code or just clone https://github.com/EqualMa/example-wasm-bindgen-import-with-same-name
  2. Run wasm-pack test --node

Expected Behavior

Imports with the same js name and rust name should all work.

Actual Behavior

If the imports have the same js name and rust name, it seems that they all link to the same bindgen js function. So if they have different signatures, calling one of them failed at runtime.

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

Successfully merging a pull request may close this issue.

1 participant