Skip to content

Expose WebAssembly.Instance.exports #3296

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

Merged
merged 1 commit into from
May 9, 2023
Merged

Conversation

daxpedda
Copy link
Collaborator

@daxpedda daxpedda commented Feb 11, 2023

I was specifically attempting to use #3177 but noticed it was impossible to call __wbindgen_thread_destroy() or get __tls_base and __stack_alloc from inside Rust.

Alternatively we could expose WebAssembly.Instance.prototype.exports directly instead.
EDIT: I decided to go ahead and expose the exports directly. Mainly because there were some targets that were much harder for me to implement exposing the instance for.

Or if we don't want a general-purpose solution like this we could expose __wbindgen_thread_destroy(), __tls_base and __stack_alloc through more intrinsics.

I'm not aware of any downsides.
EDIT: I was thinking that maybe exposing exports directly is worse then exposing the instance, but it seems that you can't do anything else with the instance anyway: https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/Instance.

Fixes #2513.

@daxpedda daxpedda marked this pull request as draft February 11, 2023 23:38
@daxpedda daxpedda changed the title Expose WebAssembly.Instance Expose WebAssembly.Instance.exports Feb 11, 2023
@daxpedda daxpedda marked this pull request as ready for review February 12, 2023 00:02
@daxpedda

This comment was marked as resolved.

@daxpedda daxpedda marked this pull request as draft February 13, 2023 20:11
@daxpedda daxpedda marked this pull request as ready for review February 13, 2023 20:59
@daxpedda
Copy link
Collaborator Author

daxpedda commented May 8, 2023

@alexcrichton would you mind getting this in before the next release (#3400)?

@alexcrichton alexcrichton merged commit b7edbd2 into rustwasm:main May 9, 2023
@alexcrichton
Copy link
Contributor

Sure!

@allsey87
Copy link
Contributor

allsey87 commented Jun 20, 2023

Quick question: is there any reason why:

wasm_bindgen::exports().js_typeof().as_string().unwrap()

is "object", while:

wasm_bindgen::exports().dyn_into::<js_sys::Object>().unwrap();

panics? From my testing, the js_sys::Object returned by unchecked_into seems to be correct/to work...

@daxpedda
Copy link
Collaborator Author

This is very strange.

It has nothing to do with wasm-bindgen though, I tried it out and apparently Instance.exports returns false on exports instanceof Object, I don't know why.
But typeof exports returns "Object" and the developer console says that it's an Object as well.

No clue!

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

Successfully merging this pull request may close these issues.

Add function to access instance exports or the instance itself.
3 participants