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

Cannot use string #18

Open
Almaju opened this issue Aug 9, 2023 · 4 comments
Open

Cannot use string #18

Almaju opened this issue Aug 9, 2023 · 4 comments
Labels
bug Something isn't working needs-replication

Comments

@Almaju
Copy link

Almaju commented Aug 9, 2023

Everything works fine when I do:

export const add = async () => {
  const {instance} = await WebAssembly.instantiate<{
    add: (a: number, b: number) => number;
  }>(AddNumber);
  return instance.exports.add;
};

But if I try to return a string instead:

export const add = async () => {
  const {instance} = await WebAssembly.instantiate<{
    greet: () => string;
  }>(Greet);
  return instance.exports.greet;
};

Then this is what I get :

 WARN  Possible Unhandled Promise Rejection (id: 0):
Error: getValueAtIndex: index 2 is out of bounds [0, 2)
Error: getValueAtIndex: index 2 is out of bounds [0, 2)
    at RNWebassembly_invoke (native)
    at anonymous (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.app:123593:66)
    at anonymous (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.app:122943:42)
    at tryCallOne (/Users/distiller/react-native/packages/react-native/sdks/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js:53:16)
    at anonymous (/Users/distiller/react-native/packages/react-native/sdks/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js:139:27)
    at apply (native)
    at anonymous (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.app:34514:26)
    at _callTimer (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.app:34393:17)
    at _callReactNativeMicrotasksPass (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.app:34438:17)
    at callReactNativeMicrotasks (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.app:34644:44)
    at __callReactNativeMicrotasks (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.app:3288:46)
    at anonymous (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.app:3062:45)
    at __guard (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.app:3261:15)
    at flushedQueue (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.app:3061:21)
@cawfree
Copy link
Owner

cawfree commented Nov 3, 2023

Changing the typing of the instantiate function would not impact the runtime in this way, though the Wasm file being loaded would certainly.

Would you be able to share the file so I can try to replicate?

@cawfree cawfree added bug Something isn't working needs-replication labels Nov 3, 2023
@whyubel1eve
Copy link

hello, @cawfree . I have the same issue. This is the rust code:

#[wasm_bindgen]
pub fn generate_hd_account(phrase: &str, index: &str) -> String

js:

 const module = await WebAssembly.instantiate<{
      generate_hd_account: (phrase: string, index: string) => string;
    }>(HD);

  const account = module.instance.exports.generate_hd_account(
    mnemonic,
    index,
  );

I got this too

Error: getValueAtIndex: index 2 is out of bounds [0, 2)

@cawfree
Copy link
Owner

cawfree commented Dec 1, 2023

Hey @whyubel1eve, thanks for clarification!

Any chance you can share a template project so I can debug this locally?

@lednhatkhanh
Copy link

@cawfree Thank you for making this library! I also face this problem, just create a wasm package that receive string with rust then you will face this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-replication
Projects
None yet
Development

No branches or pull requests

4 participants