Skip to content

Add function to access instance exports or the instance itself. #2513

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
kettle11 opened this issue Mar 29, 2021 · 0 comments · Fixed by #3296
Closed

Add function to access instance exports or the instance itself. #2513

kettle11 opened this issue Mar 29, 2021 · 0 comments · Fixed by #3296

Comments

@kettle11
Copy link

Motivation

I'm trying to write a library that can optionally work-alongside wasm-bindgen or stand-alone without wasm-bindgen based on a feature flag.

My library has some Javascript that requires access to the Wasm instance's exports (to communicate independent of wasm-bindgen), but right now it's quite tricky to expose the instance's exports to my library.

The approach I've found is to stash the value retuned by wasm-bindgen's init on a global variable to access later:

const wasm = await init();
self.kwasm_exports = wasm;

A problem with this approach is that main is called by init so if my library is called by main then it won't yet have access the Wasm exports. A hack is to add a fake entry point to my library and then later call the entry point manually but that's a pretty invasive approach.

Ideally a library user should not have to change any of their Javascript code, they just need to flip a feature flag in my library.

Proposed Solution

If wasm-bindgen exposes a Rust function to access the instance's exports (or the instance itself) instead then that could be used instead to pass the information

This feels similar in purpose to functions like wasm-bindgen's memory function.

Such a function would be a useful escape-hatch for scenarios that are a little bit outside the norm, like my own.

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

Successfully merging a pull request may close this issue.

1 participant